forked from fable-compiler/Fable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
306 lines (258 loc) · 10.4 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#r "packages/build/FAKE/tools/FakeLib.dll"
#load "paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
#load "paket-files/build/fable-compiler/fake-helpers/Fable.FakeHelpers.fs"
open System
open System.IO
open System.Text.RegularExpressions
open Fake
open Fake.Git
open Octokit
open Fable.FakeHelpers
#if MONO
// prevent incorrect output encoding (e.g. https://github.com/fsharp/FAKE/issues/1196)
System.Console.OutputEncoding <- System.Text.Encoding.UTF8
#endif
module Yarn =
open YarnHelper
let install workingDir =
Yarn (fun p ->
{ p with
Command = YarnCommand.Install InstallArgs.Standard
WorkingDirectory = workingDir
})
let run workingDir script args =
Yarn (fun p ->
{ p with
Command = YarnCommand.Custom ("run " + script + " " + args)
WorkingDirectory = workingDir
})
let runBashOrCmd cwd (scriptFileName: string) args =
if isWindows
then run cwd (scriptFileName.Replace("/", "\\") + ".cmd") args
else run cwd "sh" (scriptFileName + ".sh " + args)
let addToPath newPath =
let path = environVarOrDefault "PATH" ""
let separator = if isWindows then ";" else ":"
setEnvironVar "PATH" (newPath + separator + path)
// Project info
let project = "Fable"
let gitOwner = "fable-compiler"
let gitHome = "https://github.com/" + gitOwner
let dotnetcliVersion = "2.1.4"
let mutable dotnetExePath = environVarOrDefault "DOTNET" "dotnet"
let CWD = __SOURCE_DIRECTORY__
let cliBuildDir = CWD </> "build/fable"
let coreJsSrcDir = CWD </> "src/js/fable-core"
// Targets
let installDotnetSdk () =
dotnetExePath <- DotNetCli.InstallDotNetSDK dotnetcliVersion
if Path.IsPathRooted(dotnetExePath) then
Path.GetDirectoryName(dotnetExePath) |> addToPath
run CWD "dotnet" "--version"
let clean_ (full: bool) =
!! "src/dotnet/**/bin"
-- "src/dotnet/Fable.Client.JS/demo/**"
-- "src/dotnet/Fable.Client.JS/testapp/**"
++ "src/plugins/nunit/bin"
++ "tests*/**/bin"
++ "build"
|> CleanDirs
if full then
!! "src/dotnet/**/obj"
++"src/plugins/nunit/obj"
++"tests**/**/obj"
|> CleanDirs
else
!! "src/dotnet/**/obj/*.nuspec"
++"src/plugins/nunit/obj/*.nuspec"
++"tests**/**/obj/*.nuspec"
|> DeleteFiles
let clean () = clean_ false
let fullClean () = clean_ true
let nugetRestore baseDir () =
run (baseDir </> "Fable.Core") dotnetExePath "restore"
run (baseDir </> "Fable.Compiler") dotnetExePath "restore"
run (baseDir </> "dotnet-fable") dotnetExePath "restore"
let buildCLI baseDir isRelease () =
sprintf "publish -o %s -c %s" cliBuildDir
(if isRelease then "Release -v n" else "Debug")
|> run (baseDir </> "dotnet-fable") dotnetExePath
let buildCoreJS () =
Yarn.install CWD
Yarn.run CWD "tslint" (sprintf "--project %s" coreJsSrcDir)
Yarn.run CWD "tsc" (sprintf "--project %s" coreJsSrcDir)
let buildSplitter () =
let buildDir = CWD </> "src/js/fable-splitter"
Yarn.install CWD
// Yarn.run CWD "tslint" [sprintf "--project %s" buildDir]
Yarn.run CWD "tsc" (sprintf "--project %s" buildDir)
let buildNUnitPlugin () =
let nunitDir = "src/plugins/nunit"
// CreateDir "build/nunit" // if it does not exist
// run nunitDir dotnetExePath "restore"
// pass output path to build command
run nunitDir dotnetExePath ("build -c Release -o ../../../build/nunit")
let buildJsonConverter () =
// "restore src/dotnet/Fable.JsonConverter"
// |> run CWD dotnetExePath
"build src/dotnet/Fable.JsonConverter -c Release -o ../../../build/json-converter /p:TargetFramework=netstandard1.6"
|> run CWD dotnetExePath
let runTestsDotnet () =
CleanDir "tests/Main/obj"
// run (CWD </> "tests/Main") dotnetExePath "restore /p:TestRunner=xunit"
// run (CWD </> "tests/Main") dotnetExePath "build /p:TestRunner=xunit"
run (CWD </> "tests/Main") dotnetExePath "test /p:TestRunner=xunit"
run (CWD </> "src/dotnet/Fable.JsonConverter/tests") dotnetExePath "test"
let runTestsJS () =
Yarn.install CWD
run CWD dotnetExePath "restore tests/Main"
run CWD dotnetExePath "build/fable/dotnet-fable.dll webpack --verbose --port free -- --config tests/webpack.config.js"
Yarn.run CWD "mocha" "./build/tests/bundle.js"
let quickTest() =
run "src/tools" dotnetExePath "../../build/fable/dotnet-fable.dll yarn-run rollup"
run CWD "node" "src/tools/temp/QuickTest.js"
Target "QuickTest" quickTest
Target "QuickFableCompilerTest" (fun () ->
buildCLI "src/dotnet" false ()
quickTest ())
Target "QuickFableCoreTest" (fun () ->
buildCoreJS ()
quickTest ())
let updateVersionInToolsUtil () =
let reg = Regex(@"\bVERSION\s*=\s*""(.*?)""")
let release =
CWD </> "src/dotnet/dotnet-fable/RELEASE_NOTES.md"
|> ReleaseNotesHelper.LoadReleaseNotes
let mainFile = CWD </> "src/dotnet/dotnet-fable/ToolsUtil.fs"
(reg, mainFile) ||> replaceLines (fun line m ->
let replacement = sprintf "VERSION = \"%s\"" release.NugetVersion
reg.Replace(line, replacement) |> Some)
Target "GitHubRelease" (fun _ ->
let release =
CWD </> "src/dotnet/dotnet-fable/RELEASE_NOTES.md"
|> ReleaseNotesHelper.LoadReleaseNotes
let user =
match getBuildParam "github-user" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserInput "GitHub Username: "
let pw =
match getBuildParam "github-pw" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "GitHub Password: "
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + project))
|> function None -> gitHome + "/" + project | Some (s: string) -> s.Split().[0]
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" remote (Information.getBranchName "")
Branches.tag "" release.NugetVersion
Branches.pushTag "" remote release.NugetVersion
// release on github
createClient user pw
|> createDraft gitOwner project release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
// |> uploadFile (buildDir</>("FSharp.Compiler.Service." + release.NugetVersion + ".nupkg"))
|> releaseDraft
|> Async.RunSynchronously
)
Target "Clean" clean
Target "FullClean" fullClean
Target "NugetRestore" (nugetRestore "src/dotnet")
Target "FableCLI" (buildCLI "src/dotnet" true)
Target "FableCoreJS" buildCoreJS
Target "FableSplitter" buildSplitter
Target "NUnitPlugin" buildNUnitPlugin
Target "JsonConverter" buildJsonConverter
Target "RunTestsJS" runTestsJS
Target "RunTestsDotnet" runTestsDotnet
Target "PublishPackages" (fun () ->
let baseDir = CWD </> "src"
let packages = [
// Nuget packages
Some buildCoreJS, "dotnet/Fable.Core/Fable.Core.fsproj"
None, "dotnet/Fable.Compiler/Fable.Compiler.fsproj"
Some updateVersionInToolsUtil, "dotnet/dotnet-fable/dotnet-fable.fsproj"
None, "dotnet/Fable.JsonConverter/Fable.JsonConverter.fsproj"
None, "plugins/nunit/Fable.Plugins.NUnit.fsproj"
// NPM packages
None, "js/fable-utils"
None, "js/fable-loader"
None, "js/rollup-plugin-fable"
Some buildSplitter, "js/fable-splitter"
]
installDotnetSdk ()
fullClean ()
publishPackages2 baseDir dotnetExePath packages
)
let buildRepl () =
let replDir = CWD </> "src/dotnet/Fable.JS/demo"
let testappDir = CWD </> "src/dotnet/Fable.JS/testapp"
let fcsFork = "https://github.com/ncave/FSharp.Compiler.Service"
let fcsFableDir =
// Appveyor has problems with too long paths so download the fork closer to root
// TODO: Another option for local Windows Systems (not AppVeyor)
match environVarOrNone "APPVEYOR" with
| Some _ -> "/projects/fcs"
| None -> CWD </> "paket-files/ncave/FCS"
let fableJsProj = CWD </> "src/dotnet/Fable.JS/Fable.JS.fsproj"
let fcsFableProj = fcsFableDir </> "fcs/fcs-fable/fcs-fable.fsproj"
CleanDir fcsFableDir
Repository.cloneSingleBranch CWD fcsFork "fable" fcsFableDir
runBashOrCmd fcsFableDir "fcs/build" "CodeGen.Fable"
Directory.GetFiles(fcsFableDir </> "fcs/fcs-fable/codegen")
|> Seq.iter (printfn "%s")
let reg = Regex(@"ProjectReference Include="".*?""")
(reg, fableJsProj) ||> replaceLines (fun line _ ->
reg.Replace(line, sprintf @"ProjectReference Include=""%s""" fcsFableProj) |> Some)
// Build and minify REPL
Yarn.install replDir
Yarn.run replDir "build" ""
Yarn.run replDir "minify" ""
// build fable-core for umd
sprintf "--project %s -m umd --outDir %s" coreJsSrcDir (replDir </> "repl/build/fable-core")
|> Yarn.run CWD "tsc"
// Build testapp
Yarn.install testappDir
Yarn.run testappDir "build" ""
Yarn.run testappDir "start" ""
Yarn.run testappDir "test" ""
// Copy generated files to `../fable-compiler.github.io/public/repl/build`
// let targetDir = CWD </> "../fable-compiler.github.io/public/repl"
// if Directory.Exists(targetDir) then
// let targetDir = targetDir </> "build"
// // fable-core
// sprintf "--project %s -m amd --outDir %s" coreJsSrcDir (targetDir </> "fable-core")
// |> Yarn.run CWD "tsc"
// // REPL bundle
// printfn "Copy REPL JS files to %s" targetDir
// for file in Directory.GetFiles(replDir </> "repl/build", "*.js") do
// FileUtils.cp file targetDir
// printfn "> Copied: %s" file
Target "All" (fun () ->
installDotnetSdk ()
clean ()
// nugetRestore "src/dotnet" ()
buildCLI "src/dotnet" true ()
buildCoreJS ()
buildSplitter ()
buildNUnitPlugin ()
buildJsonConverter ()
runTestsJS ()
match environVarOrNone "APPVEYOR", environVarOrNone "TRAVIS" with
| Some _, _ -> runTestsDotnet (); buildRepl ()
// .NET tests fail most of the times in Travis for obscure reasons
| _, Some _ -> buildRepl ()
// Don't build repl locally (takes too long)
| None, None -> runTestsDotnet ()
)
Target "REPL" buildRepl
// Note: build target "All" and "REPL" before this
Target "REPL.test" (fun () ->
let replTestDir = "src/dotnet/Fable.JS/testapp"
Yarn.run replTestDir "build" ""
)
"PublishPackages"
==> "GitHubRelease"
// Start build
RunTargetOrDefault "All"