From cb544118d934b390566779de8d56554adb4247a9 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 2 Sep 2024 16:12:42 +0700 Subject: [PATCH] fix --- pkgs/core/build.ts | 26 +++++++++++++++++--------- pkgs/core/server/serve-static.ts | 2 +- pkgs/core/utils/parcel.ts | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkgs/core/build.ts b/pkgs/core/build.ts index 467ebba0..c94fee9d 100644 --- a/pkgs/core/build.ts +++ b/pkgs/core/build.ts @@ -8,6 +8,7 @@ import { fdir } from "fdir"; import { statSync } from "fs"; import { listAsync, removeAsync, writeAsync } from "fs-jetpack"; import { platform } from "os"; +import { $ } from "bun"; const brotli = await brotliPromise; @@ -87,7 +88,7 @@ const build_all = process.argv[process.argv.length - 1] === "main" ? false : true; if (build_all) { await removeAsync(dir.path("app/web/.parcel-cache")); - await removeAsync(dir.path("app/static")); + await removeAsync(dir.data("static-temp")); await writeAsync( dir.path("app/web/timestamp.ts"), @@ -106,7 +107,7 @@ if (build_all) { // "--no-optimize", "--no-scope-hoist", "--dist-dir", - dir.path(`app/static`), + dir.data(`static`), ]; let build_static = @@ -116,7 +117,7 @@ if (build_all) { const public_br = dir.path("app/web/public-br"); await removeAsync(public_br); } - + const api = new fdir().withRelativePaths().crawl(dir.path("app/web/public")); const public_files = api.sync(); if (public_files) { @@ -155,25 +156,27 @@ if (build_all) { }); await parcel.exited; - const static_br = dir.path("app/static-br"); + const static_br = dir.data("static-br-temp"); await removeAsync(static_br); - const static_files = await listAsync(dir.path("app/static")); + const static_files = await listAsync(dir.data("static-temp")); if (static_files) { await Promise.all( static_files - .filter((file) => statSync(dir.path(`app/static/${file}`)).isFile()) + .filter((file) => statSync(dir.data(`static-temp/${file}`)).isFile()) .map(async (file) => { - if (!(await Bun.file(dir.path(`app/static-br/${file}`)).exists())) { + if ( + !(await Bun.file(dir.data(`static-br-temp/${file}`)).exists()) + ) { const br = brotli.compress( new Uint8Array( - await Bun.file(dir.path(`app/static/${file}`)).arrayBuffer() + await Bun.file(dir.data(`static-temp/${file}`)).arrayBuffer() ), { quality: 11 } ); if (br) { console.log(`Compressing [static] ${file}`); await writeAsync( - dir.path(`app/static-br/${file}`), + dir.data(`static-br-temp/${file}`), Buffer.from(br) ); } @@ -181,5 +184,10 @@ if (build_all) { }) ); } + + $`rm -rf ${dir.data(`static-br`)}`.nothrow(); + $`rm -rf ${dir.data(`static`)}`.nothrow(); + $`mv ${dir.data(`static-br-temp`)} ${dir.data(`static-br`)}`.nothrow(); + $`mv ${dir.data(`static-temp`)} ${dir.data(`static`)}`.nothrow(); } } diff --git a/pkgs/core/server/serve-static.ts b/pkgs/core/server/serve-static.ts index a92d8907..6dd73b39 100644 --- a/pkgs/core/server/serve-static.ts +++ b/pkgs/core/server/serve-static.ts @@ -27,7 +27,7 @@ export const serveStatic = { } ["app/static", "app/web/public"].forEach((base_path) => { - watch(dir.path(`app/static`), async (event, filename) => { + watch(dir.data(`static`), async (event, filename) => { if (filename) { cache.dev = {}; } diff --git a/pkgs/core/utils/parcel.ts b/pkgs/core/utils/parcel.ts index d0e8dd2f..04040d14 100644 --- a/pkgs/core/utils/parcel.ts +++ b/pkgs/core/utils/parcel.ts @@ -19,7 +19,7 @@ export const parcelBuild = async () => { "./src/index.html", g.mode === "dev" ? "--no-hmr" : "", "--dist-dir", - dir.path(`app/static`), + dir.data(`static`), ]; if (g.mode === "dev") {