@jsnchn/buntastic 0.0.8 → 0.0.9
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 +29 -40
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, writeFile, readFile, copyFile, exists } from "fs/promises";
|
|
2
|
-
import { watch as fsWatch } from "fs
|
|
2
|
+
import { watch as fsWatch } from "node:fs";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
3
4
|
import { join, relative, dirname, extname } from "path";
|
|
4
5
|
import { Glob } from "bun";
|
|
5
6
|
|
|
@@ -294,48 +295,36 @@ async function dev(): Promise<void> {
|
|
|
294
295
|
|
|
295
296
|
await build(false);
|
|
296
297
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const watcher3 = fsWatch(PUBLIC_DIR, { recursive: true });
|
|
298
|
+
let buildRunning = false;
|
|
299
|
+
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
function runBuild() {
|
|
302
|
+
if (buildRunning) return;
|
|
303
|
+
buildRunning = true;
|
|
304
|
+
console.log("Rebuilding...");
|
|
305
|
+
const proc = spawn("bun", ["run", "build"], {
|
|
306
|
+
stdio: "inherit",
|
|
307
|
+
env: { ...process.env, NODE_ENV: "development" },
|
|
308
|
+
});
|
|
309
|
+
proc.on("exit", () => {
|
|
310
|
+
buildRunning = false;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
302
313
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
debounceTimer = setTimeout(async () => {
|
|
308
|
-
if (isBuilding) return;
|
|
309
|
-
isBuilding = true;
|
|
310
|
-
console.log("Rebuilding...");
|
|
311
|
-
try {
|
|
312
|
-
await build(false);
|
|
313
|
-
} finally {
|
|
314
|
-
isBuilding = false;
|
|
315
|
-
}
|
|
316
|
-
}, 100);
|
|
317
|
-
};
|
|
314
|
+
function scheduleBuild() {
|
|
315
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
316
|
+
debounceTimer = setTimeout(runBuild, 100);
|
|
317
|
+
}
|
|
318
318
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (ext !== "css" && ext !== "js" && ext !== "ts") {
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
console.log(`[${event.eventType}] ${event.filename} - rebuilding...`);
|
|
334
|
-
rebuild();
|
|
335
|
-
}
|
|
336
|
-
})();
|
|
337
|
-
}
|
|
338
|
-
})();
|
|
319
|
+
const watchDirs = [CONTENT_DIR, LAYOUTS_DIR, PUBLIC_DIR];
|
|
320
|
+
for (const dir of watchDirs) {
|
|
321
|
+
fsWatch(dir, { recursive: true }, (eventType, filename) => {
|
|
322
|
+
if (!filename) return;
|
|
323
|
+
if (filename.endsWith("~") || filename.startsWith(".")) return;
|
|
324
|
+
console.log(`[${eventType}] ${filename} - rebuilding...`);
|
|
325
|
+
scheduleBuild();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
339
328
|
}
|
|
340
329
|
|
|
341
330
|
async function preview(): Promise<void> {
|