fix esbuild
This commit is contained in:
parent
ec36cdab7b
commit
15147d9160
|
|
@ -116,7 +116,7 @@ export const _ = {
|
||||||
const root = `/code/${site_id}/site/src`;
|
const root = `/code/${site_id}/site/src`;
|
||||||
await ensureLib(root, site_id);
|
await ensureLib(root, site_id);
|
||||||
await ensureFiles(root, site_id);
|
await ensureFiles(root, site_id);
|
||||||
await initFrontEnd(root, site_id, true);
|
await initFrontEnd(root, site_id);
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
const ival = setInterval(async () => {
|
const ival = setInterval(async () => {
|
||||||
file = Bun.file(build_path);
|
file = Bun.file(build_path);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import { conns } from "../../../entity/conn";
|
||||||
import { SyncType } from "../../../type";
|
import { SyncType } from "../../../type";
|
||||||
import { sendWS } from "../../../sync-handler";
|
import { sendWS } from "../../../sync-handler";
|
||||||
import { removeAsync } from "fs-jetpack";
|
import { removeAsync } from "fs-jetpack";
|
||||||
|
import { watch } from "fs";
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
export const initFrontEnd = async (
|
export const initFrontEnd = async (
|
||||||
root: string,
|
root: string,
|
||||||
|
|
@ -23,6 +23,7 @@ export const initFrontEnd = async (
|
||||||
if (existing) {
|
if (existing) {
|
||||||
if (force) {
|
if (force) {
|
||||||
try {
|
try {
|
||||||
|
existing.watch.close();
|
||||||
await existing.ctx.dispose();
|
await existing.ctx.dispose();
|
||||||
delete code.internal.frontend[id_site];
|
delete code.internal.frontend[id_site];
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
@ -103,8 +104,27 @@ export const initFrontEnd = async (
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
code.internal.frontend[id_site] = { ctx: build_ctx, timeout: null };
|
code.internal.frontend[id_site] = {
|
||||||
await build_ctx.watch();
|
ctx: build_ctx,
|
||||||
|
timeout: null,
|
||||||
|
rebuilding: false,
|
||||||
|
watch: watch(dir.data(root), async (event, filename) => {
|
||||||
|
const ctx = code.internal.frontend[id_site];
|
||||||
|
if (
|
||||||
|
ctx &&
|
||||||
|
(filename?.endsWith(".tsx") ||
|
||||||
|
filename?.endsWith(".ts") ||
|
||||||
|
filename?.endsWith(".css") ||
|
||||||
|
filename?.endsWith(".html"))
|
||||||
|
) {
|
||||||
|
if (!ctx.rebuilding) {
|
||||||
|
ctx.rebuilding = true;
|
||||||
|
await ctx.ctx.rebuild();
|
||||||
|
ctx.rebuilding = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("Error building front end", id_site);
|
console.error("Error building front end", id_site);
|
||||||
delete code.internal.frontend[id_site];
|
delete code.internal.frontend[id_site];
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export const codeInternal = {
|
||||||
if (!g.prasi_code.frontend) g.prasi_code.frontend = {};
|
if (!g.prasi_code.frontend) g.prasi_code.frontend = {};
|
||||||
return g.prasi_code.frontend as Record<
|
return g.prasi_code.frontend as Record<
|
||||||
SITE_ID,
|
SITE_ID,
|
||||||
{ ctx: BuildContext; timeout: any }
|
{ ctx: BuildContext; timeout: any, watch: FSWatcher, rebuilding: boolean }
|
||||||
>;
|
>;
|
||||||
},
|
},
|
||||||
get typings() {
|
get typings() {
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ export const pushTreeNode = (
|
||||||
?.forEach((v, k) => {
|
?.forEach((v, k) => {
|
||||||
if (typeof v === "object") {
|
if (typeof v === "object") {
|
||||||
if ((v as any)?.get("meta")?.get("type") === "content-element") {
|
if ((v as any)?.get("meta")?.get("type") === "content-element") {
|
||||||
const mitem = (v as any).get("content") as MItem;
|
const mitem = (v as any)?.get("content") as MItem;
|
||||||
if (meta.item.id === mitem.get("id")) {
|
if (mitem && meta.item.id === mitem.get("id")) {
|
||||||
meta.mitem = mitem;
|
meta.mitem = mitem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue