Skip to content

Commit

Permalink
feat(x.mjs): add x clean command (#2980)
Browse files Browse the repository at this point in the history
feat(x.mjs): add `x clean` along with `x clean node` and `x clean rust` commands.
  • Loading branch information
Boshen authored May 4, 2023
1 parent f75eb7b commit aa32a97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "A Fast Rust-based web bundler",
"private": true,
"scripts": {
"x": "./x.mjs",
"x": "zx x.mjs",
"dev": "pnpm --filter @rspack/cli run dev",
"clean": "pnpm --filter @rspack/cli run clean",
"build:js": "pnpm --filter \"@rspack/*\" build",
Expand Down
29 changes: 28 additions & 1 deletion x.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ program
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");

Expand All @@ -30,4 +52,9 @@ buildCommand.command("binding").action(async function () {
await $`pnpm --filter @rspack/binding build:debug`;
});

program.parse(process.argv.slice(3), { from: "user" });
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" });

0 comments on commit aa32a97

Please sign in to comment.