Skip to content

Commit dd5a04f

Browse files
committed
Add a distribution directory for jsoo target
1 parent c99b848 commit dd5a04f

File tree

6 files changed

+203
-78
lines changed

6 files changed

+203
-78
lines changed

build.fsx

Lines changed: 129 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -27,140 +27,191 @@ let distDir = "./dist"
2727
let testDir = "./test"
2828

2929
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
3636

3737
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
4040

4141
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)
4549

4650
// Build targets
4751

4852
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
5458

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
5862

5963
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"
6367

6468
Target.create "YarnInstall" <| fun _ ->
65-
Yarn.installFrozenLockFile (fun ``params`` ->
66-
{ ``params`` with
67-
WorkingDirectory = "./" })
69+
Yarn.installFrozenLockFile (fun ``params`` ->
70+
{ ``params`` with WorkingDirectory = "./" })
6871

6972
Target.create "Prepare" ignore
7073

7174
Target.create "BuildOnly" <| fun _ ->
72-
dotnetExec "fable" $"{srcDir} --sourceMaps --run webpack"
75+
dotnetExec "fable" $"{srcDir} --sourceMaps --run webpack"
7376

7477
Target.create "Build" ignore
7578

7679
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"
7881

7982
"Clean"
80-
==> "YarnInstall"
81-
==> "Restore"
82-
==> "Prepare"
83-
==> "Build"
83+
==> "YarnInstall"
84+
==> "Restore"
85+
==> "Prepare"
86+
==> "Build"
8487

8588
"Prepare"
86-
?=> "BuildOnly"
87-
==> "Build"
89+
?=> "BuildOnly"
90+
==> "Build"
8891

8992
"Prepare"
90-
?=> "Watch"
93+
?=> "Watch"
9194

9295
// Test targets
9396

9497
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"
103102

104-
let generateBindings () =
105-
Directory.create outputDir
103+
let generateBindings () =
104+
Directory.create outputDir
106105

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
109108

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"
112111

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";
116115

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";
123122

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+
]
128127

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
131130

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"
137136

138137
Target.create "TestJsooGenerateBindings" <| fun _ -> Test.Jsoo.generateBindings ()
139138
Target.create "TestJsooBuild" <| fun _ -> Test.Jsoo.build ()
140139
Target.create "TestJsoo" ignore
141140

142141
"BuildOnly"
143-
==> "TestJsooGenerateBindings"
144-
==> "TestJsooBuild"
145-
==> "TestJsoo"
142+
==> "TestJsooGenerateBindings"
143+
==> "TestJsooBuild"
144+
==> "TestJsoo"
146145

147146
Target.create "Test" ignore
148147
Target.create "TestOnly" ignore
149148

150149
"TestJsoo"
151-
==> "TestOnly"
152-
==> "Test"
150+
==> "TestOnly"
151+
==> "Test"
153152

154153
"Build" ==> "Test"
155154

156155
// Deploy targets
157156

158-
let changelogFile = "CHANGELOG.md"
159-
let changelog = Changelog.load changelogFile
160-
161157
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"
164215

165216
// start build
166217
Target.runOrDefault "Build"

dist_jsoo/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ts2ocaml-stdlib.install
2+
*.merlin
3+
_build
4+
_opam
5+
.vscode
6+
build
7+
node_modules
8+
src/ts2ocaml_*.ml*

dist_jsoo/dune-project

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(lang dune 2.7)
2+
(name ts2ocaml-stdlib)
3+
(version 0.0.0)
4+
5+
(maintainers "[email protected]")
6+
(authors
7+
"The ocsigen team")
8+
9+
(source (github ocsigen/ts2ocaml))
10+
11+
(generate_opam_files true)
12+
13+
(license Apache-2.0)
14+
15+
(package
16+
(name ts2ocaml-stdlib)
17+
(synopsis "Standard Library for ts2ocaml generated bindings")
18+
(description "You can choose not to use this standard library. See the documents in the repository.")
19+
(depends
20+
(ocaml (>= 4.08))
21+
(ojs (>= 1.0.8))))

dist_jsoo/src/dune

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(library
2+
(name ts2ocaml)
3+
(public_name ts2ocaml-stdlib)
4+
(libraries ojs)
5+
(wrapped false)
6+
(modes byte)
7+
(js_of_ocaml
8+
(flags --pretty --enable deadcode --enable strict --enable inline)))

dist_jsoo/src/ts2ocaml.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include Ts2ocaml_min
2+
include Ts2ocaml_es
3+
4+
module Dom = Ts2ocaml_dom
5+
module WebWorker = Ts2ocaml_webworker

dist_jsoo/ts2ocaml-stdlib.opam

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file is generated by dune, edit dune-project instead
2+
opam-version: "2.0"
3+
version: "0.0.0"
4+
synopsis: "Standard Library for ts2ocaml generated bindings"
5+
description:
6+
"You can choose not to use this standard library. See the documents in the repository."
7+
maintainer: ["[email protected]"]
8+
authors: ["The ocsigen team"]
9+
license: "Apache-2.0"
10+
homepage: "https://github.com/ocsigen/ts2ocaml"
11+
bug-reports: "https://github.com/ocsigen/ts2ocaml/issues"
12+
depends: [
13+
"dune" {>= "2.7"}
14+
"ocaml" {>= "4.08"}
15+
"ojs" {>= "1.0.8"}
16+
"odoc" {with-doc}
17+
]
18+
build: [
19+
["dune" "subst"] {dev}
20+
[
21+
"dune"
22+
"build"
23+
"-p"
24+
name
25+
"-j"
26+
jobs
27+
"@install"
28+
"@runtest" {with-test}
29+
"@doc" {with-doc}
30+
]
31+
]
32+
dev-repo: "git+https://github.com/ocsigen/ts2ocaml.git"

0 commit comments

Comments
 (0)