// 독립 EST 테스트 서버 감시/감독 프로세스 const { spawn } = require("node:child_process"); const fs = require("node:fs"); const path = require("node:path"); const base = __dirname; const serverScript = path.join(base, "server.cjs"); // data 디렉터리, 로그 파일 등은 제외하고 소스코드 파일만 명시적으로 감시 대상에 포함 const watchArgs = fs .readdirSync(base) .filter( (file) => (file.endsWith(".js") || file.endsWith(".cjs") || file === "index.html" || file === "native.css") && !file.startsWith(".") && file !== "watch-server.cjs", ) .map((file) => `--watch-path=${path.join(base, file)}`); const args = ["--watch", ...watchArgs, serverScript]; console.log("[supervisor] Starting server with watch paths (excluding data/)..."); const child = spawn(process.execPath, args, { cwd: base, env: process.env, stdio: "inherit", }); child.on("exit", (code, signal) => { console.log(`[supervisor] Server exited with code ${code}, signal ${signal}`); process.exit(code || 0); }); for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) { process.on(sig, () => { child.kill(sig); process.exit(0); }); }