From fae641a2b3e8931c175cfcf22f61402a84d0892c Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 2 Sep 2024 16:24:31 +0700 Subject: [PATCH] fix --- pkgs/core/server/serve-static.ts | 31 +++++++++++++++++++------------ pkgs/core/utils/parcel.ts | 2 +- pkgs/core/utils/prisma.ts | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pkgs/core/server/serve-static.ts b/pkgs/core/server/serve-static.ts index 6dd73b39..32108658 100644 --- a/pkgs/core/server/serve-static.ts +++ b/pkgs/core/server/serve-static.ts @@ -26,24 +26,31 @@ export const serveStatic = { delete cache.static[k]; } - ["app/static", "app/web/public"].forEach((base_path) => { - watch(dir.data(`static`), async (event, filename) => { - if (filename) { - cache.dev = {}; - } - }); + watch(dir.data(`static`), async (event, filename) => { + if (filename) { + cache.dev = {}; + } + }); + + watch(dir.path("app/web/public"), async (event, filename) => { + if (filename) { + cache.dev = {}; + } }); } else { - await Promise.all([this.load("app/static"), this.load("app/web/public")]); + await Promise.all([ + this.load(dir.data("static")), + this.load(dir.path("app/web/public")), + ]); } }, async load(base_path: string) { try { const glob = new Bun.Glob("**"); - for await (const file_path of glob.scan(dir.path(base_path))) { - const r_path = dir.path(`${base_path}/${file_path}`); - const br_path = dir.path(`${base_path}-br/${file_path}`); + for await (const file_path of glob.scan(base_path)) { + const r_path = `${base_path}/${file_path}`; + const br_path = `${base_path}-br/${file_path}`; let final_path = r_path; let br = false; @@ -140,7 +147,7 @@ navigator.serviceWorker.getRegistration().then(function(reg) { return new Response(cache.dev[url.pathname]); } - let file = Bun.file(dir.path(`/app/static${url.pathname}`)); + let file = Bun.file(dir.data(`static${url.pathname}`)); if (await file.exists()) { cache.dev[url.pathname] = file; return new Response(file); @@ -150,7 +157,7 @@ navigator.serviceWorker.getRegistration().then(function(reg) { cache.dev[url.pathname] = file; return new Response(file); } - file = Bun.file(dir.path(`/app/static/index.html`)); + file = Bun.file(dir.data(`static/index.html`)); if (await file.exists()) { cache.dev[`/index.html`] = file; return new Response(file); diff --git a/pkgs/core/utils/parcel.ts b/pkgs/core/utils/parcel.ts index 04040d14..52b795a0 100644 --- a/pkgs/core/utils/parcel.ts +++ b/pkgs/core/utils/parcel.ts @@ -6,7 +6,7 @@ import { platform } from "os"; const decoder = new TextDecoder(); export const parcelBuild = async () => { - await dirAsync("app/static"); + await dirAsync(dir.data("static")); const args = [ "node", diff --git a/pkgs/core/utils/prisma.ts b/pkgs/core/utils/prisma.ts index bc74a97d..54ca1edc 100644 --- a/pkgs/core/utils/prisma.ts +++ b/pkgs/core/utils/prisma.ts @@ -8,7 +8,7 @@ export const preparePrisma = async () => { (await existsAsync(dir.path("app/db/.env"))) || process.env.DATABASE_URL ) { - if (g.mode === "prod" && exists(dir.path("app/static-br"))) { + if (g.mode === "prod" && exists(dir.data("static-br"))) { g.log.info("Prisma: db pull & generate"); await $({ cwd: dir.path(`app/db`) })`bun prisma db pull`; await $({ cwd: dir.path(`app/db`) })`bun prisma generate`;