@@ -27,25 +27,26 @@ let run cmd dir args =
2727 failwithf " Error while running '%s ' with args: %s " cmd args
2828
2929let platformTool tool =
30- ProcessUtils.tryFindFileOnPath tool
31- |> function Some t -> t | _ -> failwithf " %s not found" tool
30+ lazy
31+ ProcessUtils.tryFindFileOnPath tool
32+ |> function Some t -> t | _ -> failwithf " %s not found" tool
3233
3334let dotnetExec cmd args =
3435 let result = DotNet.exec id cmd args
3536 if not result.OK then
3637 failwithf " Error while running 'dotnet %s %s '" cmd args
3738
3839let opamTool = platformTool " opam"
39- let opam args = run opamTool " ./" args
40- let dune args = run opamTool " ./" ( sprintf " exec -- dune %s " args)
40+ let opam args = run opamTool.Value " ./" args
41+ let dune args = run opamTool.Value " ./" ( sprintf " exec -- dune %s " args)
4142
4243// Build targets
4344
4445let setup () =
4546 Target.create " Clean" <| fun _ ->
4647 !! " src/bin"
4748 ++ " src/obj"
48- ++ distDir
49+ ++ ( distDir </> " js " ) // clean ts2ocaml.js
4950 ++ " src/.fable"
5051 |> Seq.iter Shell.cleanDir
5152
@@ -74,24 +75,27 @@ let setup () =
7475 Target.create " Watch" <| fun _ ->
7576 dotnetExec " fable" $" watch {srcDir} --sourceMaps --define DEBUG --run webpack -w --mode=development"
7677
77- Target.create " TestComplete " ignore
78+ Target.create " Test " ignore
7879
79- " Clean " ?=> " Build "
80+ Target.create " Publish " ignore
8081
81- " Clean"
82- ?=> " YarnInstall"
82+ " YarnInstall"
8383 ==> " Restore"
8484 ==> " Prepare"
85- ?=> " Build"
8685
8786 " Prepare"
88- ?=> " BuildForTest"
89- ?=> " TestComplete"
90- ?=> " BuildForPublish"
87+ ==> " BuildForTest"
9188 ==> " Build"
9289
9390 " Prepare"
94- ?=> " Watch"
91+ ==> " BuildForPublish"
92+
93+ " Prepare"
94+ ==> " Watch"
95+
96+ " Clean"
97+ ?=> " BuildForTest" ?=> " Build" ?=> " Test"
98+ ?=> " BuildForPublish" ?=> " Publish"
9599
96100// Test targets
97101
@@ -145,6 +149,59 @@ module Test =
145149 printfn " * copied to %s " file
146150 inDirectory testDir <| fun () -> dune " build"
147151
152+ module Res =
153+ let testDir = testDir </> " res"
154+ let outputDir = outputDir </> " test_res"
155+ let srcDir = testDir </> " src"
156+ let srcGeneratedDir = srcDir </> " generated"
157+
158+ let clean () =
159+ !! $" {outputDir}/*"
160+ ++ $" {srcGeneratedDir}/*.res"
161+ ++ $" {srcGeneratedDir}/*.resi"
162+ ++ $" {srcGeneratedDir}/*.bs.js"
163+ |> Seq.iter Shell.rm
164+
165+ let generateBindings () =
166+ Directory.create outputDir
167+
168+ let ts2res args files =
169+ Yarn.exec ( sprintf " ts2ocaml res %s " ( String.concat " " ( Seq.append args files))) id
170+
171+ ts2res [ " --create-stdlib" ; $" -o {outputDir}" ] []
172+
173+ let packages = [
174+ // "full" package involving a lot of inheritance
175+ " full" , !! " node_modules/typescript/lib/typescript.d.ts" , [ " --experimental-tagged-union" ];
176+
177+ // "full" packages involving a lot of dependencies (which includes some "safe" packages)
178+ " safe" , !! " node_modules/@types/scheduler/tracing.d.ts" , [];
179+ " full" , !! " node_modules/csstype/index.d.ts" , [];
180+ " safe" , !! " node_modules/@types/prop-types/index.d.ts" , [];
181+ " full" , !! " node_modules/@types/react/index.d.ts" ++ " node_modules/@types/react/global.d.ts" , [ " --readable-names" ];
182+ " full" , !! " node_modules/@types/react-modal/index.d.ts" , [ " --readable-names" ];
183+
184+ // "safe" package which depends on another "safe" package
185+ " safe" , !! " node_modules/@types/yargs-parser/index.d.ts" , [];
186+ " safe" , !! " node_modules/@types/yargs/index.d.ts" , [];
187+
188+ " minimal" , !! " node_modules/@types/vscode/index.d.ts" , [ " --readable-names" ];
189+ ]
190+
191+ for preset, package, additionalOptions in packages do
192+ ts2res
193+ ([ " --verbose" ; " --nowarn" ; " --follow-relative-references" ;
194+ $" --preset {preset}" ; $" -o {outputDir}" ] @ additionalOptions)
195+ package
196+
197+ let build () =
198+ Shell.mkdir srcGeneratedDir
199+ for file in outputDir |> Shell.copyRecursiveTo true srcGeneratedDir do
200+ printfn " * copied to %s " file
201+ inDirectory testDir <| fun () ->
202+ Yarn.install id
203+ Yarn.exec " rescript" id
204+
148205 let setup () =
149206 Target.create " TestJsooClean" <| fun _ -> Jsoo.clean ()
150207 Target.create " TestJsooGenerateBindings" <| fun _ -> Jsoo.generateBindings ()
@@ -156,13 +213,18 @@ module Test =
156213 ==> " TestJsooGenerateBindings"
157214 ==> " TestJsooBuild"
158215 ==> " TestJsoo"
216+ ==> " Test"
159217
160- Target.create " Test" ignore
161- Target.create " TestOnly" ignore
218+ Target.create " TestResClean" <| fun _ -> Res.clean ()
219+ Target.create " TestResGenerateBindings" <| fun _ -> Res.generateBindings ()
220+ Target.create " TestResBuild" <| fun _ -> Res.build ()
221+ Target.create " TestRes" ignore
162222
163- " TestJsoo"
164- ==> " TestOnly"
165- ==> " TestComplete"
223+ " BuildForTest"
224+ ==> " TestResClean"
225+ ==> " TestResGenerateBindings"
226+ ==> " TestResBuild"
227+ ==> " TestRes"
166228 ==> " Test"
167229
168230// Publish targets
@@ -177,7 +239,7 @@ module Publish =
177239 Yarn.exec $" version --new-version {newVersion} --no-git-tag-version" id
178240
179241 module Jsoo =
180- let targetDir = " ./dist_jsoo "
242+ let targetDir = distDir </> " jsoo "
181243 let duneProject = targetDir </> " dune-project"
182244
183245 let copyArtifacts () =
@@ -200,10 +262,10 @@ module Publish =
200262 if result.Success then
201263 let oldVersion = result.Groups.[ 1 ]. Value
202264 if oldVersion <> newVersion then
203- printfn $" * updating version in dist_jsoo /dune-project from '{oldVersion}' to '{newVersion}'."
265+ printfn $" * updating version in dist/jsoo /dune-project from '{oldVersion}' to '{newVersion}'."
204266 content |> String.replace result.Value $" (version {newVersion})"
205267 else
206- printfn $" * version in dist_jsoo /dune-project not updated ('{newVersion}')."
268+ printfn $" * version in dist/jsoo /dune-project not updated ('{newVersion}')."
207269 content
208270 else content
209271 )
@@ -212,9 +274,6 @@ module Publish =
212274 inDirectory targetDir <| fun () -> dune " build"
213275
214276 let setup () =
215- Target.create " Publish" <| fun _ -> ()
216- Target.create " PublishOnly" <| fun _ -> ()
217-
218277 Target.create " PublishNpm" <| fun _ ->
219278 Npm.updateVersion ()
220279
@@ -226,13 +285,8 @@ module Publish =
226285 " BuildForPublish"
227286 ==> " PublishNpm"
228287 ==> " PublishJsoo"
229- ==> " PublishOnly"
230288 ==> " Publish"
231289
232- " TestJsoo" ==> " PublishJsoo"
233-
234- " Build" ?=> " Test" ?=> " Publish"
235-
236290// Utility targets
237291
238292module Utility =
0 commit comments