fix: update gateway watch runner
This commit is contained in:
@@ -80,7 +80,7 @@
|
|||||||
"ui:build": "node scripts/ui.js build",
|
"ui:build": "node scripts/ui.js build",
|
||||||
"start": "tsx src/entry.ts",
|
"start": "tsx src/entry.ts",
|
||||||
"clawdbot": "tsx src/entry.ts",
|
"clawdbot": "tsx src/entry.ts",
|
||||||
"gateway:watch": "tsx watch src/entry.ts gateway --force",
|
"gateway:watch": "node scripts/gateway-watch.mjs gateway --force",
|
||||||
"gateway:dev": "CLAWDBOT_SKIP_CHANNELS=1 tsx src/entry.ts --dev gateway",
|
"gateway:dev": "CLAWDBOT_SKIP_CHANNELS=1 tsx src/entry.ts --dev gateway",
|
||||||
"gateway:dev:reset": "CLAWDBOT_SKIP_CHANNELS=1 tsx src/entry.ts --dev gateway --reset",
|
"gateway:dev:reset": "CLAWDBOT_SKIP_CHANNELS=1 tsx src/entry.ts --dev gateway --reset",
|
||||||
"tui": "tsx src/entry.ts tui",
|
"tui": "tsx src/entry.ts tui",
|
||||||
|
|||||||
53
scripts/gateway-watch.mjs
Normal file
53
scripts/gateway-watch.mjs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { spawn } from "node:child_process";
|
||||||
|
import { existsSync } from "node:fs";
|
||||||
|
import { setTimeout as delay } from "node:timers/promises";
|
||||||
|
import process from "node:process";
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const env = { ...process.env };
|
||||||
|
const cwd = process.cwd();
|
||||||
|
|
||||||
|
const tsc = spawn("pnpm", ["exec", "tsc", "--watch", "--preserveWatchOutput"], {
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
let nodeProcess = null;
|
||||||
|
let exiting = false;
|
||||||
|
|
||||||
|
async function waitForEntry() {
|
||||||
|
while (!existsSync("dist/entry.js")) {
|
||||||
|
if (exiting) return;
|
||||||
|
await delay(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startNode() {
|
||||||
|
nodeProcess = spawn(process.execPath, ["--watch", "dist/entry.js", ...args], {
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup(code = 0) {
|
||||||
|
if (exiting) return;
|
||||||
|
exiting = true;
|
||||||
|
nodeProcess?.kill("SIGTERM");
|
||||||
|
tsc.kill("SIGTERM");
|
||||||
|
process.exit(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on("SIGINT", () => cleanup(130));
|
||||||
|
process.on("SIGTERM", () => cleanup(143));
|
||||||
|
process.on("exit", () => cleanup());
|
||||||
|
|
||||||
|
tsc.on("exit", (code) => {
|
||||||
|
if (exiting) return;
|
||||||
|
cleanup(code ?? 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitForEntry();
|
||||||
|
if (!exiting) startNode();
|
||||||
Reference in New Issue
Block a user