forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
executable file
·91 lines (83 loc) · 2.44 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/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 config = {
cwd: jscompDir,
encoding: "utf8",
stdio: [0, 1, 2],
shell: true,
};
/**
*
* @param {string} cmd
*/
function e(cmd) {
console.log(`>>>>>> running command: ${cmd}`);
p.execSync(cmd, config);
console.log(`<<<<<<`);
}
if (!process.env.BS_PLAYGROUND) {
var defaultPlayground = `../../bucklescript-playground`;
console.warn(
`BS_PLAYGROUND env var unset, defaulting to ${defaultPlayground}`
);
process.env.BS_PLAYGROUND = defaultPlayground;
}
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(isDev) {
var [env, ocamlFlag, jsooFlag] = isDev
? ["development", "-g ", "--pretty "]
: ["production", "", ""];
console.log(`building byte code version of the compiler [${env}]`);
e(
`${OCAMLC} ${ocamlFlag}-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 ${jsooFlag}-o exports.js`);
console.log("copy js artifacts");
e(`cp ../lib/js/*.js ${playground}/stdlib`);
e(`mv ./exports.js ${playground}`);
}
function prepublish() {
var mainPackageJson = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"))
);
var packageJson = JSON.stringify(
{
name: "reason-js-compiler",
version: mainPackageJson.version,
license: mainPackageJson.license,
description: mainPackageJson.description,
repository: mainPackageJson.repository,
author: mainPackageJson.author,
maintainers: mainPackageJson.maintainers,
bugs: mainPackageJson.bugs,
homepage: mainPackageJson.homepage,
main: "exports.js",
},
null,
2
);
fs.writeFileSync(jscompDir + `/${playground}/package.json`, packageJson, {
encoding: "utf8",
});
}
prepare(process.argv.includes("-development"));
if (process.argv.includes("-prepublish")) {
prepublish();
}