blog/bin/watch.ts

23 lines
796 B
TypeScript

import chokidar from "chokidar";
const watch = (glob: string | string[], task: string) =>
chokidar.watch(glob).on("change", (path: string) => {
console.log("[change]", path, "->", task);
return new Promise<void>((resolve) => {
const worker = new Worker(import.meta.resolve("../lib/watch-worker.ts"), { type: "module" });
worker.addEventListener("message", () => {
worker.terminate();
resolve();
});
worker.postMessage({ task });
});
});
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");