Stage 6: export book as combined Markdown or ZIP bundle (title page, book.md, chapters/, manifest) with File menu + toolbar entries and export tests

This commit is contained in:
avi 2026-08-17 09:22:41 -05:00
commit 5dcdec86b9
9 changed files with 768 additions and 1 deletions

View file

@ -119,6 +119,41 @@ ok(JSON.stringify(moveInOrder(["a", "b", "c", "d"], 0, 2)) === JSON.stringify(["
ok(JSON.stringify(moveInOrder(["a", "b", "c", "d"], 3, 0)) === JSON.stringify(["d", "a", "b", "c"]), "move last to top");
ok(JSON.stringify(moveInOrder(["a", "b", "c", "d"], 1, 1)) === JSON.stringify(["a", "b", "c", "d"]), "no-op on same index");
// ---- export (combineMarkdown + buildZip) ----
const exportOut = path.join(os.tmpdir(), `folio-export-${process.pid}.cjs`);
await esbuild.build({
entryPoints: [path.resolve("src/main/export.ts")],
bundle: true,
platform: "node",
format: "cjs",
outfile: exportOut,
write: true,
logLevel: "silent",
});
const exportMod = (await import(url.pathToFileURL(exportOut).href)).default;
const { combineMarkdown, buildZip } = exportMod;
const b1 = createChapter(dir, "Intro");
setChapterContent(dir, b1.id, "# Intro\n\nHello world\n\n- a\n- b");
const b2 = createChapter(dir, "Scene");
setChapterContent(dir, b2.id, "## Scene one\n\nIt was a night.");
const combined = combineMarkdown(dir);
ok(combined.includes("# Test Book"), "combined markdown starts with book title");
ok(combined.includes("## Intro"), "combined markdown has chapter heading (Intro)");
ok(combined.includes("## Scene"), "combined markdown has chapter heading (Scene)");
ok(combined.includes("- a") && combined.includes("It was a night"), "combined markdown includes chapter content in order");
ok(combined.startsWith("# Test Book"), "combined markdown first line is book title");
const zip = await buildZip(dir);
ok(Buffer.isBuffer(zip), "buildZip returns a Buffer");
ok(zip.length > 0, "zip buffer is non-empty");
ok(zip.includes("book.md"), "zip contains book.md");
ok(zip.includes("title_page.md"), "zip contains title_page.md");
ok(zip.includes("manifest.json"), "zip contains manifest.json");
ok(zip.includes("chapters"), "zip contains a chapters/ folder");
ok(zip.slice(0, 2).toString("ascii") === "PK", "zip starts with PK signature");
fs.rmSync(exportOut, { force: true });
fs.rmSync(projOut, { force: true });
fs.rmSync(chapOut, { force: true });
fs.rmSync(dir, { recursive: true, force: true });