Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
/**
|
|
* Force process env KEY=VAL pairs, then spawn the command after `--`.
|
|
* Values passed here always override so children that load monorepo `.env`
|
|
* but skip pre-set keys (run-in-dir / Vite) pick up these ports.
|
|
*
|
|
* Usage: node scripts/with-forced-env.mjs KEY=val KEY=val -- command [args...]
|
|
*/
|
|
import { spawn } from "node:child_process";
|
|
|
|
const sep = process.argv.indexOf("--");
|
|
if (sep < 0 || sep === process.argv.length - 1) {
|
|
console.error("Usage: node scripts/with-forced-env.mjs KEY=val -- command [args...]");
|
|
process.exit(1);
|
|
}
|
|
|
|
const env = { ...process.env };
|
|
for (const raw of process.argv.slice(2, sep)) {
|
|
const eq = raw.indexOf("=");
|
|
if (eq <= 0) {
|
|
console.error(`Invalid KEY=val: ${raw}`);
|
|
process.exit(1);
|
|
}
|
|
env[raw.slice(0, eq)] = raw.slice(eq + 1);
|
|
}
|
|
|
|
const [command, ...args] = process.argv.slice(sep + 1);
|
|
const child = spawn(command, args, {
|
|
stdio: "inherit",
|
|
shell: process.platform === "win32",
|
|
env,
|
|
});
|
|
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) {
|
|
process.kill(process.pid, signal);
|
|
return;
|
|
}
|
|
process.exit(code ?? 1);
|
|
});
|