Skip to content

Commit 5ead996

Browse files
authoredApr 27, 2020
Merge pull request #4334 from jchavarri/playground-action
[Playground] Add new workflow to build an npm-ready package
2 parents 523b1d2 + 0c046d4 commit 5ead996

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed
 

Diff for: ‎.github/workflows/playground.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build playground
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
run:
8+
name: Build
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [macos-latest, ubuntu-latest]
14+
ocaml-version: ["4.06.1"]
15+
node-version: [12.x]
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2.0.0
19+
- name: Cache .opam folder
20+
id: cache-opam
21+
uses: actions/cache@v1
22+
with:
23+
path: ~/.opam
24+
key: ${{ runner.os }}-opam-${{ matrix.ocaml-version }}-3.5.1-v1
25+
- name: Use OCaml ${{ matrix.ocaml-version }}
26+
uses: avsm/setup-ocaml@v1.0
27+
with:
28+
ocaml-version: ${{ matrix.ocaml-version }}
29+
- if: steps.cache-opam.outputs.cache-hit != 'true'
30+
run: opam install js_of_ocaml.3.5.1
31+
- run: git submodule update --init && ./scripts/buildocaml.js
32+
- run: ./scripts/ninja.js config && ./scripts/ninja.js build
33+
- run: mkdir playground && mkdir playground/stdlib
34+
- run: BS_PLAYGROUND=../playground ./scripts/repl.js -prepublish
35+
- run: node -e "require('./exports.js'); eval(ocaml.compile('Js.log Sys.ocaml_version').js_code)"
36+
working-directory: ./playground
37+
- name: Archive npm artifacts
38+
uses: actions/upload-artifact@v1
39+
with:
40+
name: reason-js-compiler
41+
path: playground
42+

Diff for: ‎scripts/repl.js

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
var p = require("child_process");
4-
4+
var fs = require("fs");
55
var path = require("path");
66

77

@@ -32,17 +32,46 @@ if (!process.env.BS_PLAYGROUND) {
3232
var playground = process.env.BS_PLAYGROUND;
3333

3434
function prepare() {
35-
e(`hash hash js_of_ocaml 2>/dev/null || { echo >&2 "js_of_ocaml not found on path. Please install version 3.5.1 (with opam switch ${ocamlVersion}), and put it on your path."; exit 1; }
35+
e(`opam exec -- js_of_ocaml 2>/dev/null || { echo >&2 "js_of_ocaml not found on path. Please install version 3.5.1 (with opam switch ${ocamlVersion}), and put it on your path."; exit 1; }
3636
`);
3737

3838
e(
39-
`ocamlc.opt -w -30-40 -no-check-prims -I ${jsRefmtCompDir} ${jsRefmtCompDir}/js_compiler.mli ${jsRefmtCompDir}/js_compiler.ml -o jsc.byte && js_of_ocaml jsc.byte -o exports.js`
39+
`opam exec -- ocamlc.opt -w -30-40 -no-check-prims -I ${jsRefmtCompDir} ${jsRefmtCompDir}/js_refmt_compiler.mli ${jsRefmtCompDir}/js_refmt_compiler.ml -o jsc.byte && opam exec -- js_of_ocaml jsc.byte -o exports.js`
4040
);
4141

4242
e(`cp ../lib/js/*.js ${playground}/stdlib`);
4343
e(`mv ./exports.js ${playground}`)
4444
}
4545

46+
function prepublish() {
47+
var mainPackageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')));
48+
var packageJson = JSON.stringify(
49+
{
50+
name: "reason-js-compiler",
51+
version: mainPackageJson.version,
52+
license: mainPackageJson.license,
53+
description: mainPackageJson.description,
54+
repository: mainPackageJson.repository,
55+
author: mainPackageJson.author,
56+
maintainers: mainPackageJson.maintainers,
57+
bugs: mainPackageJson.bugs,
58+
homepage: mainPackageJson.homepage,
59+
main: "exports.js",
60+
},
61+
null,
62+
2
63+
);
4664

47-
prepare();
65+
fs.writeFileSync(
66+
jscompDir + `/${playground}/package.json`,
67+
packageJson,
68+
{
69+
encoding: "utf8",
70+
}
71+
);
72+
}
4873

74+
prepare();
75+
if (process.argv.includes("-prepublish")) {
76+
prepublish();
77+
}

0 commit comments

Comments
 (0)
Please sign in to comment.