singularity-forge/scripts/dev.js
Jeremy McSpadden a79e953caa refactor: deduplicate help text, cross-platform validate-pack, fix dev.js
- Extract duplicated help text from loader.ts and cli.ts into shared
  help-text.ts module (single source of truth)
- Convert validate-pack.sh to Node.js for Windows compatibility
- Fix dev.js using unnecessary npx for tsc (it's a devDependency,
  use node_modules/.bin/tsc directly)
2026-03-16 13:29:31 -05:00

47 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/**
* Dev supervisor — runs tsc --watch and watch-resources.js in parallel.
*
* Both processes terminate together when either exits or when the parent
* receives SIGINT/SIGTERM. This avoids the problem with shell backgrounding
* (`&`) where the watcher can outlive tsc and orphan.
*/
import { spawn } from 'node:child_process'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const root = resolve(__dirname, '..')
const procs = [
spawn('node', [resolve(__dirname, 'watch-resources.js')], {
cwd: root, stdio: 'inherit'
}),
spawn(resolve(root, 'node_modules', '.bin', 'tsc'), ['--watch'], {
cwd: root, stdio: 'inherit'
})
]
function cleanup() {
for (const p of procs) {
try { p.kill() } catch {}
}
}
// If either child exits, kill the other and exit with its code
for (const p of procs) {
p.on('exit', (code) => {
cleanup()
process.exit(code ?? 1)
})
}
// Forward signals to children
for (const sig of ['SIGINT', 'SIGTERM']) {
process.on(sig, () => {
cleanup()
process.exit(0)
})
}