forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx.mjs
executable file
·150 lines (132 loc) · 3.67 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env zx
import "zx/globals";
import { Command } from "commander";
import { version_handler } from "./scripts/release/version.mjs";
import { publish_handler } from "./scripts/release/publish.mjs";
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 ready
program
.command("ready")
.alias("r")
.description("ready to create a pull request, build and run all tests")
.action(async function () {
await $`cargo check`;
await $`cargo lint`;
await $`cargo test`;
await $`pnpm install`;
await $`pnpm run build:cli:release`;
await $`pnpm run test:example`;
await $`pnpm run test:unit`;
console.log(chalk.green("All passed."));
});
// 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`;
});
// x build
const buildCommand = program.command("build").alias("b").description("build");
buildCommand
.option("-a", "build all")
.option("-b", "build rust binding")
.option("-j", "build js packages")
.option("-r", "release")
.action(async function ({ a, b = a, j = a, r }) {
let mode = r ? "release" : "debug";
b && (await $`pnpm --filter @rspack/binding build:${mode}`);
j && (await $`pnpm --filter "@rspack/*" build`);
});
// x build binding
buildCommand
.command("binding")
.description("build rust binding")
.action(async function () {
await $`pnpm --filter @rspack/binding build:debug`;
});
// x build js
buildCommand
.command("js")
.description("build js packages")
.action(async function () {
await $`pnpm --filter "@rspack/*" build`;
});
// x test
const testCommand = program.command("test").alias("t").description("test");
// x test rust
testCommand
.command("rust")
.description("run cargo tests")
.action(async function () {
await $`cargo test`;
});
// x test example
testCommand
.command("example")
.description("build examples")
.action(async function () {
await $`pnpm --filter "example-*" build`;
});
// x test unit
testCommand
.command("unit")
.description("run all unit tests")
.action(async function () {
await $`./x build js`;
await $`pnpm --filter "@rspack/*" test`;
});
// x test ci
testCommand
.command("ci")
.description("run tests for ci")
.action(async function () {
await $`./x test example`;
await $`./x test unit`;
});
let versionCommand = program
.command("version")
.argument("<bump_version>", "bump version to (major|minor|patch|snapshot)")
.description("bump version")
.action(version_handler);
let releaseCommand = program
.command("publish")
.argument("<mode>", "publish mode (snapshot|stable)")
.requiredOption("--tag <char>", "publish tag")
.option(
"--dry-run",
"Does everything a publish would do except actually publishing to the registry"
)
.option("--no-dry-run", "negative dry-run")
.option("--push-tags", "push tags to github")
.option("--no-push-tags", "don't push tags to github")
.description("publish package after version bump")
.action(publish_handler);
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" });