-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.fsx
252 lines (198 loc) · 6.95 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
#r "paket:
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget Fake.Core.Target
nuget Fake.Core.Process
nuget Fake.Core.String
nuget Fake.Core.ReleaseNotes
nuget Fake.IO.FileSystem
nuget Fake.Tools.Git
nuget Fake.JavaScript.Yarn
//"
#load ".fake/build.fsx/intellisense.fsx"
#nowarn "52"
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open Fake.JavaScript
let rootDir = Path.getFullName "."
let srcDir = "./src"
let outputDir = "./output"
let distDir = "./dist"
let testDir = "./test"
let inDirectory dirName action =
Shell.cd dirName
action ()
Shell.cd rootDir
let run cmd dir args =
let result =
CreateProcess.fromRawCommandLine cmd args
|> CreateProcess.withWorkingDirectory dir
|> Proc.run
if result.ExitCode <> 0 then
failwithf "Error while running '%s' with args: %s " cmd args
let platformTool tool =
ProcessUtils.tryFindFileOnPath tool
|> function Some t -> t | _ -> failwithf "%s not found" tool
let dotnetExec cmd args =
let result = DotNet.exec id cmd args
if not result.OK then
failwithf "Error while running 'dotnet %s %s'" cmd args
let opamTool = platformTool "opam"
let opam args = run opamTool "./" args
let dune args = run opamTool "./" (sprintf "exec -- dune %s" args)
// Build targets
Target.create "Clean" <| fun _ ->
!! "src/bin"
++ "src/obj"
++ distDir
++ "src/.fable"
|> Seq.iter Shell.cleanDir
!! "src/**/*fs.js"
++ "src/**/*fs.js.map"
|> Seq.iter Shell.rm
Target.create "Restore" <| fun _ ->
DotNet.restore
(DotNet.Options.withWorkingDirectory __SOURCE_DIRECTORY__)
"ts2ocaml.sln"
Target.create "YarnInstall" <| fun _ ->
Yarn.installFrozenLockFile (fun ``params`` ->
{ ``params`` with WorkingDirectory = "./" })
Target.create "Prepare" ignore
Target.create "BuildForPublish" <| fun _ ->
dotnetExec "fable" $"{srcDir} --sourceMaps --run webpack --mode=production"
Target.create "BuildForTest" <| fun _ ->
dotnetExec "fable" $"{srcDir} --sourceMaps --define DEBUG --run webpack --mode=development"
Target.create "Build" ignore
Target.create "Watch" <| fun _ ->
dotnetExec "fable" $"watch {srcDir} --sourceMaps --define DEBUG --run webpack -w --mode=development"
Target.create "TestComplete" ignore
"Clean"
==> "YarnInstall"
==> "Restore"
==> "Prepare"
==> "Build"
"Prepare"
?=> "BuildForTest"
?=> "TestComplete"
?=> "BuildForPublish"
==> "Build"
"Prepare"
?=> "Watch"
// Test targets
module Test =
module Jsoo =
let testDir = testDir </> "jsoo"
let outputDir = outputDir </> "test_jsoo"
let srcDir = testDir </> "src"
let clean () =
!! $"{outputDir}/*"
++ $"{srcDir}/*.mli"
++ $"{srcDir}/stub.js"
|> Seq.iter Shell.rm
let generateBindings () =
Directory.create outputDir
let ts2ocaml args files =
Yarn.exec (sprintf "ts2ocaml %s" (String.concat " " (Seq.append args files))) id
ts2ocaml ["jsoo"; "--verbose"; "--nowarn"; "--stdlib"; $"-o {outputDir}"] <|
!! "node_modules/typescript/lib/lib.*.d.ts"
let packages = [
// "full" package involving a lot of inheritance
"full", !! "node_modules/typescript/lib/typescript.d.ts", [];
// "full" packages involving a lot of dependencies (which includes some "safe" packages)
"safe", !! "node_modules/@types/scheduler/tracing.d.ts", [];
"full", !! "node_modules/csstype/index.d.ts", [];
"safe", !! "node_modules/@types/prop-types/index.d.ts", ["--rec-module=off"];
"full", !! "node_modules/@types/react/index.d.ts" ++ "node_modules/@types/react/global.d.ts", [];
"full", !! "node_modules/@types/react-modal/index.d.ts", [];
// "safe" package which depends on another "safe" package
"safe", !! "node_modules/@types/yargs-parser/index.d.ts", [];
"safe", !! "node_modules/@types/yargs/index.d.ts", ["--rec-module=off"];
]
for preset, package, additionalOptions in packages do
ts2ocaml
(["jsoo"; "--verbose"; "--nowarn"; "--follow-relative-references";
$"--preset {preset}"; $"-o {outputDir}"] @ additionalOptions)
package
let build () =
for file in outputDir |> Shell.copyRecursiveTo true srcDir do
printfn "* copied to %s" file
inDirectory testDir <| fun () -> dune "build"
Target.create "TestJsooClean" <| fun _ -> Test.Jsoo.clean ()
Target.create "TestJsooGenerateBindings" <| fun _ -> Test.Jsoo.generateBindings ()
Target.create "TestJsooBuild" <| fun _ -> Test.Jsoo.build ()
Target.create "TestJsoo" ignore
"BuildForTest"
==> "TestJsooClean"
==> "TestJsooGenerateBindings"
==> "TestJsooBuild"
==> "TestJsoo"
Target.create "Test" ignore
Target.create "TestOnly" ignore
"TestJsoo"
==> "TestOnly"
==> "TestComplete"
==> "Test"
// Publish targets
module Publish =
let changelogFile = "CHANGELOG.md"
let changelog = Changelog.load changelogFile
let newVersion = changelog.LatestEntry.SemVer.AsString
module Npm =
let updateVersion () =
Yarn.exec $"version --new-version {newVersion} --no-git-tag-version" id
module Jsoo =
let targetDir = "./dist_jsoo"
let duneProject = targetDir </> "dune-project"
let copyArtifacts () =
let mliDir = outputDir </> "test_jsoo"
let mlDir = testDir </> "jsoo/_build/default/src"
let targets = ["ts2ocaml_min"; "ts2ocaml_es"; "ts2ocaml_dom"; "ts2ocaml_webworker"]
let targetDir = targetDir </> "src"
for target in targets do
Shell.rm (targetDir </> $"{target}.mli")
Shell.copyFile targetDir (mliDir </> $"{target}.mli")
Shell.rm (targetDir </> $"{target}.ml")
Shell.copyFile targetDir (mlDir </> $"{target}.ml")
let versionRegex =
String.getRegEx "\\(version ((?>\\w\\.)*\\w)\\)"
let updateVersion () =
duneProject |> File.applyReplace (fun content ->
let result = versionRegex.Match content
if result.Success then
let oldVersion = result.Groups.[1].Value
if oldVersion <> newVersion then
printfn $"* updating version in dist_jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
content |> String.replace result.Value $"(version {newVersion})"
else
printfn $"* version in dist_jsoo/dune-project not updated ('{newVersion}')."
content
else content
)
let testBuild () =
inDirectory targetDir <| fun () -> dune "build"
Target.create "Publish" <| fun _ -> ()
Target.create "PublishOnly" <| fun _ -> ()
Target.create "PublishNpm" <| fun _ ->
Publish.Npm.updateVersion ()
Target.create "PublishJsoo" <| fun _ ->
Publish.Jsoo.copyArtifacts ()
Publish.Jsoo.updateVersion ()
Publish.Jsoo.testBuild ()
"BuildForPublish"
==> "PublishNpm"
==> "PublishJsoo"
==> "PublishOnly"
==> "Publish"
"TestJsoo" ==> "PublishJsoo"
"Build" ?=> "Test" ?=> "Publish"
Target.create "All" ignore
"Build"
==> "Test"
==> "Publish"
==> "All"
// start build
Target.runOrDefault "Build"