@@ -23,97 +23,127 @@ let FCS_REPO_LOCAL = "../fsharp_fable"
23
23
let FCS_REPO_FABLE_BRANCH = " fable"
24
24
let FCS_REPO_SERVICE_SLIM_BRANCH = " service_slim"
25
25
26
- type GhRealeases =
27
- [<Emit( """ new Promise((succeed, fail) =>
28
- $0.create({user: $1, token: $2}, $3, $4, { tag_name: $5, name: $5, body: $6 }, (err, res) =>
29
- err != null ? fail(err) : succeed(res)))""" ) >]
30
- abstract create: user : string * token : string * owner : string * repo : string * name : string * msg : string -> JS.Promise < obj >
26
+ module Util =
27
+ type GhRealeases =
28
+ [<Emit( """ new Promise((succeed, fail) =>
29
+ $0.create({user: $1, token: $2}, $3, $4, { tag_name: $5, name: $5, body: $6 }, (err, res) =>
30
+ err != null ? fail(err) : succeed(res)))""" ) >]
31
+ abstract create: user : string * token : string * owner : string * repo : string * name : string * msg : string -> JS.Promise < obj >
31
32
32
- type Chokidar =
33
- abstract watch: path : string -> Chokidar
34
- abstract on: event : string * ( string -> unit ) -> Chokidar
33
+ let cleanDirs dirs =
34
+ for dir in dirs do
35
+ removeDirRecursive dir
35
36
36
- let concurrently ( commands : string []): unit = importDefault " concurrently"
37
- let chokidar : Chokidar = importDefault " chokidar"
37
+ let updateVersionInFableTransforms version =
38
+ let filePath = " src/Fable.Transforms/Global/Compiler.fs"
39
+ // printfn "VERSION %s" version
40
+ Regex.Replace(
41
+ readFile filePath,
42
+ @" let \[<Literal>] VERSION = "" .*?"" " ,
43
+ sprintf " let [<Literal>] VERSION = \" %s \" " version)
44
+ |> writeFile filePath
38
45
39
- let cleanDirs dirs =
40
- for dir in dirs do
41
- removeDirRecursive dir
46
+ let updatePkgVersionInFsproj projFile version =
47
+ readFile projFile
48
+ |> replaceRegex Publish.NUGET_ PACKAGE_ VERSION [ " $1" ; version; " $3" ]
49
+ |> writeFile projFile
42
50
43
- let updateVersionInFableTransforms version =
44
- let filePath = " src/Fable.Transforms/Global/Compiler.fs"
45
- // printfn "VERSION %s" version
46
- Regex.Replace(
47
- readFile filePath,
48
- @" let \[<Literal>] VERSION = "" .*?"" " ,
49
- sprintf " let [<Literal>] VERSION = \" %s \" " version)
50
- |> writeFile filePath
51
+ let runTypescript projectDir =
52
+ // run ("npx tslint --project " + projectDir)
53
+ run ( " npm run tsc -- --project " + projectDir)
51
54
52
- let updatePkgVersionInFsproj projFile version =
53
- readFile projFile
54
- |> replaceRegex Publish.NUGET_ PACKAGE_ VERSION [ " $1" ; version; " $3" ]
55
- |> writeFile projFile
55
+ let runFableWithArgs projectDir args =
56
+ run ( " dotnet run -c Release -p src/Fable.Cli -- " + projectDir + " " + String.concat " " args)
56
57
57
- let downloadAndExtractTo ( url : string ) ( targetDir : string ) =
58
- sprintf " npx download --extract --out %s \" %s \" " targetDir url |> run
58
+ let runFableWithArgsAsync projectDir args =
59
+ runAsync ( " dotnet run -c Release -p src/Fable.Cli -- " + projectDir + " " + String.concat " " args )
59
60
60
- let runTypescript projectDir =
61
- // run ("npx tslint --project " + projectDir)
62
- run ( " npx tsc --project " + projectDir)
61
+ let runNpx command args =
62
+ run ( " npx " + command + " " + ( String.concat " " args))
63
63
64
- let watchFableWithArgs projectDir args =
65
- run ( " dotnet watch run -p src/Fable.Cli -- " + projectDir + " " + String.concat " " args)
64
+ let runNpmScriptAsync script args =
65
+ runAsync ( " npm run " + script + " -- " + ( String.concat " " args) )
66
66
67
- let runFableWithArgs projectDir args =
68
- run ( " dotnet run -c Release -p src/Fable.Cli -- " + projectDir + " " + String.concat " " args )
67
+ let runFable projectDir =
68
+ runFableWithArgs projectDir []
69
69
70
- let runNpx command args =
71
- run ( " npx " + command + " " + ( String.concat " " args))
70
+ open Util
72
71
73
- let runFable projectDir =
74
- runFableWithArgs projectDir []
72
+ module Unused =
73
+ // type Chokidar =
74
+ // abstract watch: path: string -> Chokidar
75
+ // abstract on: event: string * (string -> unit) -> Chokidar
75
76
76
- let buildLibrary () =
77
- let projectDir = fullPath " src/fable-library"
78
- let buildDir = fullPath " build/fable-library"
77
+ // let chokidar: Chokidar = importDefault "chokidar"
79
78
80
- cleanDirs [ buildDir ]
79
+ // let concurrently(commands: string[]): unit = importDefault "concurrently"
81
80
82
- runTypescript projectDir
81
+ let downloadAndExtractTo ( url : string ) ( targetDir : string ) =
82
+ sprintf " npx download --extract --out %s \" %s \" " targetDir url |> run
83
83
84
- runFableWithArgs projectDir [
84
+ let downloadStandalone () =
85
+ let targetDir = " src/fable-standalone/dist"
86
+ cleanDirs [ targetDir]
87
+ downloadAndExtractTo APPVEYOR_ REPL_ ARTIFACT_ URL targetDir
88
+
89
+ let coverage () =
90
+ // report converter
91
+ // https://github.com/danielpalme/ReportGenerator
92
+ // dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
93
+ if not ( pathExists " ./bin/tools/reportgenerator" ) && not ( pathExists " ./bin/tools/reportgenerator.exe" ) then
94
+ runInDir " ." " dotnet tool install dotnet-reportgenerator-globaltool --tool-path bin/tools"
95
+ let reportGen =
96
+ if pathExists " ./bin/tools/reportgenerator" then " bin/tools/reportgenerator"
97
+ else " bin\\ tools\\ reportgenerator.exe"
98
+
99
+ // if not (pathExists "build/fable-library") then
100
+ // buildLibrary()
101
+
102
+ cleanDirs [ " build/tests" ]
103
+ runFable " tests"
104
+
105
+ // JS
106
+ run " npx nyc mocha build/tests --require source-map-support/register --reporter dot -t 10000"
107
+ runInDir " ." ( reportGen + " \" -reports:build/coverage/nyc/lcov.info\" -reporttypes:Html \" -targetdir:build/coverage/nyc/html\" " )
108
+
109
+ // .NET
110
+ //runInDir "tests/Main" "dotnet build /t:Collect_Coverage"
111
+ cleanDirs [ " build/coverage/netcoreapp2.0/out" ]
112
+ runInDir " ." ( reportGen + " \" -reports:build/coverage/netcoreapp2.0/coverage.xml\" -reporttypes:Html \" -targetdir:build/coverage/netcoreapp2.0/html\" " )
113
+
114
+ // TARGETS ---------------------------
115
+
116
+ let buildLibraryWithOptions ( opts : {| watch: bool |}) =
117
+ let projectDir = fullPath " src/fable-library"
118
+ let buildDir = fullPath " build/fable-library"
119
+ let fableOpts = [
85
120
" --outDir " + buildDir
86
121
" --fableLib " + buildDir
87
122
" --exclude Fable.Core"
88
123
" --define FX_NO_BIGINT"
89
124
" --define FABLE_LIBRARY"
125
+ if opts.watch then " --watch"
90
126
]
91
127
92
- // // Move js files to build folder
93
- // let moveJsFile oldDir newDir (file: string) =
94
- // if file.EndsWith(".js") then
95
- // let newPath = newDir </> file
96
- // let newDir = dirname newPath
97
- // if not(pathExists newDir) then
98
- // makeDirRecursive(newDir)
99
- // moveFile (oldDir </> file) newPath
100
-
101
- // for file in dirFiles projectDir do
102
- // if isDirectory (projectDir </> file) then
103
- // let dir = file
104
- // if not(List.contains dir ["lib"; "bin"; "obj"]) then
105
- // for file in dirFiles (projectDir </> dir) do
106
- // moveJsFile projectDir buildDir (dir </> file)
107
- // else
108
- // moveJsFile projectDir buildDir file
109
-
110
- let watchLibrary () =
111
- let libDir = " src/fable-library"
112
- printfn " Watching %s ..." libDir
113
- chokidar
114
- .watch( libDir)
115
- .on( " change" , fun _ -> buildLibrary())
116
- |> ignore
128
+ cleanDirs [ buildDir]
129
+ if opts.watch then
130
+ runNpmScriptAsync " tsc" [
131
+ " --project " + projectDir
132
+ " --watch"
133
+ ]
134
+ runFableWithArgsAsync projectDir fableOpts
135
+ else
136
+ runTypescript projectDir
137
+ runFableWithArgs projectDir fableOpts
138
+
139
+ let buildLibrary () = buildLibraryWithOptions {| watch = false |}
140
+ let watchLibrary () = buildLibraryWithOptions {| watch = true |}
141
+ // let libDir = "src/fable-library"
142
+ // printfn "Watching %s..." libDir
143
+ // chokidar
144
+ // .watch(libDir)
145
+ // .on("change", fun _ -> buildLibrary())
146
+ // |> ignore
117
147
118
148
let buildLibraryTs () =
119
149
let projectDir = " src/fable-library"
@@ -132,8 +162,8 @@ let buildLibraryTs() =
132
162
]
133
163
// TODO: cleanDirs [buildDirTs </> "fable-library"]
134
164
// TODO: copy *.ts/*.js from projectDir to buildDir
135
- runInDir buildDirTs " npx tsc --init --target es2020 --module es2020 --allowJs"
136
- runInDir buildDirTs ( " npx tsc --outDir ../../" + buildDirJs)
165
+ runInDir buildDirTs " npm run tsc -- --init --target es2020 --module es2020 --allowJs"
166
+ runInDir buildDirTs ( " npm run tsc -- --outDir ../../" + buildDirJs)
137
167
138
168
let quicktest () =
139
169
if not ( pathExists " build/fable-library" ) then
@@ -241,8 +271,9 @@ let buildStandalone (opts: {| minify: bool; watch: bool |}) =
241
271
]
242
272
243
273
// make standalone worker dist
244
- run ( sprintf " npx rollup %s /worker/Worker.js -o %s /worker.js --format esm" buildDir buildDir)
245
- run ( sprintf " npx webpack --entry ./%s /worker.js --output ./%s /worker.min.js --config ./%s /../worker.config.js" buildDir distDir projectDir)
274
+ runNpx " rollup" [ sprintf " %s /worker/Worker.js -o %s /worker.js --format esm" buildDir buildDir]
275
+ // runNpx "webpack" [sprintf "--entry ./%s/worker.js --output ./%s/worker.min.js --config ./%s/../worker.config.js" buildDir distDir projectDir]
276
+ runNpx " terser" [ sprintf " %s /worker.js -o %s /worker.min.js --mangle --compress" buildDir distDir]
246
277
247
278
// print bundle size
248
279
fileSizeInBytes ( distDir </> " bundle.min.js" ) / 1000 |> printfn " Bundle size: %i KB"
@@ -325,7 +356,7 @@ let testJs(minify) =
325
356
326
357
let testReact () =
327
358
runFableWithArgs " tests/React" []
328
- run " npx jest "
359
+ runInDir " tests/React " " npm i && npm test "
329
360
330
361
let test () =
331
362
let projectDir = " tests/Main"
@@ -381,36 +412,6 @@ let testRepos() =
381
412
version ( " .." </> pkgDir))
382
413
runInDir repoDir command
383
414
384
- let coverage () =
385
- // report converter
386
- // https://github.com/danielpalme/ReportGenerator
387
- // dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
388
- if not ( pathExists " ./bin/tools/reportgenerator" ) && not ( pathExists " ./bin/tools/reportgenerator.exe" ) then
389
- runInDir " ." " dotnet tool install dotnet-reportgenerator-globaltool --tool-path bin/tools"
390
- let reportGen =
391
- if pathExists " ./bin/tools/reportgenerator" then " bin/tools/reportgenerator"
392
- else " bin\\ tools\\ reportgenerator.exe"
393
-
394
- if not ( pathExists " build/fable-library" ) then
395
- buildLibrary()
396
-
397
- cleanDirs [ " build/tests" ]
398
- runFable " tests"
399
-
400
- // JS
401
- run " npx nyc mocha build/tests --require source-map-support/register --reporter dot -t 10000"
402
- runInDir " ." ( reportGen + " \" -reports:build/coverage/nyc/lcov.info\" -reporttypes:Html \" -targetdir:build/coverage/nyc/html\" " )
403
-
404
- // .NET
405
- //runInDir "tests/Main" "dotnet build /t:Collect_Coverage"
406
- cleanDirs [ " build/coverage/netcoreapp2.0/out" ]
407
- runInDir " ." ( reportGen + " \" -reports:build/coverage/netcoreapp2.0/coverage.xml\" -reporttypes:Html \" -targetdir:build/coverage/netcoreapp2.0/html\" " )
408
-
409
- let downloadStandalone () =
410
- let targetDir = " src/fable-standalone/dist"
411
- cleanDirs [ targetDir]
412
- downloadAndExtractTo APPVEYOR_ REPL_ ARTIFACT_ URL targetDir
413
-
414
415
let githubRelease () =
415
416
match envVarOrNone " GITHUB_USER" , envVarOrNone " GITHUB_TOKEN" with
416
417
| Some user, Some token ->
@@ -507,23 +508,23 @@ let minify<'T> =
507
508
argsLower |> List.contains " --no-minify" |> not
508
509
509
510
match argsLower with
511
+ // | "check-sourcemaps"::_ ->
512
+ // ("src/quicktest/Quicktest.fs", "src/quicktest/bin/Quicktest.js", "src/quicktest/bin/Quicktest.js.map")
513
+ // |||> sprintf "nodemon --watch src/quicktest/bin/Quicktest.js --exec 'source-map-visualization --sm=\"%s;%s;%s\"'"
514
+ // |> List.singleton |> quicktest
515
+ // | "download-standalone"::_ -> downloadStandalone()
516
+ // | "coverage"::_ -> coverage()
510
517
| " test" ::_ -> test()
511
518
| " test-js" ::_ -> testJs( minify)
512
519
| " test-js-fast" ::_ -> testJsFast()
513
520
| " test-react" ::_ -> testReact()
514
- | " coverage" ::_ -> coverage()
515
521
| " quicktest" ::_ -> quicktest()
516
- // | "check-sourcemaps"::_ ->
517
- // ("src/quicktest/Quicktest.fs", "src/quicktest/bin/Quicktest.js", "src/quicktest/bin/Quicktest.js.map")
518
- // |||> sprintf "nodemon --watch src/quicktest/bin/Quicktest.js --exec 'source-map-visualization --sm=\"%s;%s;%s\"'"
519
- // |> List.singleton |> quicktest
520
- | ( " fable-library" | " library" )::_ -> buildLibrary()
521
522
| ( " watch-library" )::_ -> watchLibrary()
523
+ | ( " fable-library" | " library" )::_ -> buildLibrary()
522
524
| ( " fable-library-ts" | " library-ts" )::_ -> buildLibraryTs()
523
525
| ( " fable-compiler-js" | " compiler-js" )::_ -> buildCompilerJs( minify)
524
526
| ( " fable-standalone" | " standalone" )::_ -> buildStandalone {| minify= minify; watch= false |}
525
527
| " watch-standalone" ::_ -> buildStandalone {| minify= false ; watch= true |}
526
- | " download-standalone" ::_ -> downloadStandalone()
527
528
| " publish" :: restArgs -> publishPackages restArgs
528
529
| " github-release" ::_ ->
529
530
publishPackages []
0 commit comments