This commit is contained in:
Rizky 2024-08-04 14:53:27 +07:00
parent c696a87cd0
commit 2e168805e0
3 changed files with 55 additions and 1 deletions

BIN
bun.lockb

Binary file not shown.

53
pkgs/api/_zip.ts Normal file
View File

@ -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`));
},
};

View File

@ -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() {