Files
landing-builder/lib/exporter/zip.ts
T

25 lines
674 B
TypeScript

import JSZip from 'jszip'
export type BuildZipInput = {
html: string
css: string
js: string
assets?: Record<string, Uint8Array>
}
export async function buildZip(input: BuildZipInput): Promise<Uint8Array> {
const zip = new JSZip()
zip.file('index.html', input.html)
zip.file('styles.css', input.css)
zip.file('app.js', input.js)
if (input.assets) {
for (const [path, bytes] of Object.entries(input.assets)) {
// In Node/Vitest, use Buffer for robust binary handling
const buf = Buffer.from(bytes)
zip.file(path, buf as unknown as Buffer)
}
}
const content = await zip.generateAsync({ type: 'uint8array' })
return content
}