Skip to content

Commit

Permalink
Refactor command execution in index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
maastrich committed Nov 10, 2023
1 parent 810dec9 commit edeea31
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ for (const [name, workspaces] of commands) {
.usage(`${name} [...workspaces] [options]`)
.action(async (wss: Array<string>, options) => {
const args = ["moon", "run"];
const rest = options["--"] ?? [];
const rest = ["--", ...options["--"]];
if (wss.length === 0) {
return Bun.spawnSync({
cmd: [...args, `:${name}`, ...rest],
cmd: [args, `:${name}`, "--", rest].flat(),
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
onExit(_, exitCode) {
if (exitCode) {
logger.error(`task ${name} failed`);
process.exit(exitCode);
}
},
});
}
wss = wss.filter((ws) => {
Expand All @@ -43,10 +49,16 @@ for (const [name, workspaces] of commands) {
return;
}
return Bun.spawnSync({
cmd: [...args, ...wss.map((ws) => `${name}:${ws}`), ...rest],
cmd: [args, wss.map((ws) => `${name}:${ws}`), rest].flat(),
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
onExit(_, exitCode) {
if (exitCode) {
logger.error(`task ${name} failed`);
process.exit(exitCode);
}
},
});
});
}
Expand Down

0 comments on commit edeea31

Please sign in to comment.