From 2e168805e06cfa4b474730a1d932e2281ed13f4b Mon Sep 17 00:00:00 2001 From: Rizky Date: Sun, 4 Aug 2024 14:53:27 +0700 Subject: [PATCH] fix --- bun.lockb | Bin 121581 -> 121581 bytes pkgs/api/_zip.ts | 53 +++++++++++++++++++++++++++++++++++++++++++ pkgs/utils/deploy.ts | 3 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pkgs/api/_zip.ts diff --git a/bun.lockb b/bun.lockb index c394241bde4b2c5929af92be342ebea933a529a3..42669eb8c88fc61fec8f3838749b8903f83ca61f 100755 GIT binary patch delta 39 vcmaF6mHq8j_J%EtFH<-e;|%o-4fPDRe@tQI6=I7s)w9$y+|E+Y_%ay)DYOk` delta 39 qcmaF6mHq8j_J%EtFH<;}7$9K##}r0hAvRMzLvuZY?JVVtFOvZT(+jx( diff --git a/pkgs/api/_zip.ts b/pkgs/api/_zip.ts new file mode 100644 index 0000000..0917658 --- /dev/null +++ b/pkgs/api/_zip.ts @@ -0,0 +1,53 @@ +import { $ } from "bun"; +import { removeAsync } from "fs-jetpack"; +import { dir } from "utils/dir"; +import { g } from "utils/global"; + +export const _ = { + url: "/_zip", + raw: true, + async api() { + await removeAsync(dir(`${g.datadir}/bundle`)); + + for (const [directory, files] of Object.entries(g.deploy.content || {})) { + if (directory !== "code" && directory !== "site") { + for (const comp of Object.values(files) as any) { + let filepath = `${g.datadir}/bundle/${directory}/${comp.id}.json`; + await Bun.write(filepath, JSON.stringify(comp), { + createPath: true, + }); + } + } else if (directory === "site") { + await Bun.write( + `${g.datadir}/bundle/${directory}.json`, + JSON.stringify(files), + { + createPath: true, + } + ); + } else { + for (const [filename, content] of Object.entries(files)) { + let filepath = `${g.datadir}/bundle/${directory}/${filename}`; + + if (content instanceof Buffer || typeof content === "string") { + await Bun.write(filepath, content, { createPath: true }); + } else { + for (const [k, v] of Object.entries(content || {})) { + filepath = `${g.datadir}/bundle/${directory}/${filename}/${k}`; + if (v instanceof Buffer || typeof v === "string") { + await Bun.write(filepath, v, { createPath: true }); + } else { + await Bun.write(filepath, JSON.stringify(v), { + createPath: true, + }); + } + } + } + } + } + } + + await $`zip -r bundle.zip .`.quiet().cwd(`${g.datadir}/bundle`); + return new Response(Bun.file(`${g.datadir}/bundle/bundle.zip`)); + }, +}; diff --git a/pkgs/utils/deploy.ts b/pkgs/utils/deploy.ts index 339e0ed..5bc20bd 100644 --- a/pkgs/utils/deploy.ts +++ b/pkgs/utils/deploy.ts @@ -127,7 +127,8 @@ export const deploy = { } } catch (e) { console.log("Failed to load site", this.config.site_id); - console.error(e); + if (e instanceof Error) + console.error(e.message, `[app/web/deploy/${ts}.gz]`); } }, async run() {