forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrescript
executable file
·132 lines (117 loc) · 2.89 KB
/
rescript
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
//@ts-check
"use strict";
/**
* This script is supposed to be running in project root directory
* It matters since we need read .sourcedirs(location)
* and its content are file/directories with regard to project root
*/
var bsc_exe = require("./scripts/bin_path").bsc_exe;
var rescript_exe = require("./scripts/bin_path").rescript_exe;
var bsb = require("./scripts/rescript_bsb");
var cwd = process.cwd();
process.env.BSB_PROJECT_ROOT = cwd;
if (process.env.NINJA_ANSI_FORCED === undefined) {
if (require("tty").isatty(1)) {
process.env.NINJA_ANSI_FORCED = "1";
}
} else {
if (process.argv.includes("-verbose")) {
console.log(`NINJA_ANSI_FORCED: "${process.env.NINJA_ANSI_FORCED}"`);
}
}
const helpMessage = `Usage: rescript <options> <subcommand>
\`rescript\` is equivalent to \`rescript build\`
Options:
-v, -version display version number
-h, -help display help
Subcommands:
build
clean
format
convert
dump
help
Run \`rescript <subcommand> -h\` for subcommand help. Examples:
rescript build -h
rescript format -h`;
function onUncaughtException(err) {
console.error("Uncaught Exception", err);
bsb.releaseBuild();
process.exit(1);
}
function exitProcess() {
bsb.releaseBuild();
process.exit(0);
}
process.on("uncaughtException", onUncaughtException);
// OS signal handlers
// Ctrl+C
process.on("SIGINT", exitProcess);
// kill pid
process.on("SIGUSR1", exitProcess);
process.on("SIGUSR2", exitProcess);
process.on("SIGTERM", exitProcess);
process.on("SIGHUP", exitProcess);
const process_argv = process.argv;
const maybeSubcommand = process_argv[2];
if (!maybeSubcommand) {
bsb.build([]);
} else {
switch (maybeSubcommand) {
case "info": {
bsb.info(process_argv.slice(3));
break;
}
case "clean": {
bsb.clean(process_argv.slice(3));
break;
}
case "build": {
bsb.build(process_argv.slice(3));
break;
}
case "format":
require("./scripts/rescript_format.js").main(
process.argv.slice(3),
rescript_exe,
bsc_exe
);
break;
case "dump":
require("./scripts/rescript_dump.js").main(
process.argv.slice(3),
rescript_exe,
bsc_exe
);
break;
case "convert":
require("./scripts/rescript_convert.js").main(
process.argv.slice(3),
rescript_exe,
bsc_exe
);
break;
case "-h":
case "-help":
case "--help":
case "help":
console.log(helpMessage);
break;
case "-v":
case "-version":
case "--version":
case "version":
console.log(require("./package.json").version);
break;
default:
if (maybeSubcommand.startsWith("-")) {
bsb.build(process_argv.slice(2));
} else {
console.error(
`Error: Unknown command "${maybeSubcommand}".\n${helpMessage}`
);
process.exit(2);
}
}
}