Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building playground on the fly #4372

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions scripts/repl.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#!/usr/bin/env node

//@ts-check
var p = require("child_process");
var fs = require("fs");
var path = require("path");


var ocamlVersion = "4.06.1";
var jscompDir = path.join(__dirname, "..", "jscomp");
var jsRefmtCompDir = path.join(__dirname, "..", "lib", ocamlVersion, "unstable");
var jsRefmtCompDir = path.join(
__dirname,
"..",
"lib",
ocamlVersion,
"unstable"
);

var config = {
cwd: jscompDir,
encoding: "utf8",
stdio: [0, 1, 2],
shell: true
shell: true,
};
/**
*
* @param {string} cmd
*/
function e(cmd) {
console.log(`>>>>>> running command: ${cmd}`);
p.execSync(cmd, config);
Expand All @@ -31,20 +40,27 @@ if (!process.env.BS_PLAYGROUND) {

var playground = process.env.BS_PLAYGROUND;

var nativePath = path.join(__dirname, "..", "native", "4.06.1", "bin");
var OCAMLC = path.join(nativePath, "ocamlc.opt");
var OCAMLRUN = path.join(nativePath, "ocamlrun");
var JSOO = path.join(__dirname, "..", "vendor", "js_of_ocaml.bc");
function prepare() {
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; }
`);

console.log("building byte code version of the compiler");
e(
`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`
`${OCAMLC} -w -30-40 -no-check-prims -I ${jsRefmtCompDir} ${jsRefmtCompDir}/js_refmt_compiler.mli ${jsRefmtCompDir}/js_refmt_compiler.ml -o jsc.byte `
);

console.log("building js version");
e(`${OCAMLRUN} ${JSOO} compile jsc.byte -o exports.js`);
// e() js_of_ocaml jsc.byte -o exports.js
console.log("copy js artifacts");
e(`cp ../lib/js/*.js ${playground}/stdlib`);
e(`mv ./exports.js ${playground}`)
e(`mv ./exports.js ${playground}`);
}

function prepublish() {
var mainPackageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')));
var mainPackageJson = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"))
);
var packageJson = JSON.stringify(
{
name: "reason-js-compiler",
Expand All @@ -62,13 +78,9 @@ function prepublish() {
2
);

fs.writeFileSync(
jscompDir + `/${playground}/package.json`,
packageJson,
{
encoding: "utf8",
}
);
fs.writeFileSync(jscompDir + `/${playground}/package.json`, packageJson, {
encoding: "utf8",
});
}

prepare();
Expand Down
Binary file added vendor/js_of_ocaml.bc
Binary file not shown.