forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x.mjs
executable file
·226 lines (199 loc) · 5.55 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/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";
import {
launchRspackCli,
launchJestWithArgs
} from "./scripts/debug/launch.mjs";
process.env.CARGO_TERM_COLOR = "always"; // Assume every terminal that using zx supports color
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: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");
const watchCommand = program.command("watch").alias("w").description("watch");
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`);
});
watchCommand
.option("-a", "watch all")
.option("-b", "watch rust binding")
.option("-j", "watch 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 watch:${mode}`);
j && (await $`pnpm --filter "@rspack/*" watch`);
});
// 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 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 unit`;
});
// x test webpack
testCommand
.command("webpack")
.description("run webpack test suites")
.action(async function () {
await $`pnpm --filter "webpack-test" test`;
});
// x rspack / x rs
const rspackCommand = program.command("rspack").alias("rs").description(`
$ x rspack -- [your-rspack-cli-args...]
$ x rspack --debug -- build
$ x rs -d -- build
$ x rsd -- build
`);
rspackCommand
.option("-d, --debug", "Launch debugger in VSCode")
.action(async function ({ debug }) {
if (!debug) {
await $`npx rspack ${getVariadicArgs()}`;
return;
}
await launchRspackCli(getVariadicArgs());
});
// x rsd
program
.command("rspack-debug")
.alias("rsd")
.description("Alias for `x rspack --debug`")
.action(async function () {
await launchRspackCli(getVariadicArgs());
});
// x jest / x j
const jestCommand = program.command("jest").alias("j").description(`
$ x jest -- [your-jest-args...]
$ x jest --debug -- -t <test-name-pattern>
$ x j -d -- [test-path-pattern]
$ x jd -- [your-jest-args...]
`);
jestCommand
.option("-d, --debug", "Launch debugger in VSCode")
.action(async ({ debug }) => {
if (!debug) {
await $`npx jest ${getVariadicArgs()}`;
return;
}
await launchJestWithArgs(getVariadicArgs());
});
// x jd
program
.command("jest-debug")
.alias("jd")
.description("Alias for `x jest --debug`")
.action(async function () {
await launchJestWithArgs(getVariadicArgs());
});
program
.command("version")
.argument("<bump_version>", "bump version to (major|minor|patch|snapshot)")
.description("bump version")
.action(version_handler);
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" });
// Get args after `--`
function getVariadicArgs() {
let idx = argv.findIndex(c => c === "--");
return idx === -1 ? [] : argv.slice(idx + 1);
}