damn that shit was not necessary
This commit is contained in:
parent
6cbf15b783
commit
8d0d5f3ae0
1 changed files with 0 additions and 42 deletions
42
serve.ts
42
serve.ts
|
@ -1,42 +0,0 @@
|
||||||
|
|
||||||
let server: Deno.HttpServer | null = null;
|
|
||||||
async function runScript() {
|
|
||||||
if (server) {
|
|
||||||
await server.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
const { startServer } = await import((`./server.ts?cache_bust=${Date.now()}`));
|
|
||||||
server = startServer("localhost", 6969);
|
|
||||||
}
|
|
||||||
|
|
||||||
function debounced(fn: () => Promise<void>) {
|
|
||||||
let timeoutId: ReturnType<typeof setTimeout> | null;
|
|
||||||
return () => {
|
|
||||||
if (timeoutId) {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
|
|
||||||
timeoutId = setTimeout(fn, 200);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch for file changes
|
|
||||||
async function watchFiles(paths: string[], handler: () => void) {
|
|
||||||
const watcher = Deno.watchFs(paths);
|
|
||||||
for await (const event of watcher) {
|
|
||||||
if (event.kind === "modify" || event.kind === "create") {
|
|
||||||
handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startup() {
|
|
||||||
// Initial run
|
|
||||||
runScript();
|
|
||||||
await watchFiles(["."], debounced(runScript));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
await startup()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue