-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathrescript_dump.js
51 lines (47 loc) · 1.21 KB
/
rescript_dump.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
//@ts-check
var arg = require("./rescript_arg.js");
var dump_usage = `Usage: rescript dump <options> [target]
\`rescript dump\` dumps the information for the target
`;
var child_process = require("child_process");
var path = require("path");
/**
* @type {arg.specs}
*/
var specs = [];
/**
* @param {string[]} argv
* @param {string} rescript_exe
* @param {string} bsc_exe
*/
function main(argv, rescript_exe, bsc_exe) {
var target;
arg.parse_exn(dump_usage, argv, specs, xs => {
if (xs.length !== 1) {
arg.bad_arg(`Expect only one target, ${xs.length} found`);
}
target = xs[0];
});
var { ext } = path.parse(target);
if (ext !== ".cmi") {
console.error("Only .cmi target allowed");
process.exit(2);
}
var output = child_process.spawnSync(rescript_exe, ["build", "--", target], {
encoding: "utf-8",
});
if (output.status !== 0) {
console.log(output.stdout);
console.error(output.stderr);
process.exit(2);
}
output = child_process.spawnSync(bsc_exe, [path.join("lib", "bs", target)], {
encoding: "utf-8",
});
console.log(output.stdout.trimEnd());
if (output.status !== 0) {
console.error(output.stderr);
process.exit(2);
}
}
exports.main = main;