@@ -23,97 +23,127 @@ let FCS_REPO_LOCAL = "../fsharp_fable"
2323let FCS_REPO_FABLE_BRANCH = " fable"
2424let FCS_REPO_SERVICE_SLIM_BRANCH = " service_slim"
2525
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 >
3132
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
3536
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
3845
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
4250
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)
5154
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)
5657
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 )
5960
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))
6363
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) )
6666
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 []
6969
70- let runNpx command args =
71- run ( " npx " + command + " " + ( String.concat " " args))
70+ open Util
7271
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
7576
76- let buildLibrary () =
77- let projectDir = fullPath " src/fable-library"
78- let buildDir = fullPath " build/fable-library"
77+ // let chokidar: Chokidar = importDefault "chokidar"
7978
80- cleanDirs [ buildDir ]
79+ // let concurrently(commands: string[]): unit = importDefault "concurrently"
8180
82- runTypescript projectDir
81+ let downloadAndExtractTo ( url : string ) ( targetDir : string ) =
82+ sprintf " npx download --extract --out %s \" %s \" " targetDir url |> run
8383
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 = [
85120 " --outDir " + buildDir
86121 " --fableLib " + buildDir
87122 " --exclude Fable.Core"
88123 " --define FX_NO_BIGINT"
89124 " --define FABLE_LIBRARY"
125+ if opts.watch then " --watch"
90126 ]
91127
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
117147
118148let buildLibraryTs () =
119149 let projectDir = " src/fable-library"
@@ -132,8 +162,8 @@ let buildLibraryTs() =
132162 ]
133163 // TODO: cleanDirs [buildDirTs </> "fable-library"]
134164 // 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)
137167
138168let quicktest () =
139169 if not ( pathExists " build/fable-library" ) then
@@ -241,8 +271,9 @@ let buildStandalone (opts: {| minify: bool; watch: bool |}) =
241271 ]
242272
243273 // 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]
246277
247278 // print bundle size
248279 fileSizeInBytes ( distDir </> " bundle.min.js" ) / 1000 |> printfn " Bundle size: %i KB"
@@ -325,7 +356,7 @@ let testJs(minify) =
325356
326357let testReact () =
327358 runFableWithArgs " tests/React" []
328- run " npx jest "
359+ runInDir " tests/React " " npm i && npm test "
329360
330361let test () =
331362 let projectDir = " tests/Main"
@@ -381,36 +412,6 @@ let testRepos() =
381412 version ( " .." </> pkgDir))
382413 runInDir repoDir command
383414
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-
414415let githubRelease () =
415416 match envVarOrNone " GITHUB_USER" , envVarOrNone " GITHUB_TOKEN" with
416417 | Some user, Some token ->
@@ -507,23 +508,23 @@ let minify<'T> =
507508 argsLower |> List.contains " --no-minify" |> not
508509
509510match 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()
510517| " test" ::_ -> test()
511518| " test-js" ::_ -> testJs( minify)
512519| " test-js-fast" ::_ -> testJsFast()
513520| " test-react" ::_ -> testReact()
514- | " coverage" ::_ -> coverage()
515521| " 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()
521522| ( " watch-library" )::_ -> watchLibrary()
523+ | ( " fable-library" | " library" )::_ -> buildLibrary()
522524| ( " fable-library-ts" | " library-ts" )::_ -> buildLibraryTs()
523525| ( " fable-compiler-js" | " compiler-js" )::_ -> buildCompilerJs( minify)
524526| ( " fable-standalone" | " standalone" )::_ -> buildStandalone {| minify= minify; watch= false |}
525527| " watch-standalone" ::_ -> buildStandalone {| minify= false ; watch= true |}
526- | " download-standalone" ::_ -> downloadStandalone()
527528| " publish" :: restArgs -> publishPackages restArgs
528529| " github-release" ::_ ->
529530 publishPackages []
0 commit comments