forked from davedawkins/Sutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
159 lines (123 loc) · 4.7 KB
/
build.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// FAKE script adapter for FSI
//
// Adapter details from here:
// https://github.com/fsharp/FAKE/issues/2517
//
// Use this adapter template if you're suffering from this:
// Error: Package manager key 'paket' was not registered
// Explanation here:
// https://stackoverflow.com/questions/66665009/fix-for-package-manager-key-paket-was-not-registered-in-build-fsx
//
// Usage:
// % dotnet fsi build.fsx
// % dotnet fsi build.fsx --target <target>
#r "nuget: System.Reactive" // Prevent "Could not load file or assembly ..." error when using adapter
#r "nuget: Fake.Core.Target"
#load "node_modules/fable-publish-utils/PublishUtils.fs"
//open PublishUtils
open System
open System.IO
open Fake.Core
open PublishUtils
open Fake.Core.TargetOperators
// Boilerplate for adapter
System.Environment.GetCommandLineArgs()
|> Array.skip 2 // skip fsi.exe; build.fsx
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
|> Fake.Core.Context.RuntimeContext.Fake
|> Fake.Core.Context.setExecutionContext
// ---------------------------------------------------
// -- Your targets and regular FAKE code goes below --
let deleteFileIfExists file =
if (File.Exists(file)) then
File.Delete(file)
let copyFileOverwrite source target =
deleteFileIfExists target
File.Copy( source, target )
let setDotNet (v : int) =
let globalJson = "global.json"
copyFileOverwrite (sprintf "%s-dotnet%d" globalJson v) globalJson
let fsdocs (local : bool) =
let fsDocsCache = Path.Combine(".fsdocs", "cache")
let docsInputFolder = Path.Combine("temp", "docs")
let root = if local then "http://127.0.0.1:5500/public/apidocs/" else "https://sutil.dev/apidocs/"
deleteFileIfExists fsDocsCache
//let fscOptions = " -r:/Users/david/.nuget/packages/fable.core/3.7.1/lib/netstandard2.0/Fable.Core.dll"
run("dotnet build src/Sutil/Sutil.fsproj")
//run($"dotnet fsdocs build --output public/docs --fscoptions \"{fscOptions}\" --parameters root ../")
setDotNet(7)
if not (Directory.Exists(docsInputFolder)) then
Directory.CreateDirectory(docsInputFolder) |> ignore
sprintf "dotnet tool install fsdocs-tool" |> run
sprintf "dotnet fsdocs build --input %s --output public/apidocs --parameters fsdocs-logo-src ../../images/logo-small.png root %s" docsInputFolder root
|> run
sprintf "dotnet tool uninstall fsdocs-tool" |> run
Directory.Delete(docsInputFolder)
setDotNet(6)
Target.create "fsdocs" (fun _ -> fsdocs false)
Target.create "fsdocs:local" (fun _ -> fsdocs true)
Target.create "publish:package" (fun _ ->
let pkg = "Sutil"
pushNuget ("src" </> pkg </> pkg + ".fsproj") [] doNothing
)
Target.create "deploy:linode" (fun _ ->
// "deploy:linode": "bash deployToLinode.sh ./public sutil '' [email protected] /home/deploy/apps",
PublishUtils.run "bash deployToLinode.sh ./public sutil '' [email protected] /home/deploy/apps"
)
Target.create "sutilxml" (fun _ ->
PublishUtils.run("dotnet build -c Release src/Sutil/Sutil.fsproj")
copyFileOverwrite "src/Sutil/bin/Release/netstandard2.0/Sutil.xml" "public/Sutil.xml"
)
Target.create "publish:website" (fun _ ->
PublishUtils.run("node publish.js")
)
Target.create "usage" (fun _ ->
Console.WriteLine("Targets: publish")
)
Target.create "samples" (fun _ ->
let samplesTarget = Path.Combine( "public", "samples" )
if (not(Directory.Exists(samplesTarget))) then
Directory.CreateDirectory(samplesTarget) |> ignore
let re = System.Text.RegularExpressions.Regex(@"view\s*\(\)")
Directory.EnumerateFiles( "src/App", "*.fs" )
|> Seq.toList
|> List.filter (fun f -> Path.GetFileName(f) <> "App.fs")
|> List.iter (fun f ->
Console.WriteLine("copy {0}", f)
let targetFs = Path.Combine(samplesTarget, Path.GetFileName(f))
if (File.Exists(targetFs)) then
File.Delete(targetFs)
File.Copy( f, targetFs )
let content = File.ReadAllText(targetFs)
if (re.Match(content).Success) then
Console.WriteLine(" Found view() function")
File.AppendAllText( targetFs, "\nview() |> Program.mount\n")
)
)
Target.create "build:app" (fun _ ->
run "dotnet fable src/App --run webpack --mode production"
)
Target.create "clean" (fun _ ->
run("dotnet fable clean --yes")
run("dotnet clean")
)
Target.create "pack" (fun _ ->
run("dotnet pack -c Release src/Sutil/Sutil.fsproj")
)
"fsdocs"
==> "publish:website"
|> ignore
"fsdocs"
==> "build:app"
==> "samples"
==> "deploy:linode"
|> ignore
"clean"
==> "publish:package"
|> ignore
"clean"
==> "pack"
|> ignore
Target.runOrDefault "usage"