@jsnchn/buntastic 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +26 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsnchn/buntastic",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "A simple static site generator built with Bun",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { mkdir, writeFile, readFile, copyFile, exists } from "fs/promises";
2
+ import { watch as fsWatch } from "fs/promises";
2
3
  import { join, relative, dirname, extname } from "path";
3
4
  import { Glob } from "bun";
4
5
 
@@ -291,11 +292,31 @@ async function dev(): Promise<void> {
291
292
 
292
293
  console.log(`Dev server running at http://localhost:${server.port}`);
293
294
 
294
- const watcher = Bun.watch([CONTENT_DIR, LAYOUTS_DIR, PUBLIC_DIR]);
295
- for await (const event of watcher) {
296
- console.log(`[${event.kind}] ${event.path} - rebuilding...`);
297
- await build(false);
298
- }
295
+ const watcher1 = fsWatch(CONTENT_DIR, { recursive: true });
296
+ const watcher2 = fsWatch(LAYOUTS_DIR, { recursive: true });
297
+ const watcher3 = fsWatch(PUBLIC_DIR, { recursive: true });
298
+
299
+ const watchers = [watcher1, watcher2, watcher3];
300
+
301
+ let debounceTimer: ReturnType<typeof setTimeout> | undefined;
302
+ const rebuild = () => {
303
+ clearTimeout(debounceTimer);
304
+ debounceTimer = setTimeout(async () => {
305
+ console.log("Rebuilding...");
306
+ await build(false);
307
+ }, 100);
308
+ };
309
+
310
+ (async () => {
311
+ for (const watcher of watchers) {
312
+ (async () => {
313
+ for await (const event of watcher) {
314
+ console.log(`[${event.eventType}] ${event.filename} - rebuilding...`);
315
+ rebuild();
316
+ }
317
+ })();
318
+ }
319
+ })();
299
320
  }
300
321
 
301
322
  async function preview(): Promise<void> {