fix: run cli scripts via node build runner
This commit is contained in:
38
scripts/run-node.mjs
Normal file
38
scripts/run-node.mjs
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawn } from "node:child_process";
|
||||
import process from "node:process";
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const env = { ...process.env };
|
||||
const cwd = process.cwd();
|
||||
|
||||
const build = spawn("pnpm", ["exec", "tsc", "-p", "tsconfig.json"], {
|
||||
cwd,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
build.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.exit(1);
|
||||
return;
|
||||
}
|
||||
if (code !== 0 && code !== null) {
|
||||
process.exit(code);
|
||||
return;
|
||||
}
|
||||
|
||||
const nodeProcess = spawn(process.execPath, ["dist/entry.js", ...args], {
|
||||
cwd,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
nodeProcess.on("exit", (exitCode, exitSignal) => {
|
||||
if (exitSignal) {
|
||||
process.exit(1);
|
||||
return;
|
||||
}
|
||||
process.exit(exitCode ?? 1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user