change to use jszip
This commit is contained in:
parent
ae00815f76
commit
73b03e28ba
|
|
@ -21,7 +21,9 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"brotli-wasm": "^2.0.1",
|
"brotli-wasm": "^2.0.1",
|
||||||
"exit-hook": "^4.0.0",
|
"exit-hook": "^4.0.0",
|
||||||
|
"file-type": "^21.1.1",
|
||||||
"firebase-admin": "^12.2.0",
|
"firebase-admin": "^12.2.0",
|
||||||
|
"jszip": "^3.10.1",
|
||||||
"prisma": "^5.17.0"
|
"prisma": "^5.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ import { startBrCompress } from "./br-load";
|
||||||
import { dir } from "./dir";
|
import { dir } from "./dir";
|
||||||
import { g } from "./global";
|
import { g } from "./global";
|
||||||
import { gunzipAsync } from "./gzip";
|
import { gunzipAsync } from "./gzip";
|
||||||
|
import { fileTypeFromBlob, fileTypeFromBuffer } from "file-type";
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
|
|
@ -109,12 +110,32 @@ export const deploy = {
|
||||||
await removeAsync(dir("public"));
|
await removeAsync(dir("public"));
|
||||||
}
|
}
|
||||||
if (g.deploy.content.public) {
|
if (g.deploy.content.public) {
|
||||||
console.log(`[DEBUG] Creating public directory and writing ${Object.keys(g.deploy.content.public).length} files`);
|
console.log(`[DEBUG] Extracting public directory from zip file`);
|
||||||
await dirAsync(dir("public"));
|
const zipPath = dir(`app/web/deploy/${ts}.zip`);
|
||||||
for (const [k, v] of Object.entries(g.deploy.content.public)) {
|
const publicDestPath = dir("public");
|
||||||
await writeAsync(dir(`public/${k}`), v);
|
|
||||||
|
await dirAsync(publicDestPath);
|
||||||
|
|
||||||
|
// Read the zip file
|
||||||
|
const JSZip = (await import("jszip")).default;
|
||||||
|
const zipData = await Bun.file(zipPath).arrayBuffer();
|
||||||
|
const zip = await JSZip.loadAsync(zipData);
|
||||||
|
|
||||||
|
// Extract only files in the public folder
|
||||||
|
const publicFiles = Object.keys(zip.files).filter(path => path.startsWith("public/"));
|
||||||
|
|
||||||
|
for (const filePath of publicFiles) {
|
||||||
|
const file = zip.files[filePath];
|
||||||
|
if (!file.dir) {
|
||||||
|
const content = await file.async("uint8array");
|
||||||
|
const destPath = dir(filePath);
|
||||||
|
await dirAsync(destPath.substring(0, destPath.lastIndexOf("/")));
|
||||||
|
await Bun.write(destPath, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`[DEBUG] Successfully extracted ${publicFiles.length} files from public folder`);
|
||||||
|
}
|
||||||
console.log(`[DEBUG] Public files setup completed`);
|
console.log(`[DEBUG] Public files setup completed`);
|
||||||
|
|
||||||
for (const page of g.deploy.content.layouts) {
|
for (const page of g.deploy.content.layouts) {
|
||||||
|
|
@ -343,8 +364,10 @@ export const deploy = {
|
||||||
|
|
||||||
if (isBinary) {
|
if (isBinary) {
|
||||||
g.deploy.content.public[relativePath] = fileContent;
|
g.deploy.content.public[relativePath] = fileContent;
|
||||||
|
console.log(`[DEBUG] ✓ Loaded binary file for public/${relativePath}`);
|
||||||
} else {
|
} else {
|
||||||
g.deploy.content.public[relativePath] = new TextDecoder().decode(fileContent);
|
g.deploy.content.public[relativePath] = new TextDecoder().decode(fileContent);
|
||||||
|
console.log(`[DEBUG] ✓ Loaded text file for public/${relativePath}`);
|
||||||
}
|
}
|
||||||
} else if (entry.filename.startsWith('server/')) {
|
} else if (entry.filename.startsWith('server/')) {
|
||||||
const relativePath = entry.filename.slice(7); // Remove 'server/' prefix
|
const relativePath = entry.filename.slice(7); // Remove 'server/' prefix
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue