Files
pikasTech-HWLAB/tools/device-pod-cli.mjs
T

45 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const runBun = path.join(root, "scripts", "run-bun.mjs");
const cli = path.join(root, "tools", "device-pod-cli.ts");
if (!existsSync(runBun) || !existsSync(cli)) {
console.log(JSON.stringify({
generatedAt: new Date().toISOString(),
cli: "device-pod-cli",
ok: false,
status: "failed",
error: {
code: "device_pod_cli_entrypoint_missing",
message: "device-pod-cli TypeScript entrypoint or Bun runner is missing",
runBun,
cli
}
}, null, 2));
process.exitCode = 127;
} else {
const cliArgs = process.argv.slice(2).map((arg) => (arg === "--help" || arg === "-h" ? "help" : arg));
const result = spawnSync(process.execPath, [runBun, cli, ...cliArgs], {
cwd: root,
env: process.env,
stdio: "inherit"
});
if (result.error) {
console.log(JSON.stringify({
generatedAt: new Date().toISOString(),
cli: "device-pod-cli",
ok: false,
status: "failed",
error: { code: "device_pod_cli_spawn_failed", message: result.error.message }
}, null, 2));
process.exitCode = 127;
} else {
process.exitCode = result.status ?? 0;
}
}