forked from SINTEF-9012/PruneCluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.ts
46 lines (37 loc) · 1.21 KB
/
dev.ts
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
import { Hono } from "hono";
import { serveStatic } from "hono/bun";
import { exec } from "child_process";
import chokidar from "chokidar";
const app = new Hono();
const PORT = 3000;
// Serve static files from the 'examples' directory
app.get('/*', serveStatic({ root: './' }));
// Track if a build is already running to avoid overlapping builds
let isBuilding = false;
// Watch for changes in the 'src' directory
chokidar.watch("src/**/*.{ts,js}", { ignoreInitial: false }).on("all", (event, file) => {
console.log(`File changed: ${file}`);
if (isBuilding) {
console.log(`Change detected in ${file}, but a build is already in progress.`);
return;
}
isBuilding = true;
console.log(`Starting build due to changes in ${file}...`);
exec("bun run build:example", (error, stdout, stderr) => {
isBuilding = false; // Reset build flag
if (error) {
console.error(`Build error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Build stderr: ${stderr}`);
return;
}
console.log(`Build succeeded:\n${stdout}`);
});
});
// Start the server
export default {
port: PORT,
fetch: app.fetch,
};