This commit is contained in:
Rizky 2024-08-16 10:54:15 +07:00
parent 30ccaac624
commit cac2e1ea1e
1 changed files with 48 additions and 46 deletions

View File

@ -75,56 +75,58 @@ export const initFrontEnd = async (
rebuilding: false, rebuilding: false,
}; };
if (!code.internal.frontend[id_site].watch) { if (code.internal.frontend[id_site].watch) {
console.log('watching', dir.data(root)) code.internal.frontend[id_site].watch.close();
code.internal.frontend[id_site].watch = watch( }
dir.data(root), console.log("watching", dir.data(root));
{ code.internal.frontend[id_site].watch = watch(
recursive: true, dir.data(root),
}, {
async (event, filename) => { recursive: true,
const fe = code.internal.frontend[id_site]; persistent: true
const srv = code.internal.server[id_site]; },
async (event, filename) => {
const fe = code.internal.frontend[id_site];
const srv = code.internal.server[id_site];
if ( if (
filename?.startsWith("node_modules") || filename?.startsWith("node_modules") ||
filename?.startsWith("typings") || filename?.startsWith("typings") ||
filename?.endsWith(".log") filename?.endsWith(".log")
) )
return; return;
console.log( console.log(
event, event,
filename, filename,
typeof fe !== "undefined" && !fe.rebuilding typeof fe !== "undefined" && !fe.rebuilding
? "start-rebuild" ? "start-rebuild"
: "rebuilding..." : "rebuilding..."
); );
if ( if (
filename?.endsWith(".tsx") || filename?.endsWith(".tsx") ||
filename?.endsWith(".ts") || filename?.endsWith(".ts") ||
filename?.endsWith(".css") || filename?.endsWith(".css") ||
filename?.endsWith(".html") filename?.endsWith(".html")
) { ) {
if (typeof fe !== "undefined" && !fe.rebuilding) { if (typeof fe !== "undefined" && !fe.rebuilding) {
fe.rebuilding = true; fe.rebuilding = true;
clearTimeout(fe.timeout); clearTimeout(fe.timeout);
fe.timeout = setTimeout(async () => { fe.timeout = setTimeout(async () => {
try { try {
broadcastLoading(); broadcastLoading();
await fe.ctx.rebuild(); await fe.ctx.rebuild();
fe.rebuilding = false; fe.rebuilding = false;
} catch (e: any) { } catch (e: any) {
console.error(`Frontend failed rebuild (site: ${id_site})`); console.error(`Frontend failed rebuild (site: ${id_site})`);
console.error(e.message); console.error(e.message);
fe.rebuilding = false; fe.rebuilding = false;
} }
}, 500); }, 500);
}
} }
} }
); }
} );
const fe = code.internal.frontend[id_site]; const fe = code.internal.frontend[id_site];
fe.rebuilding = true; fe.rebuilding = true;
try { try {