@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.
- package/package.json +1 -1
- package/src/index.ts +26 -5
package/package.json
CHANGED
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
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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> {
|