// Build the homepage artifact from the Builder export using our own engine. // Output: src/generated/home.json = { css, scripts, html: { en, ja } } import fs from "node:fs"; import path from "node:path"; const PAGE_DIR = "builder-export/page"; const SYM_DIR = "builder-export/symbol"; const PAGE_NAME = "Beyond 2 - LIVE"; // The Builder export is local-only design/source material (gitignored). When it's // absent (fresh clone / CI / Coolify build), keep the committed src/generated/home.json. // NB: engine.mjs reads the export at import time, so it must be loaded *after* this // guard (dynamic import) — a static import would run, and crash, before the check. if (!fs.existsSync(PAGE_DIR)) { console.warn(`[build-home] ${PAGE_DIR} not present (source export is local-only) — keeping committed src/generated/home.json`); process.exit(0); } const { renderPage } = await import("./builder/engine.mjs"); let page; for (const f of fs.readdirSync(PAGE_DIR)) { if (f === "_all.json") continue; const x = JSON.parse(fs.readFileSync(path.join(PAGE_DIR, f), "utf8")); if (x.name === PAGE_NAME) { page = x; break; } } if (!page) throw new Error(`page not found: ${PAGE_NAME}`); const symbols = new Map(); for (const s of JSON.parse(fs.readFileSync(path.join(SYM_DIR, "_all.json"), "utf8"))) { symbols.set(s.id, s); } const blocks = page.data.blocks || []; const en = renderPage(blocks, symbols, "en"); const ja = renderPage(blocks, symbols, "ja"); // Per-page CSS authored in Builder (data.cssCode), applied after compiled styles. const pageCss = page.data?.cssCode ? `\n/* page cssCode */\n${page.data.cssCode}` : ""; const artifact = { meta: { title: page.data?.title || "", description: page.data?.description || "", source: PAGE_NAME, }, css: en.css + pageCss, scripts: en.scripts, html: { en: en.html, ja: ja.html }, }; fs.mkdirSync("src/generated", { recursive: true }); fs.writeFileSync("src/generated/home.json", JSON.stringify(artifact)); console.log("home.json written"); console.log(" css bytes:", artifact.css.length); console.log(" scripts:", artifact.scripts.length); console.log(" html.en bytes:", artifact.html.en.length, "| html.ja bytes:", artifact.html.ja.length);