|
| 1 | +//@ts-check |
| 2 | +var arg = require("./rescript_arg.js"); |
| 3 | +var dump_usage = `Usage: rescript dump <options> [target] |
| 4 | +\`rescript dump\` dumps the information for the target |
| 5 | +`; |
| 6 | +var child_process = require("child_process"); |
| 7 | +var path = require("path"); |
| 8 | +var specs = []; |
| 9 | + |
| 10 | +/** |
| 11 | + * @param {string[]} argv |
| 12 | + * @param {string} bsb_exe |
| 13 | + * @param {string} bsc_exe |
| 14 | + */ |
| 15 | +function main(argv, bsb_exe, bsc_exe) { |
| 16 | + var target; |
| 17 | + arg.parse_exn(dump_usage, argv, specs, (xs) => { |
| 18 | + if (xs.length !== 1) { |
| 19 | + arg.bad_arg(`Expect only one target, ${xs.length} found` ); |
| 20 | + } |
| 21 | + target = xs[0]; |
| 22 | + }); |
| 23 | + |
| 24 | + var { ext } = path.parse(target); |
| 25 | + if (ext !== ".cmi") { |
| 26 | + console.error("Only .cmi target allowed"); |
| 27 | + process.exit(2); |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + var output = child_process.spawnSync( |
| 32 | + bsb_exe, |
| 33 | + ["build", "--", target], |
| 34 | + { |
| 35 | + encoding: "utf-8", |
| 36 | + } |
| 37 | + ); |
| 38 | + if (output.status !== 0) { |
| 39 | + console.log(output.stdout); |
| 40 | + console.error(output.stderr); |
| 41 | + process.exit(2); |
| 42 | + } |
| 43 | + output = child_process.spawnSync( |
| 44 | + bsc_exe, |
| 45 | + [path.join("lib", "bs", target)], |
| 46 | + { |
| 47 | + encoding: "utf-8", |
| 48 | + } |
| 49 | + ); |
| 50 | + console.log(output.stdout.trimEnd()); |
| 51 | + if (output.status !== 0) { |
| 52 | + console.error(output.stderr); |
| 53 | + process.exit(2); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +exports.main = main; |
0 commit comments