33 lines
813 B
JavaScript
33 lines
813 B
JavaScript
#!/usr/bin/env node
|
|
|
|
import { spawn } from "node:child_process";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const [, , command, ...args] = process.argv;
|
|
if (!command) {
|
|
console.error("Usage: node scripts/run-go-command.mjs <go-command> [args...]");
|
|
process.exit(2);
|
|
}
|
|
|
|
const backendDirectory = fileURLToPath(new URL("../backend/", import.meta.url));
|
|
const child = spawn("go", [command, ...args], {
|
|
cwd: backendDirectory,
|
|
env: {
|
|
...process.env,
|
|
CGO_ENABLED: process.env.CGO_ENABLED || "0",
|
|
},
|
|
stdio: "inherit",
|
|
});
|
|
|
|
child.on("error", (error) => {
|
|
console.error(`[go:${command}] ${error.message}`);
|
|
process.exit(1);
|
|
});
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) {
|
|
console.error(`[go:${command}] terminated by ${signal}`);
|
|
process.exit(1);
|
|
}
|
|
process.exit(code ?? 1);
|
|
});
|