forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x.mjs
executable file
·60 lines (49 loc) · 1.35 KB
/
x.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
#!/usr/bin/env zx
import "zx/globals";
import { Command } from "commander";
process.env.FORCE_COLOR = 3; // Fix zx losing color output in subprocesses
const program = new Command();
program
.name("Rspack Development CLI")
.description("CLI for development of Rspack")
.showHelpAfterError(true)
.showSuggestionAfterError(true);
// x install
program
.command("install")
.alias("i")
.description("install all dependencies")
.action(async function () {
await $`pnpm install`;
});
// x clean
let cleanCommand = program
.command("clean")
.description("clean target/ directory");
// x clean all
cleanCommand.command("all").action(async function () {
await $`./x clean rust`;
});
// x clean rust
cleanCommand
.command("rust")
.description("clean target/ directory")
.action(async function () {
await $`cargo clean`;
within(async () => {
cd("crates/node_binding");
await $`cargo clean`;
});
});
// x build
const buildCommand = program.command("build").alias("b").description("build");
// x build binding
buildCommand.command("binding").action(async function () {
await $`pnpm --filter @rspack/binding build:debug`;
});
let argv = process.argv.slice(2); // remove the `node` and script call
if (argv[0] && /x.mjs/.test(argv[0])) {
// Called from `zx x.mjs`
argv = argv.slice(1);
}
program.parse(argv, { from: "user" });