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