snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
51
examples/lit/ssr/scripts/dev.mjs
Normal file
51
examples/lit/ssr/scripts/dev.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import { spawn, spawnSync } from 'node:child_process'
|
||||
import { once } from 'node:events'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
||||
const tsxCommand = process.platform === 'win32' ? 'tsx.cmd' : 'tsx'
|
||||
const cwd = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
|
||||
function runBuild() {
|
||||
const result = spawnSync(npmCommand, ['run', 'build'], {
|
||||
cwd,
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
||||
if (result.status !== 0) {
|
||||
process.exit(result.status ?? 1)
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
runBuild()
|
||||
|
||||
const server = spawn(tsxCommand, ['./server/index.mjs'], {
|
||||
cwd,
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
||||
const stopServer = (signal) => {
|
||||
if (server.exitCode === null) {
|
||||
server.kill(signal)
|
||||
}
|
||||
}
|
||||
|
||||
process.on('SIGINT', () => stopServer('SIGINT'))
|
||||
process.on('SIGTERM', () => stopServer('SIGTERM'))
|
||||
|
||||
const outcome = await Promise.race([
|
||||
once(server, 'error').then(([error]) => {
|
||||
throw error
|
||||
}),
|
||||
once(server, 'exit').then(([code]) => ({ code })),
|
||||
])
|
||||
|
||||
process.exitCode = outcome.code ?? 0
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in New Issue
Block a user