mirror of
https://git.sfja.dk/sfja/h6-logicirc.git
synced 2025-05-15 16:58:08 +01:00
add dev.ts
This commit is contained in:
parent
e17953ae4a
commit
0db1c3b90a
36
deno.lock
36
deno.lock
@ -3,8 +3,15 @@
|
||||
"specifiers": {
|
||||
"jsr:@luca/esbuild-deno-loader@0.11": "0.11.1",
|
||||
"jsr:@std/bytes@^1.0.2": "1.0.4",
|
||||
"jsr:@std/cli@^1.0.6": "1.0.6",
|
||||
"jsr:@std/encoding@^1.0.5": "1.0.5",
|
||||
"jsr:@std/fmt@^1.0.3": "1.0.7",
|
||||
"jsr:@std/http@*": "1.0.10",
|
||||
"jsr:@std/media-types@^1.1.0": "1.1.0",
|
||||
"jsr:@std/net@^1.0.4": "1.0.4",
|
||||
"jsr:@std/path@^1.0.6": "1.0.8",
|
||||
"jsr:@std/path@^1.0.8": "1.0.8",
|
||||
"jsr:@std/streams@^1.0.8": "1.0.9",
|
||||
"npm:esbuild@0.20.2": "0.20.2"
|
||||
},
|
||||
"jsr": {
|
||||
@ -13,17 +20,44 @@
|
||||
"dependencies": [
|
||||
"jsr:@std/bytes",
|
||||
"jsr:@std/encoding",
|
||||
"jsr:@std/path"
|
||||
"jsr:@std/path@^1.0.6"
|
||||
]
|
||||
},
|
||||
"@std/bytes@1.0.4": {
|
||||
"integrity": "11a0debe522707c95c7b7ef89b478c13fb1583a7cfb9a85674cd2cc2e3a28abc"
|
||||
},
|
||||
"@std/cli@1.0.6": {
|
||||
"integrity": "d22d8b38c66c666d7ad1f2a66c5b122da1704f985d3c47f01129f05abb6c5d3d"
|
||||
},
|
||||
"@std/encoding@1.0.5": {
|
||||
"integrity": "ecf363d4fc25bd85bd915ff6733a7e79b67e0e7806334af15f4645c569fefc04"
|
||||
},
|
||||
"@std/fmt@1.0.7": {
|
||||
"integrity": "2a727c043d8df62cd0b819b3fb709b64dd622e42c3b1bb817ea7e6cc606360fb"
|
||||
},
|
||||
"@std/http@1.0.10": {
|
||||
"integrity": "4e32d11493ab04e3ef09f104f0cb9beb4228b1d4b47c5469573c2c294c0d3692",
|
||||
"dependencies": [
|
||||
"jsr:@std/cli",
|
||||
"jsr:@std/encoding",
|
||||
"jsr:@std/fmt",
|
||||
"jsr:@std/media-types",
|
||||
"jsr:@std/net",
|
||||
"jsr:@std/path@^1.0.8",
|
||||
"jsr:@std/streams"
|
||||
]
|
||||
},
|
||||
"@std/media-types@1.1.0": {
|
||||
"integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4"
|
||||
},
|
||||
"@std/net@1.0.4": {
|
||||
"integrity": "2f403b455ebbccf83d8a027d29c5a9e3a2452fea39bb2da7f2c04af09c8bc852"
|
||||
},
|
||||
"@std/path@1.0.8": {
|
||||
"integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be"
|
||||
},
|
||||
"@std/streams@1.0.9": {
|
||||
"integrity": "a9d26b1988cdd7aa7b1f4b51e1c36c1557f3f252880fa6cc5b9f37078b1a5035"
|
||||
}
|
||||
},
|
||||
"npm": {
|
||||
|
66
dev.ts
Normal file
66
dev.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { serveDir } from "jsr:@std/http/file-server";
|
||||
import { bundle } from "./bundle.ts";
|
||||
|
||||
function listening(addr: Addr) {
|
||||
console.log(`Listening on http://${addr.hostname}:${addr.port}/`);
|
||||
}
|
||||
|
||||
type Addr = {
|
||||
hostname: string;
|
||||
port: number;
|
||||
};
|
||||
|
||||
async function check() {
|
||||
const command = new Deno.Command("deno", {
|
||||
args: ["check", "src"],
|
||||
stdout: "piped",
|
||||
});
|
||||
const process = command.spawn();
|
||||
const output = await process.output();
|
||||
await Deno.stdout.write(output.stdout);
|
||||
}
|
||||
|
||||
async function watchAndBundle(addr: Addr) {
|
||||
let changeOccurred = true;
|
||||
let running = false;
|
||||
setInterval(async () => {
|
||||
if (!changeOccurred || running) {
|
||||
return;
|
||||
}
|
||||
running = true;
|
||||
console.clear();
|
||||
await bundle().catch((err) => console.error(`bundle: ${err}`));
|
||||
await check();
|
||||
listening(addr);
|
||||
changeOccurred = false;
|
||||
running = false;
|
||||
}, 250);
|
||||
const watcher = Deno.watchFs(["src", "static"]);
|
||||
for await (const _ of watcher) {
|
||||
changeOccurred = true;
|
||||
}
|
||||
}
|
||||
|
||||
function serveBuild(addr: Addr) {
|
||||
Deno.serve({
|
||||
port: addr.port,
|
||||
hostname: addr.hostname,
|
||||
onListen: (_) => listening(addr),
|
||||
}, (req: Request) => {
|
||||
return serveDir(req, {
|
||||
fsRoot: "build",
|
||||
urlRoot: "",
|
||||
quiet: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const addr = {
|
||||
hostname: "0.0.0.0",
|
||||
port: 8432,
|
||||
};
|
||||
await bundle();
|
||||
watchAndBundle(addr);
|
||||
serveBuild(addr);
|
||||
}
|
Loading…
Reference in New Issue
Block a user