-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBuild.fs
More file actions
254 lines (201 loc) · 6.7 KB
/
Build.fs
File metadata and controls
254 lines (201 loc) · 6.7 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
open Fake.Core
open Fake.IO
open Helpers
initializeContext ()
let sln = "GenPRES.sln"
let sharedPath = Path.getFullName "src/Informedica.GenPRES.Shared"
let serverPath = Path.getFullName "src/Informedica.GenPRES.Server"
let clientPath = Path.getFullName "src/Informedica.GenPRES.Client"
let dataPath = Path.getFullName "src/Informedica.GenPRES.Server/data"
let deployPath = Path.getFullName "deploy"
let clientTestsPath = Path.getFullName "tests/Client"
Target.create
"Clean"
(fun _ ->
Shell.cleanDir deployPath
Shell.cleanDir (Path.combine clientPath "dist")
run dotnet [ "fable"; "clean"; "--yes"; "-e"; ".jsx" ] clientPath // Delete *.fs.js files created by Fable
)
Target.create "RestoreClient" (fun _ -> run npm [ "ci" ] clientPath)
Target.create
"Bundle"
(fun _ ->
[
"server", dotnet [ "publish"; "-c"; "Release"; "-o"; deployPath ] serverPath
"client",
dotnet
[
"fable"
// "--test:MSBuildCracker"
"-o"
"output"
"-s"
"-e"
".jsx"
"--run"
"npx"
"vite"
"build"
"--emptyOutDir"
]
clientPath
]
|> runParallel
let deployDataPath = Path.combine deployPath "data"
printfn $"Copying data to {deployDataPath} ..."
Shell.copyDir deployDataPath dataPath (fun _ -> true)
let logPath = Path.combine deployDataPath "logs"
Shell.cleanDir logPath
let result = System.IO.Directory.Exists(deployDataPath)
printfn $"Copying data ... done: {result}"
)
Target.create "Build" (fun _ -> run dotnet [ "build"; sln ] ".")
Target.create
"Run"
(fun _ ->
[
"server", dotnet [ "run"; "--no-restore" ] serverPath
"client",
dotnet
[
"fable"
"watch" (*"--test:MSBuildCracker";*)
"-o"
"output"
"-s"
"-e"
".jsx"
"--run"
"npx"
"vite"
]
clientPath
]
|> runParallel
)
Target.create
"ServerTests"
(fun _ ->
let totalPassed = ref 0
let totalFailed = ref 0
let totalSkipped = ref 0
let totalTests = ref 0
let started = ref false
let parseLine (line: string) =
if line.Contains("Passed:") && line.Contains("Failed:") && line.Contains("Total:") then
let grab (key: string) =
let i = line.IndexOf(key)
if i >= 0 then
let start = i + key.Length
line
.Substring(start)
.TrimStart()
.Split([| ','; ' ' |], System.StringSplitOptions.RemoveEmptyEntries)
|> Array.tryHead
|> Option.bind (fun s ->
match System.Int32.TryParse(s) with
| true, n -> Some n
| _ -> None
)
|> Option.defaultValue 0
else
0
totalFailed.Value <- totalFailed.Value + grab "Failed:"
totalPassed.Value <- totalPassed.Value + grab "Passed:"
totalSkipped.Value <- totalSkipped.Value + grab "Skipped:"
totalTests.Value <- totalTests.Value + grab "Total:"
if not started.Value then
started.Value <- true
printf "Running tests "
printf "."
dotnet
[
"test"
sln
"--no-restore"
"--verbosity"
"quiet"
"--logger"
"console;verbosity=minimal"
]
"."
|> CreateProcess.redirectOutputIfNotRedirected
|> CreateProcess.withOutputEventsNotNull parseLine (eprintfn "%s")
|> Proc.run
|> fun result ->
printfn ""
printfn "====================================================================="
printfn
"Test Summary: %d passed, %d failed, %d skipped, %d total"
totalPassed.Value
totalFailed.Value
totalSkipped.Value
totalTests.Value
printfn "====================================================================="
if result.ExitCode <> 0 then
failwithf "Tests failed with exit code %d" result.ExitCode
)
Target.create
"TestHeadless"
(fun _ ->
run dotnet [ "test"; sln; "--no-build"; "--no-restore" ] "."
run
dotnet
[
"fable"
"-o"
"output"
"-s"
"-e"
".jsx"
"--run"
"npx"
"vite"
]
clientPath
// run dotnet [ "fable"; "-o"; "output"; "-e"; ".jsx" ] clientTestsPath
// run npx [ "mocha"; "output" ] clientTestsPath
)
Target.create
"WatchTests"
(fun _ ->
[
// "server", dotnet [ "watch"; "run"; "--no-restore" ] serverTestsPath
"client",
dotnet
[
"fable"
"watch"
"-o"
"output"
"-s"
"-e"
".jsx"
"--run"
"npx"
"vite"
]
clientTestsPath
]
|> runParallel
)
Target.create "Format" (fun _ -> run dotnet [ "fantomas"; "." ] ".")
Target.create
"MarkdownLint"
(fun _ ->
try
run npx [ "--yes"; "markdownlint-cli2"; "**/*.md"; "#node_modules" ] "."
with ex ->
Trace.traceImportant $"⚠️ MarkdownLint: {ex.Message}"
)
Target.create "DockerRun" (fun _ -> run docker [ "run"; "-it"; "p"; "8080:8085"; "halcwb/genpres" ] ".")
open Fake.Core.TargetOperators
let dependencies =
[
"Clean" ==> "RestoreClient" ==> "Bundle"
"Clean" ==> "RestoreClient" ==> "Build" ==> "Run"
"RestoreClient" ==> "Build" ==> "TestHeadless"
"RestoreClient" ==> "Build" ==> "WatchTests"
]
[<EntryPoint>]
let main args = runOrDefault args