@@ -27,140 +27,191 @@ let distDir = "./dist"
27
27
let testDir = " ./test"
28
28
29
29
let run cmd dir args =
30
- let result =
31
- CreateProcess.fromRawCommandLine cmd args
32
- |> CreateProcess.withWorkingDirectory dir
33
- |> Proc.run
34
- if result.ExitCode <> 0 then
35
- failwithf " Error while running '%s ' with args: %s " cmd args
30
+ let result =
31
+ CreateProcess.fromRawCommandLine cmd args
32
+ |> CreateProcess.withWorkingDirectory dir
33
+ |> Proc.run
34
+ if result.ExitCode <> 0 then
35
+ failwithf " Error while running '%s ' with args: %s " cmd args
36
36
37
37
let platformTool tool =
38
- ProcessUtils.tryFindFileOnPath tool
39
- |> function Some t -> t | _ -> failwithf " %s not found" tool
38
+ ProcessUtils.tryFindFileOnPath tool
39
+ |> function Some t -> t | _ -> failwithf " %s not found" tool
40
40
41
41
let dotnetExec cmd args =
42
- let result = DotNet.exec id cmd args
43
- if not result.OK then
44
- failwithf " Error while running 'dotnet %s %s '" cmd args
42
+ let result = DotNet.exec id cmd args
43
+ if not result.OK then
44
+ failwithf " Error while running 'dotnet %s %s '" cmd args
45
+
46
+ let opamTool = platformTool " opam"
47
+ let opam args = run opamTool " ./" args
48
+ let dune args = run opamTool " ./" ( sprintf " exec -- dune %s " args)
45
49
46
50
// Build targets
47
51
48
52
Target.create " Clean" <| fun _ ->
49
- !! " src/bin"
50
- ++ " src/obj"
51
- ++ distDir
52
- ++ " src/.fable"
53
- |> Seq.iter Shell.cleanDir
53
+ !! " src/bin"
54
+ ++ " src/obj"
55
+ ++ distDir
56
+ ++ " src/.fable"
57
+ |> Seq.iter Shell.cleanDir
54
58
55
- !! " src/**/*fs.js"
56
- ++ " src/**/*fs.js.map"
57
- |> Seq.iter Shell.rm
59
+ !! " src/**/*fs.js"
60
+ ++ " src/**/*fs.js.map"
61
+ |> Seq.iter Shell.rm
58
62
59
63
Target.create " Restore" <| fun _ ->
60
- DotNet.restore
61
- ( DotNet.Options.withWorkingDirectory __ SOURCE_ DIRECTORY__)
62
- " ts2ocaml.sln"
64
+ DotNet.restore
65
+ ( DotNet.Options.withWorkingDirectory __ SOURCE_ DIRECTORY__)
66
+ " ts2ocaml.sln"
63
67
64
68
Target.create " YarnInstall" <| fun _ ->
65
- Yarn.installFrozenLockFile ( fun ``params`` ->
66
- { `` params `` with
67
- WorkingDirectory = " ./" })
69
+ Yarn.installFrozenLockFile ( fun ``params`` ->
70
+ { `` params `` with WorkingDirectory = " ./" })
68
71
69
72
Target.create " Prepare" ignore
70
73
71
74
Target.create " BuildOnly" <| fun _ ->
72
- dotnetExec " fable" $" {srcDir} --sourceMaps --run webpack"
75
+ dotnetExec " fable" $" {srcDir} --sourceMaps --run webpack"
73
76
74
77
Target.create " Build" ignore
75
78
76
79
Target.create " Watch" <| fun _ ->
77
- dotnetExec " fable" $" watch {srcDir} --sourceMaps --define DEBUG --run webpack -w"
80
+ dotnetExec " fable" $" watch {srcDir} --sourceMaps --define DEBUG --run webpack -w"
78
81
79
82
" Clean"
80
- ==> " YarnInstall"
81
- ==> " Restore"
82
- ==> " Prepare"
83
- ==> " Build"
83
+ ==> " YarnInstall"
84
+ ==> " Restore"
85
+ ==> " Prepare"
86
+ ==> " Build"
84
87
85
88
" Prepare"
86
- ?=> " BuildOnly"
87
- ==> " Build"
89
+ ?=> " BuildOnly"
90
+ ==> " Build"
88
91
89
92
" Prepare"
90
- ?=> " Watch"
93
+ ?=> " Watch"
91
94
92
95
// Test targets
93
96
94
97
module Test =
95
- let opamTool = platformTool " opam"
96
- let opam args = run opamTool " ./" args
97
- let dune args = run opamTool " ./" ( sprintf " exec -- dune %s " args)
98
-
99
- module Jsoo =
100
- let testDir = testDir </> " jsoo"
101
- let outputDir = outputDir </> " test_jsoo"
102
- let srcDir = testDir </> " src"
98
+ module Jsoo =
99
+ let testDir = testDir </> " jsoo"
100
+ let outputDir = outputDir </> " test_jsoo"
101
+ let srcDir = testDir </> " src"
103
102
104
- let generateBindings () =
105
- Directory.create outputDir
103
+ let generateBindings () =
104
+ Directory.create outputDir
106
105
107
- let ts2ocaml args files =
108
- Yarn.exec ( sprintf " ts2ocaml %s " ( String.concat " " ( Seq.append args files))) id
106
+ let ts2ocaml args files =
107
+ Yarn.exec ( sprintf " ts2ocaml %s " ( String.concat " " ( Seq.append args files))) id
109
108
110
- ts2ocaml [ " jsoo" ; " --verbose" ; " --nowarn" ; " --stdlib" ; $" -o {outputDir}" ] <|
111
- !! " node_modules/typescript/lib/lib.*.d.ts"
109
+ ts2ocaml [ " jsoo" ; " --verbose" ; " --nowarn" ; " --stdlib" ; $" -o {outputDir}" ] <|
110
+ !! " node_modules/typescript/lib/lib.*.d.ts"
112
111
113
- let packages = [
114
- // "full" package involving a lot of inheritance
115
- " full" , !! " node_modules/typescript/lib/typescript.d.ts" ;
112
+ let packages = [
113
+ // "full" package involving a lot of inheritance
114
+ " full" , !! " node_modules/typescript/lib/typescript.d.ts" ;
116
115
117
- // "full" packages involving a lot of dependencies (which includes some "safe" packages)
118
- " safe" , !! " node_modules/@types/scheduler/tracing.d.ts" ;
119
- " full" , !! " node_modules/csstype/index.d.ts" ;
120
- " safe" , !! " node_modules/@types/prop-types/index.d.ts" ;
121
- " full" , !! " node_modules/@types/react/index.d.ts" ++ " node_modules/@types/react/global.d.ts" ;
122
- " full" , !! " node_modules/@types/react-modal/index.d.ts" ;
116
+ // "full" packages involving a lot of dependencies (which includes some "safe" packages)
117
+ " safe" , !! " node_modules/@types/scheduler/tracing.d.ts" ;
118
+ " full" , !! " node_modules/csstype/index.d.ts" ;
119
+ " safe" , !! " node_modules/@types/prop-types/index.d.ts" ;
120
+ " full" , !! " node_modules/@types/react/index.d.ts" ++ " node_modules/@types/react/global.d.ts" ;
121
+ " full" , !! " node_modules/@types/react-modal/index.d.ts" ;
123
122
124
- // "safe" package which depends on another "safe" package
125
- " safe" , !! " node_modules/@types/yargs-parser/index.d.ts" ;
126
- " safe" , !! " node_modules/@types/yargs/index.d.ts" ;
127
- ]
123
+ // "safe" package which depends on another "safe" package
124
+ " safe" , !! " node_modules/@types/yargs-parser/index.d.ts" ;
125
+ " safe" , !! " node_modules/@types/yargs/index.d.ts" ;
126
+ ]
128
127
129
- for preset, package in packages do
130
- ts2ocaml [ " jsoo" ; " --verbose" ; " --nowarn" ; $" --preset {preset}" ; $" -o {outputDir}" ] package
128
+ for preset, package in packages do
129
+ ts2ocaml [ " jsoo" ; " --verbose" ; " --nowarn" ; $" --preset {preset}" ; $" -o {outputDir}" ] package
131
130
132
- let build () =
133
- for file in outputDir |> Shell.copyRecursiveTo true srcDir do
134
- printfn " * copied to %s " file
135
- Shell.cd testDir
136
- dune " build"
131
+ let build () =
132
+ for file in outputDir |> Shell.copyRecursiveTo true srcDir do
133
+ printfn " * copied to %s " file
134
+ Shell.cd testDir
135
+ dune " build"
137
136
138
137
Target.create " TestJsooGenerateBindings" <| fun _ -> Test.Jsoo.generateBindings ()
139
138
Target.create " TestJsooBuild" <| fun _ -> Test.Jsoo.build ()
140
139
Target.create " TestJsoo" ignore
141
140
142
141
" BuildOnly"
143
- ==> " TestJsooGenerateBindings"
144
- ==> " TestJsooBuild"
145
- ==> " TestJsoo"
142
+ ==> " TestJsooGenerateBindings"
143
+ ==> " TestJsooBuild"
144
+ ==> " TestJsoo"
146
145
147
146
Target.create " Test" ignore
148
147
Target.create " TestOnly" ignore
149
148
150
149
" TestJsoo"
151
- ==> " TestOnly"
152
- ==> " Test"
150
+ ==> " TestOnly"
151
+ ==> " Test"
153
152
154
153
" Build" ==> " Test"
155
154
156
155
// Deploy targets
157
156
158
- let changelogFile = " CHANGELOG.md"
159
- let changelog = Changelog.load changelogFile
160
-
161
157
module Deploy =
162
- let setPackageJson () =
163
- Yarn.exec $" version --new-version {changelog.LatestEntry.SemVer.AsString} --no-git-tag-version" id
158
+ let changelogFile = " CHANGELOG.md"
159
+ let changelog = Changelog.load changelogFile
160
+ let newVersion = changelog.LatestEntry.SemVer.AsString
161
+
162
+ module Npm =
163
+ let updateVersion () =
164
+ Yarn.exec $" version --new-version {newVersion} --no-git-tag-version" id
165
+
166
+ module Jsoo =
167
+ let targetDir = " ./dist_jsoo"
168
+ let duneProject = targetDir </> " dune-project"
169
+
170
+ let copyArtifacts () =
171
+ let mliDir = outputDir </> " test_jsoo"
172
+ let mlDir = testDir </> " jsoo/_build/default/src"
173
+ let targets = [ " ts2ocaml_es" ; " ts2ocaml_dom" ; " ts2ocaml_webworker" ]
174
+ let targetDir = targetDir </> " src"
175
+ for target in targets do
176
+ Shell.copyFile targetDir ( mliDir </> $" {target}.mli" )
177
+ Shell.copyFile targetDir ( mlDir </> $" {target}.ml" )
178
+
179
+ let versionRegex =
180
+ String.getRegEx " \\ (version ((?>\\ w\\ .)*\\ w)\\ )"
181
+
182
+ let updateVersion () =
183
+ File.read duneProject
184
+ |> Seq.map ( fun line ->
185
+ let result = versionRegex.Match line
186
+ if result.Success then
187
+ let oldVersion = result.Groups.[ 1 ]. Value
188
+ if oldVersion <> newVersion then
189
+ printfn $" * updating version in dist_jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
190
+ " (version ${newVersion})"
191
+ else
192
+ printfn $" * version in dist_jsoo/dune-project not updated ('{newVersion}')."
193
+ line
194
+ else
195
+ line)
196
+ |> File.write false duneProject
197
+
198
+ Target.create " Deploy" <| fun _ -> ()
199
+ Target.create " DeployOnly" <| fun _ -> ()
200
+
201
+ Target.create " DeployNpm" <| fun _ ->
202
+ Deploy.Npm.updateVersion ()
203
+
204
+ Target.create " DeployJsoo" <| fun _ ->
205
+ Deploy.Jsoo.copyArtifacts ()
206
+ Deploy.Jsoo.updateVersion ()
207
+
208
+ " BuildOnly"
209
+ ==> " DeployNpm"
210
+ ==> " DeployJsoo"
211
+ ==> " DeployOnly"
212
+ ==> " Deploy"
213
+
214
+ " Build" ==> " Deploy"
164
215
165
216
// start build
166
217
Target.runOrDefault " Build"
0 commit comments