Thread viewer for Bluesky
1import { parseArgs } from 'util';
2import { runBuild } from './build.js';
3import { runTypecheck } from './typecheck.js';
4
5let { values: options } = parseArgs({
6 args: Bun.argv,
7 options: {
8 ts: {
9 type: 'boolean'
10 }
11 },
12 strict: true,
13 allowPositionals: true
14});
15
16async function rebuild() {
17 let start = Bun.nanoseconds();
18 let result = await runBuild(true);
19 let timeSpent = Math.floor((Bun.nanoseconds() - start) / 100_000) / 10;
20
21 let bundlePath = result.outputs.find(x => x.kind == 'entry-point').path;
22 console.log(`[${new Date().toUTCString()}] Built ${bundlePath} in ${timeSpent} ms`);
23
24 if (options.ts) {
25 setTimeout(() => {
26 let start2 = Bun.nanoseconds();
27 let result = runTypecheck();
28 let timeSpent = Math.floor((Bun.nanoseconds() - start) / 100_000) / 10;
29
30 console.log(`[${new Date().toUTCString()}] Type-checked TypeScript in ${timeSpent} ms`);
31
32 if (!result.ok) {
33 console.error("\n" + result.text);
34 }
35 }, 75);
36 }
37}
38
39rebuild().catch(err => {
40 console.log(err);
41});
42
43Bun.serve({
44 routes: {
45 '/': {
46 async GET(req) {
47 await rebuild();
48 return new Response(Bun.file("./index.html"));
49 }
50 }
51 },
52 async fetch(req) {
53 let url = new URL(req.url);
54 let file = Bun.file(`.${url.pathname}`);
55 return new Response(file);
56 }
57});