Update watcher to rebuild on api dir change

This commit is contained in:
2026-04-05 06:09:22 +01:00
parent 5166ba037f
commit 333c84281d
3 changed files with 28 additions and 11 deletions
+14 -6
View File
@@ -1,4 +1,4 @@
import { watch, existsSync } from "fs";
import { watch, existsSync, statSync } from "fs";
import path from "path";
import grabDirNames from "../../utils/grab-dir-names";
import { log } from "../../utils/log";
@@ -22,6 +22,10 @@ export default async function watcherEsbuildCTX() {
}
const full_file_path = path.join(ROOT_DIR, filename);
const does_file_exist = existsSync(full_file_path);
const file_stat = does_file_exist
? statSync(full_file_path)
: undefined;
if (full_file_path.match(/\/styles$/)) {
global.RECOMPILING = true;
@@ -69,9 +73,9 @@ export default async function watcherEsbuildCTX() {
return;
}
const is_file_of_interest = Boolean(
filename.match(target_files_match),
);
const is_file_of_interest =
Boolean(filename.match(target_files_match)) ||
file_stat?.isDirectory();
if (!is_file_of_interest) {
return;
@@ -83,8 +87,12 @@ export default async function watcherEsbuildCTX() {
if (global.RECOMPILING) return;
const action = existsSync(full_file_path) ? "created" : "deleted";
const type = filename.match(/\.css$/) ? "Sylesheet" : "Page";
const action = does_file_exist ? "created" : "deleted";
const type = filename.match(/\.css$/)
? "Sylesheet"
: file_stat?.isDirectory()
? "Directory"
: "Page";
await fullRebuild({
msg: `${type} ${action}: ${filename}. Rebuilding ...`,