-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
160 lines (130 loc) · 3.73 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
160
open Fake.IO
#r "paket:
nuget Fake.Core.Target
nuget Fake.DotNet.Cli
nuget Fake.JavaScript.Npm"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.IO.Globbing.Operators
open Fake.JavaScript
open System.Diagnostics
open System.IO
//Target names
let defaultTarget = "default"
let all = "all"
let buildApi = "build-api"
let buildWeb = "build-web"
let restoreWeb = "restore-web"
let buildAll = "build-all"
let runApi = "run-api"
let runWeb = "run-web"
let runAll = "run-all"
let fsLint = "fs-lint"
let esLint = "es-lint"
let lintAll = "lint-all"
let testApiInt = "test-api-int"
let testApiUnit = "test-api-unit"
let testWebUnit = "test-web-unit"
let testAll = "test-all"
//Targets
Target.create defaultTarget (fun _ ->
Trace.trace "Enter a target, or use 'fake build --list' to see all targets."
)
let getDir (subDir : string) = sprintf "%s/%s" __SOURCE_DIRECTORY__ subDir
let dotnetBuild (path : string) (_ : TargetParameter) =
DotNet.exec id "build" path |> ignore
let dotNetRun (path : string) (_ : TargetParameter) =
DotNet.exec id "run" ("--project " + path) |> ignore
let dotNetTest (path : string) (_ : TargetParameter) =
DotNet.exec id "build" path |> ignore
DotNet.test
(fun o ->
let common = { o.Common with Verbosity = Some DotNet.Verbosity.Normal }
{ o with
Common = common
NoBuild = true
}
)
path
|> ignore
let setNpmParams (dir : string) (o : Npm.NpmParams) = { o with WorkingDirectory = getDir dir }
let launchConsole (dir : string) (command : string) (args : string list) (_ : TargetParameter) =
let psi = ProcessStartInfo()
psi.FileName <- command
psi.Arguments <- System.String.Join(" ", args)
psi.WorkingDirectory <- getDir dir
psi.UseShellExecute <- true
Process.Start psi |> ignore
Target.create buildApi (dotnetBuild "api/api.host/api.host.fsproj")
Target.create restoreWeb (fun _ -> Npm.install (setNpmParams "web"))
Target.create buildWeb (fun _ -> Npm.run "build" (setNpmParams "web"))
Target.create fsLint (fun _ ->
let projects = !! "**/*.fsproj"
for p in projects do
let args = sprintf """-f "%s" """ p
DotNet.exec id "fsharplint" args
|> ignore
)
Target.create esLint (fun _ ->
let dir = Path.Combine(__SOURCE_DIRECTORY__, "web")
let psi = ProcessStartInfo()
psi.FileName <- Path.Combine(dir, "node_modules/.bin/eslint.cmd")
psi.Arguments <- "**/*.ts*"
psi.WorkingDirectory <- dir
Process.Start psi
|> ignore
)
Target.create testApiUnit (dotNetTest "api/tests/api.unitTests/api.unitTests.fsproj")
Target.create testApiInt (dotNetTest "api/tests/api.integrationTests/api.integrationTests.fsproj")
Target.create testWebUnit (fun _ -> Npm.run "test" (setNpmParams "web"))
Target.create runApi (launchConsole "api/api.host" "dotnet" ["run api.host.fsproj"])
Target.create runWeb (launchConsole "web/dist/dev" "http-server" [])
Target.create buildAll ignore
Target.create lintAll ignore
Target.create testAll ignore
Target.create runAll ignore
Target.create all ignore
//Dependencies
open Fake.Core.TargetOperators
buildApi ?=> buildWeb
buildApi ?=> runApi
restoreWeb ?=> buildWeb
buildWeb ?=> runWeb
buildApi ?=> testApiUnit
buildApi ?=> testApiInt
buildWeb ?=> testWebUnit
testApiUnit ?=> runApi
testApiInt ?=> runApi
testWebUnit ?=> runWeb
buildAll <==
[
buildApi
restoreWeb
buildWeb
]
runAll <==
[
runApi
runWeb
]
testAll <==
[
testApiUnit
testApiInt
testWebUnit
]
lintAll <==
[
fsLint
esLint
]
all <==
[
buildAll
runAll
testAll
lintAll
]
//Start
Target.runOrDefault defaultTarget