-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcheerp.mjs
executable file
·63 lines (55 loc) · 1.53 KB
/
cheerp.mjs
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
#!/usr/bin/env node
import { path } from "../index.mjs";
import { resolve } from "path";
import { spawnSync } from "child_process";
const [, , binName, ...args] = process.argv;
let exitCode = 0;
switch (binName) {
case "clang":
case "clang++":
runCommand(binName, args);
break;
case "prefix":
console.log(path);
break;
default:
console.error(`unknown command: ${binName}`);
console.log("");
exitCode = 1;
// fallthrough
case undefined:
case "":
case "help":
showHelp();
break;
}
process.exit(exitCode);
function showHelp() {
console.log(`Cheerp 3.0 (https://labs.leaningtech.com/cheerp)`);
console.log(``);
console.log(`Usage:`)
console.log(` $ cheerp [command] [options]`);
console.log(``);
console.log(`Commands:`);
console.log(` clang C compiler`);
console.log(` clang++ C++ compiler`);
console.log(` prefix Print installation path prefix`);
console.log(` help Display this message`);
}
function runCommand(binName, args) {
const suffix = process.platform === "win32" ? ".exe" : "";
const binPath = resolve(path, "bin", binName + suffix);
const { error, status } = spawnSync(binPath, args, {
shell: false,
stdio: "inherit",
});
if (error) {
if (error.code === "ENOENT") {
console.error(`executable not found: ${binPath}`);
console.error("installation has failed, please report this issue: https://github.com/leaningtech/cheerp-meta/issues");
process.exit(127);
}
throw error;
}
exitCode = status;
}