#!/usr/bin/env node // Renders the README banner, docs/banner.jpg (2048x600: 1024x300 at twice the // pixel density). Dev-only. // // node scripts/make-banner.mjs [--browser ] // // The five Plannys are the console's own step poses (the in // src/web-console/public/index.html), drawn with its tokens.css and poses.css // in the dark theme, held still. Rerun it when the tagline, the license or a // step pose changes. Needs playwright-core (a root devDependency) and a local // Chrome or Edge. import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { launchBrowser } from "./browser.mjs"; const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url))); const PUBLIC = path.join(ROOT, "src", "web-console", "public"); const STEPS = [ ["pathfinder", "Pathfinder"], ["plan", "Plan"], ["document", "Document"], ["implement", "Implement"], ["finalize", "Finalize"], ]; const TAGLINE = "Plan it. Approve it. Let it build."; const FOOT = "plan2code.jparkerweb.com ยท Apache 2.0"; // One pose's from the console page, by its data-pose. function pose(html, name) { const m = new RegExp(``).exec(html); if (!m) throw new Error(`no data-pose="${name}" in index.html`); return m[0]; } // A fixed sky, so two runs draw the same picture. function stars() { let seed = 7; const rand = () => ((seed = (seed * 16807) % 2147483647) / 2147483647); const out = []; // Kept off the words and the step labels, where a dot reads as punctuation. const onText = (x, y) => (x < 40 && y > 15 && y < 82) || (x > 43 && y > 58 && y < 76); while (out.length < 34) { const blue = rand() < 0.35; const x = rand() * 100; const y = rand() * 100; if (onText(x, y)) continue; out.push(``); } return out.join(""); } const index = fs.readFileSync(path.join(PUBLIC, "index.html"), "utf8"); const css = (f) => pathToFileURL(path.join(PUBLIC, "styles", f)).href; const page = ` `; if (!page.includes(TAGLINE.split(" Let")[0])) throw new Error("tagline drifted"); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-banner-")); const file = path.join(tmp, "banner.html"); fs.writeFileSync(file, page); const flag = process.argv.indexOf("--browser"); const browser = await launchBrowser(flag > 0 ? { executablePath: process.argv[flag + 1] } : {}); try { const tab = await browser.newPage({ viewport: { width: 1024, height: 300 }, deviceScaleFactor: 2, colorScheme: "dark" }); await tab.goto(pathToFileURL(file).href); await tab.evaluate(() => document.fonts.ready); const out = path.join(ROOT, "docs", "banner.jpg"); await tab.screenshot({ path: out, type: "jpeg", quality: 90, clip: { x: 0, y: 0, width: 1024, height: 300 } }); console.log(`wrote ${path.relative(ROOT, out)} (${Math.round(fs.statSync(out).size / 1024)} KB)`); } finally { await browser.close(); fs.rmSync(tmp, { recursive: true, force: true }); }