blog/bin/watch.ts

26 lines
855 B
TypeScript
Raw Permalink Normal View History

2024-06-27 02:58:26 +00:00
import chokidar from "chokidar";
2024-06-27 08:58:54 +00:00
import { debug, info } from "../lib/log.ts";
2024-06-27 02:58:26 +00:00
const watch = (glob: string | string[], task: string) =>
chokidar.watch(glob).on("change", (path: string) => {
2024-06-27 08:58:54 +00:00
debug("File changed", { path, task });
2024-06-27 02:58:26 +00:00
return new Promise<void>((resolve) => {
2024-06-27 04:22:58 +00:00
const worker = new Worker(import.meta.resolve("../lib/watch-worker.ts"), { type: "module" });
worker.addEventListener("message", () => {
worker.terminate();
resolve();
});
worker.postMessage({ task });
2024-06-27 02:58:26 +00:00
});
});
watch(["lib/views/*.tsx", "articles/**/*.asciidoc"], "articles");
watch("src/*.css", "css");
watch("src/*.avif", "images");
watch("src/*.svg", "svg");
watch("dist/_assets/fonts.manifest", "css");
watch("dist/_assets/css.manifest", "articles");
2024-06-27 08:58:54 +00:00
info("Started");