forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrescript_dump.js
57 lines (52 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
52
53
54
55
56
57
//@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");
var specs = [];
/**
* @param {string[]} argv
* @param {string} bsb_exe
* @param {string} bsc_exe
*/
function main(argv, bsb_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(
bsb_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;