// Runs the Foundry Virtual Tabletop start script defined by FOUNDRY_START_SCRIPT // in the root .env file. Used by `npm run dev` via concurrently. const { spawn } = require('node:child_process'); const fs = require('node:fs'); const path = require('node:path'); try { process.loadEnvFile(path.join(__dirname, '..', '.env')); } catch { // No .env at the repo root: nothing to launch. } const script = process.env.FOUNDRY_START_SCRIPT; function idle(reason) { console.log(`[foundry] ${reason} — Foundry server not started.`); // Keep the process alive so concurrently (-k) does not kill the other dev servers. setInterval(() => {}, 1 << 30); } if (!script) idle('FOUNDRY_START_SCRIPT is not set in .env'); else if (!fs.existsSync(script)) idle(`start script not found: ${script}`); else { console.log(`[foundry] Running ${script}`); const child = spawn('sh', [script], { stdio: 'inherit', cwd: path.dirname(script) }); child.on('exit', (code, signal) => { if (signal) process.exit(0); // killed together with `npm run dev` idle(`exited with code ${code}`); }); child.on('error', (err) => idle(`failed to start: ${err.message}`)); }