-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathdump.js
More file actions
57 lines (50 loc) · 1.25 KB
/
dump.js
File metadata and controls
57 lines (50 loc) · 1.25 KB
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
import * as child_process from "node:child_process";
import * as path from "node:path";
import * as arg from "#cli/args";
const dump_usage = `Usage: rescript dump <options> [target]
\`rescript dump\` dumps the information for the target
`;
/**
* @type {arg.specs}
*/
const specs = [];
/**
* @param {string[]} argv
* @param {string} rescript_legacy_exe
* @param {string} bsc_exe
*/
export function main(argv, rescript_legacy_exe, bsc_exe) {
let 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];
});
const { ext } = path.parse(target);
if (ext !== ".cmi") {
console.error("Only .cmi target allowed");
process.exit(2);
}
let output = child_process.spawnSync(
rescript_legacy_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);
}
}