Skip to content

Instantly share code, notes, and snippets.

@schickling
Created May 15, 2025 07:34
Show Gist options
  • Save schickling/c158f80b10a2e06939ef896f95a5bbb8 to your computer and use it in GitHub Desktop.
Save schickling/c158f80b10a2e06939ef896f95a5bbb8 to your computer and use it in GitHub Desktop.
import { spawn } from 'node:child_process'
import process from 'node:process'
const run = (cmd: string, args: string[], forwardStdin = true) =>
spawn(cmd, args, {
shell: true,
stdio: [forwardStdin ? 'inherit' : 'ignore', 'inherit', 'inherit'],
})
const processes = [
// Forward stdin to allow Vite keyboard input
run('pnpm', ['run', 'dev:vite'], true),
run('pnpm', ['run', 'dev:wrangler'], false),
]
// Cleanly kill both on ^C or when either exits
const shutdown = () => {
for (const p of processes) {
p.kill('SIGINT')
}
}
process.on('SIGINT', shutdown).on('SIGTERM', shutdown)
for (const p of processes) {
p.on('exit', shutdown)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment