From 01ad78eb74bc9c31af2b0ddba92b0e72de2c5ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20=E2=80=9CAd=C3=A6dra=E2=80=9D=20Hamel?= Date: Thu, 27 Jun 2024 04:58:26 +0200 Subject: [PATCH] Own watcher --- bin/watch.ts | 19 +++++++++++++++++++ package-lock.json | 1 + package.json | 1 + tsconfig.json | 4 +++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 bin/watch.ts diff --git a/bin/watch.ts b/bin/watch.ts new file mode 100644 index 0000000..68a2d55 --- /dev/null +++ b/bin/watch.ts @@ -0,0 +1,19 @@ +import { Worker } from "node:worker_threads"; +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((resolve) => { + const worker = new Worker(new URL(import.meta.resolve("./build.ts")), { argv: [task] }); + worker.on("exit", () => resolve()); + }); + }); + +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"); diff --git a/package-lock.json b/package-lock.json index 01f191f..bddcf74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@mapbox/rehype-prism": "^0.9.0", "asciidoctor": "^3.0.4", + "chokidar": "^3.6.0", "cssnano": "^7.0.2", "glob": "^10.4.2", "gulp": "^5.0.0", diff --git a/package.json b/package.json index c781a95..fc68f6b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "@mapbox/rehype-prism": "^0.9.0", "asciidoctor": "^3.0.4", + "chokidar": "^3.6.0", "cssnano": "^7.0.2", "glob": "^10.4.2", "gulp": "^5.0.0", diff --git a/tsconfig.json b/tsconfig.json index 553e665..f5fb3ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,8 @@ "compilerOptions": { "esModuleInterop": true, "jsx": "react-jsx", - "jsxImportSource": "preact" + "jsxImportSource": "preact", + "module": "NodeNext", + "moduleResolution": "NodeNext" } }