CODE · 1.3 KB
scripts/rebuild-real-e2e.mjs
Workspace snapshot · 08/31 23:51
import { readFile, mkdir, writeFile } from "node:fs/promises";
import JSZip from "jszip";
import { buildExportBundle } from "../src/export-bundle.js";
const output = new URL("../output/real-e2e/", import.meta.url);
const design = JSON.parse(await readFile(new URL("design.json", output), "utf8"));
const summary = JSON.parse(await readFile(new URL("e2e-summary.json", output), "utf8"));
const images = [];
for (const sectionId of summary.imageSections || []) {
const bytes = await readFile(new URL(`images/${sectionId}.png`, output));
images.push({ sectionId, textIntegrated: true, src: `data:image/png;base64,${bytes.toString("base64")}` });
}
const bundle = await buildExportBundle({
project: design.project,
sections: design.sections,
tone: design.tone,
images,
publicUrl: design.project?.answers?.canonicalUrl || "",
});
const bytes = Buffer.from(await bundle.arrayBuffer());
await writeFile(new URL("landing-page-package.zip", output), bytes);
const zip = await JSZip.loadAsync(bytes);
for (const [name, entry] of Object.entries(zip.files)) {
if (entry.dir) continue;
const file = new URL(name, output);
await mkdir(new URL("./", file), { recursive: true });
await writeFile(file, Buffer.from(await entry.async("uint8array")));
}
console.log(`rebuilt ${design.sections.length} sections with ${images.length} packaged visuals`);