diff --git a/bun.lockb b/bun.lockb index c394241..42669eb 100755 Binary files a/bun.lockb and b/bun.lockb differ 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() {