This commit is contained in:
Rizky 2024-09-02 16:24:31 +07:00
parent 466fb90533
commit fae641a2b3
3 changed files with 21 additions and 14 deletions

View File

@ -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.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);

View File

@ -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",

View File

@ -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`;