mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: use bun to execute server and analytics
This commit is contained in:
1 parent
2feedc329c
commit
77577d9b8d
13 files changed
+128
-120
No files matched your search
@@ -0,0 +1,27 @@
|
||||
// Dev server with auto-restart. `bun --watch` only tracks imported modules,
|
||||
// but quests are read from YAML at startup, so rewrite the entry file (same
|
||||
// contents) whenever a quest file changes to trigger a restart. Bun ignores
|
||||
// timestamp-only changes, so `touch` would not work.
|
||||
import { watch, readFileSync, writeFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const entry = path.join(import.meta.dir, '../src/index.ts')
|
||||
const questsDir = path.join(import.meta.dir, '../../quests')
|
||||
|
||||
const server = Bun.spawn(['bun', '--watch', entry], {
|
||||
stdio: ['inherit', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
watch(questsDir, { recursive: true }, (_event, filename) => {
|
||||
if (!filename?.endsWith('.yml')) return
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => {
|
||||
writeFileSync(entry, readFileSync(entry))
|
||||
}, 100)
|
||||
})
|
||||
|
||||
const stop = () => server.kill()
|
||||
process.on('SIGINT', stop)
|
||||
process.on('SIGTERM', stop)
|
||||
process.exit(await server.exited)
|
||||
Reference in new issue
Block a user