mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-12-03 00:09:19 -08:00
Replace the desktop app placeholder pictures with real captures, redraw the banner
AI Assisted
This commit is contained in:
1 parent
ccf82c4eb7
commit
bc2325e061
12 files changed
+468
-75
No files matched your search
@@ -0,0 +1,322 @@
|
||||
// The desktop app's five pictures for the docs, taken by
|
||||
// `node scripts/capture-screenshots.mjs --app`. Dev-only.
|
||||
//
|
||||
// The app's own page (plan2code-app/ui: the bar, the launch card, the loop
|
||||
// banner, the terminal panel) runs in Chrome from a small static server, with
|
||||
// a stand-in for the Rust side of window.__TAURI__: `invoke` answers from a
|
||||
// fixed table, `listen` keeps the handlers so a scene can fire `console-page`
|
||||
// and the agent's output channel. The dashboard in its frame is a real console
|
||||
// session staged the same way as every other shot (capture-screenshots.mjs),
|
||||
// with PLAN2CODE_IN_APP and PLAN2CODE_EMBED_ORIGIN set so it may be framed and
|
||||
// draws its app-only parts (the loop cards, the loop setup, the stop screen).
|
||||
// The terminal text is written by the scene: no agent runs.
|
||||
//
|
||||
// Each shot is dark only, 1280x800 at twice the pixel density, Ocean highlight.
|
||||
|
||||
import fs from "node:fs";
|
||||
import http from "node:http";
|
||||
import path from "node:path";
|
||||
|
||||
export const APP_SHOTS = ["app-launch", "app-terminal", "loop-setup", "loop-banner", "loop-stop"];
|
||||
|
||||
const TYPES = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png", ".woff2": "font/woff2" };
|
||||
|
||||
/** Serves plan2code-app/ui on 127.0.0.1. Resolves { origin, close }. */
|
||||
export function serveAppUi(root) {
|
||||
const dir = path.join(root, "plan2code-app", "ui");
|
||||
for (const f of ["xterm.js", "addon-fit.js", "xterm.css", "tokens.css"]) {
|
||||
if (!fs.existsSync(path.join(dir, "vendor", f))) {
|
||||
throw new Error(`plan2code-app/ui/vendor/${f} is missing: run \`npm install\` and \`node scripts/vendor.mjs\` in plan2code-app first.`);
|
||||
}
|
||||
}
|
||||
const server = http.createServer((req, res) => {
|
||||
const rel = decodeURIComponent(new URL(req.url, "http://x").pathname).replace(/^\/+/, "") || "index.html";
|
||||
const abs = path.join(dir, rel);
|
||||
if (!abs.startsWith(dir + path.sep) || !fs.existsSync(abs) || !fs.statSync(abs).isFile()) {
|
||||
res.writeHead(404);
|
||||
return res.end();
|
||||
}
|
||||
res.writeHead(200, { "content-type": TYPES[path.extname(abs)] || "application/octet-stream", "cache-control": "no-store" });
|
||||
fs.createReadStream(abs).pipe(res);
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
resolve({ origin: `http://127.0.0.1:${server.address().port}`, close: () => new Promise((r) => server.close(r)) });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// The launch card's agents, the way the Rust side lists them: the three
|
||||
// built-ins, installed, with the shipped model menu.
|
||||
function availability(root) {
|
||||
const models = JSON.parse(fs.readFileSync(path.join(root, "src", "launcher", "models.json"), "utf8"));
|
||||
const entry = (id, label) => ({ id, label, installed: true, state: "found", path: null, folder: null, installHint: "", installUrl: null, hasEffort: id !== "devin", custom: false, models: models[id] || [] });
|
||||
return { agents: [entry("claude", "Claude Code"), entry("codex", "Codex"), entry("devin", "Devin")], warnings: [] };
|
||||
}
|
||||
|
||||
// Runs in the app page only (the console's frame gets nothing): the stand-in
|
||||
// for the Tauri globals. `config` comes from the scene.
|
||||
function tauriStub(config) {
|
||||
if (window.top !== window) return;
|
||||
const hub = { listeners: {}, channel: null, config };
|
||||
window.__p2c = hub;
|
||||
class Channel {
|
||||
constructor() {
|
||||
this.onmessage = null;
|
||||
}
|
||||
}
|
||||
const answers = {
|
||||
app_state: () => ({
|
||||
projectDir: config.projectDir,
|
||||
firstRunDone: true,
|
||||
nodeChecked: true,
|
||||
nodeVersion: "22.11.0",
|
||||
// Nothing saved: the app's own default split for this window width.
|
||||
termPanel: null,
|
||||
// One step under the default, so the scenes' lines fit the default pane.
|
||||
terminalFontSize: 12,
|
||||
copyOnSelect: false,
|
||||
lastAgent: "claude",
|
||||
launchModel: "",
|
||||
}),
|
||||
agent_availability: () => config.availability,
|
||||
platform_info: () => ({ os: "windows", windowsBuild: 26100 }),
|
||||
agent_reattach: (args) => {
|
||||
hub.channel = args.onOutput;
|
||||
return { state: "idle", generation: 0 };
|
||||
},
|
||||
loop_state: () => config.loopState,
|
||||
loop_facts: () => config.loopFacts,
|
||||
console_status: () => ({ state: "running" }),
|
||||
console_start: () => ({ url: hub.consoleUrl }),
|
||||
version_status: () => ({ mismatch: false }),
|
||||
check_new_release: () => ({ latest: null, problem: null }),
|
||||
recent_folders: () => [],
|
||||
};
|
||||
const windowApi = new Proxy({}, { get: (_, name) => (name === "setTitle" ? async (t) => { document.title = t; } : async () => {}) });
|
||||
window.__TAURI__ = {
|
||||
core: {
|
||||
Channel,
|
||||
invoke: async (cmd, args) => (answers[cmd] ? answers[cmd](args || {}) : null),
|
||||
},
|
||||
event: {
|
||||
listen: async (name, cb) => {
|
||||
(hub.listeners[name] ||= []).push(cb);
|
||||
return () => {};
|
||||
},
|
||||
},
|
||||
window: { getCurrentWindow: () => windowApi },
|
||||
};
|
||||
hub.emit = (name, payload) => (hub.listeners[name] || []).forEach((cb) => cb({ payload }));
|
||||
hub.agent = (state) => hub.channel && hub.channel.onmessage(state);
|
||||
hub.write = (text) => hub.channel && hub.channel.onmessage(new TextEncoder().encode(text).buffer);
|
||||
}
|
||||
|
||||
// What the terminal shows in each scene. Plain words in the shape of an agent's
|
||||
// session, not any agent's real screen.
|
||||
const DIM = "\x1b[2m";
|
||||
const OFF = "\x1b[0m";
|
||||
const BLUE = "\x1b[38;5;75m";
|
||||
const GREEN = "\x1b[32m";
|
||||
const RED = "\x1b[31m";
|
||||
const lines = (...rows) => rows.join("\r\n") + "\r\n";
|
||||
|
||||
const TERM_DASHBOARD = lines(
|
||||
`${DIM}~/code/task-api${OFF}`,
|
||||
"",
|
||||
`${BLUE}>${OFF} /plan2code`,
|
||||
"",
|
||||
"● Opening the dashboard.",
|
||||
"",
|
||||
"● Bash(console.mjs open)",
|
||||
` ${DIM}⎿ → See the dashboard${OFF}`,
|
||||
` ${DIM}beside this terminal.${OFF}`,
|
||||
"",
|
||||
"● The dashboard is open.",
|
||||
" Phases 1 and 2 are done.",
|
||||
" Implement is next, for",
|
||||
" Phase 3. Pick a card",
|
||||
" when you are ready.",
|
||||
"",
|
||||
`${DIM} Waiting for your pick...${OFF}`,
|
||||
);
|
||||
|
||||
const TERM_BUILDING = lines(
|
||||
`${DIM}Phase 3 of 4, by the loop${OFF}`,
|
||||
"",
|
||||
"● Read(phase-3.md)",
|
||||
"",
|
||||
"● Update(routes.js)",
|
||||
` ${DIM}⎿ GET /tasks, paged${OFF}`,
|
||||
"",
|
||||
"● Update(tasks.test.js)",
|
||||
` ${DIM}⎿ 6 tests for paging${OFF}`,
|
||||
"",
|
||||
"● Bash(npm test)",
|
||||
` ${DIM}⎿${OFF} ${GREEN}✔ 41 passed${OFF} ${DIM}(1.8s)${OFF}`,
|
||||
"",
|
||||
"● Task 3.1 done.",
|
||||
" Next: POST /tasks.",
|
||||
"",
|
||||
"● Update(routes.js)",
|
||||
` ${DIM}⎿ POST /tasks with Zod${OFF}`,
|
||||
);
|
||||
|
||||
const TERM_STOPPED = lines(
|
||||
`${DIM}Phase 3 of 4, by the loop${OFF}`,
|
||||
"",
|
||||
"● Update(routes.js)",
|
||||
` ${DIM}⎿ PATCH, DELETE /tasks/:id${OFF}`,
|
||||
"",
|
||||
"● Bash(npm test)",
|
||||
` ${DIM}⎿${OFF} ${RED}✖ 2 failed${OFF}, 46 passed`,
|
||||
"",
|
||||
"● Still failing after a fix",
|
||||
" round. Reporting to the",
|
||||
" loop.",
|
||||
);
|
||||
|
||||
const LOOP_FACTS = { agent: "claude", agentLabel: "Claude Code", model: "opus", effort: "high", permissionMode: "bypass", promptSupport: true, running: false };
|
||||
|
||||
const LOOP_RUNNING = {
|
||||
running: true,
|
||||
kind: "phases",
|
||||
phase: 3,
|
||||
phases: 4,
|
||||
phaseName: "API endpoints",
|
||||
step: "Building",
|
||||
specName: "task-api",
|
||||
strength: "balanced",
|
||||
model: "sonnet",
|
||||
effort: "high",
|
||||
retriesUsed: 0,
|
||||
canStopAfter: true,
|
||||
};
|
||||
|
||||
const LOOP_STOPPED = {
|
||||
kind: "stopped",
|
||||
reason: "Phase 3 stopped: its tests still failed after a fix round.",
|
||||
line: "npm test failed twice in Phase 3: PATCH /tasks/:id answers 200 for a deleted task, and a second DELETE answers 204 (test/tasks.test.js)",
|
||||
advice: "Decide whether a deleted task should answer 404 or 410, then fix it together with an agent.",
|
||||
recommend: "fix",
|
||||
phase: 3,
|
||||
phases: [
|
||||
{ n: 3, name: "API endpoints", commit: null, unfixed: 0, retries: 1 },
|
||||
{ n: 4, name: "Authentication", commit: null, unfixed: 0, retries: 0 },
|
||||
],
|
||||
uncommitted: ["src/tasks/routes.js", "test/tasks.test.js"],
|
||||
can: ["ask", "resume", "fix", "dashboard"],
|
||||
};
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
/**
|
||||
* Takes one app shot. `h` carries what capture-screenshots.mjs owns: the
|
||||
* browser, the app page's origin, the sample project, `cli`, `post`, `stage`
|
||||
* and the output folder.
|
||||
*/
|
||||
export async function captureAppShot(name, h) {
|
||||
const { browser, origin, project, cli, post, stage, root, out } = h;
|
||||
const config = { projectDir: project, availability: availability(root), loopFacts: LOOP_FACTS, loopState: null };
|
||||
let sid = null;
|
||||
let url = null;
|
||||
if (name === "app-terminal" || name === "loop-setup") {
|
||||
({ sid, url } = stage(project, { workflow: "dashboard", posts: ["dashboard"] }));
|
||||
} else if (name === "loop-banner" || name === "loop-stop") {
|
||||
// A loop phase's page: opened with --loop, which only works under the app.
|
||||
const r = cli(project, "open", "--workflow", "implement", "--spec", "specs/task-api", "--loop", "--no-open");
|
||||
if (r.code !== 0 || !r.out || !r.out.url) throw new Error(`open --loop failed (${r.code}): ${r.err.trim()}`);
|
||||
({ sid, url } = { sid: r.out.sid, url: r.out.url });
|
||||
post(project, sid, "build");
|
||||
if (name === "loop-banner") config.loopState = { ...LOOP_RUNNING, startedAtMs: 0 };
|
||||
else {
|
||||
const file = path.join(path.dirname(r.out.session), `loop-end-${sid}.json`);
|
||||
fs.writeFileSync(file, JSON.stringify({ loopEnd: LOOP_STOPPED, agent: { status: "waiting" } }));
|
||||
const p = cli(project, "post", "--session", sid, "--file", file);
|
||||
if (p.code !== 0) throw new Error(`posting the loop's end failed (${p.code}): ${p.err.trim()}`);
|
||||
}
|
||||
}
|
||||
|
||||
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 }, deviceScaleFactor: 2, colorScheme: "dark" });
|
||||
try {
|
||||
await ctx.addInitScript(tauriStub, config);
|
||||
const page = await ctx.newPage();
|
||||
page.on("pageerror", (e) => console.log(` page error: ${e.message}`));
|
||||
await page.goto(origin + "/index.html", { waitUntil: "domcontentloaded" });
|
||||
await page.waitForFunction(() => window.__p2c && window.__p2c.channel, null, { timeout: 15000 });
|
||||
// The banner's clock: started 23 minutes ago, set once the page is up.
|
||||
if (config.loopState) {
|
||||
await page.evaluate(() => {
|
||||
const s = { ...window.__p2c.config.loopState, startedAtMs: Date.now() - 23 * 60 * 1000 - 12000 };
|
||||
window.__p2c.emit("loop-state", s);
|
||||
});
|
||||
}
|
||||
|
||||
if (name === "app-launch") {
|
||||
await page.locator("#launch-card:not([hidden])").waitFor({ timeout: 10000 });
|
||||
await page.selectOption("#launch-model", "opus");
|
||||
await page.selectOption("#launch-effort", "high");
|
||||
await sleep(800);
|
||||
} else {
|
||||
const ended = name === "loop-stop";
|
||||
await page.evaluate(
|
||||
({ text, ended, loop }) => {
|
||||
const p = window.__p2c;
|
||||
p.agent({ state: "running", kind: "claude", generation: 1, mode: "bypass", model: loop ? "sonnet" : "opus", effort: "high" });
|
||||
p.write(text);
|
||||
if (ended) p.agent({ state: "ended", kind: "claude", generation: 1, mode: "bypass", model: "sonnet", effort: "high", reason: "exited with code 0" });
|
||||
},
|
||||
{ text: name === "loop-banner" ? TERM_BUILDING : name === "loop-stop" ? TERM_STOPPED : TERM_DASHBOARD, ended, loop: name.startsWith("loop-") && name !== "loop-setup" },
|
||||
);
|
||||
await page.evaluate((u) => {
|
||||
window.__p2c.consoleUrl = u;
|
||||
window.__p2c.emit("console-page", { url: u, sid: "", workflow: "" });
|
||||
}, url);
|
||||
const frame = page.frameLocator("iframe");
|
||||
// The dashboard in the app opens on Planny asleep: wake him the way a
|
||||
// person would, past the intro.
|
||||
if (name === "app-terminal" || name === "loop-setup") {
|
||||
const skip = frame.getByRole("button", { name: "Skip the intro" });
|
||||
await skip.waitFor({ timeout: 20000 });
|
||||
await skip.click();
|
||||
await skip.waitFor({ state: "hidden" });
|
||||
}
|
||||
// Anything drawn in the main column: cards, the loop's end, or a phase's
|
||||
// build-in-progress heading.
|
||||
const drawn = frame.locator(".dash-card, .card, .handoff, .loop-end, #main h1, #main h2").first();
|
||||
await drawn.waitFor({ timeout: 20000 }).catch(async () => {
|
||||
const text = await frame.locator("body").innerText().catch(() => "");
|
||||
console.log(` warning: ${name}: nothing known drew in the frame; it reads: ${text.slice(0, 300).replace(/\s+/g, " ")}`);
|
||||
});
|
||||
// The cards' entrance.
|
||||
await sleep(3500);
|
||||
// The dashboard: the suggested card in view, as in the console's own shot.
|
||||
if (name === "app-terminal") {
|
||||
await frame.locator(".dash-toggle").evaluate((n) => n.scrollIntoView({ block: "start", behavior: "instant" }));
|
||||
await sleep(400);
|
||||
}
|
||||
if (name === "loop-setup") {
|
||||
// The card is the button itself.
|
||||
await frame.locator(".dash-card", { hasText: "Implementation Loop" }).first().click();
|
||||
await frame.locator("#loop-start").waitFor({ timeout: 10000 });
|
||||
await sleep(1500);
|
||||
// From its top: the spec, the phases left and the strength.
|
||||
await frame.locator(".loop-setup, #main").first().evaluate((n) => n.scrollIntoView({ block: "start", behavior: "instant" }));
|
||||
await sleep(400);
|
||||
}
|
||||
if (name === "loop-stop") await frame.locator(".loop-end-actions").waitFor({ timeout: 10000 });
|
||||
}
|
||||
|
||||
const cdp = await ctx.newCDPSession(page);
|
||||
const clip = { x: 0, y: 0, width: 1280, height: 800, scale: 2 };
|
||||
const { data } = await cdp.send("Page.captureScreenshot", { format: "webp", quality: 85, captureBeyondViewport: false, clip });
|
||||
await cdp.detach();
|
||||
const file = path.join(out, `${name}-dark.webp`);
|
||||
fs.writeFileSync(file, Buffer.from(data, "base64"));
|
||||
console.log(`${path.basename(file)} ${Math.round(fs.statSync(file).size / 1024)} KB`);
|
||||
return file;
|
||||
} finally {
|
||||
await ctx.close();
|
||||
if (sid) cli(project, "stop", "--session", sid);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@
|
||||
//
|
||||
// Shots: dashboard, dashboard-plan, dashboard-utilities, question, doc, build, signoff, signoff-changes, finish, ask, git,
|
||||
// notebook, learning, lessons, deps, activities and prototypes.
|
||||
// --app takes the desktop app's five pictures instead (app-launch, app-terminal,
|
||||
// loop-setup, loop-banner, loop-stop; dark only): the app's own page with a
|
||||
// stand-in for its Rust side, framing a real staged console. See
|
||||
// scripts/capture-app-shots.mjs. --only picks one of them.
|
||||
// --compare adds workspace, stop, delete, help, prefs and cleanup: screens the
|
||||
// docs never show, for checking a change by eye against a "before" set. Its
|
||||
// --out must be outside docs/screenshots/, so the set is never published.
|
||||
@@ -37,6 +41,7 @@ import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { launchBrowser } from "./browser.mjs";
|
||||
import { APP_SHOTS, captureAppShot, serveAppUi } from "./capture-app-shots.mjs";
|
||||
|
||||
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||
const CONSOLE_CLI = path.join(ROOT, "src", "web-console", "console.mjs");
|
||||
@@ -659,8 +664,12 @@ async function main() {
|
||||
fail(`--compare never writes into ${path.relative(ROOT, docs)}: pass --out with a folder outside it.`);
|
||||
}
|
||||
const table = args.compare ? { ...SHOTS, ...COMPARE_SHOTS } : SHOTS;
|
||||
const names = args.only ? [args.only] : Object.keys(table);
|
||||
for (const n of names) if (!table[n]) fail(`Unknown shot "${n}". Shots: ${Object.keys(table).join(", ")}`);
|
||||
const known = args.app ? APP_SHOTS : Object.keys(table);
|
||||
const names = args.only ? [args.only] : known;
|
||||
for (const n of names) if (!known.includes(n)) fail(`Unknown shot "${n}". Shots: ${known.join(", ")}`);
|
||||
// The app's page is served before any console starts: the console is told
|
||||
// its origin is allowed to frame it.
|
||||
const appUi = args.app ? await serveAppUi(ROOT) : null;
|
||||
|
||||
SCRATCH = fs.mkdtempSync(path.join(SCRATCH_ROOT, "p2c-shots-"));
|
||||
HOME = path.join(SCRATCH, "console-home");
|
||||
@@ -672,7 +681,11 @@ async function main() {
|
||||
PLAN2CODE_NOTEPADS_DIR: path.join(SCRATCH, "notepads"),
|
||||
PLAN2CODE_LEARNING_DIR: path.join(SCRATCH, "learning"),
|
||||
PLAN2CODE_NO_BROWSER: "1",
|
||||
...(appUi ? { PLAN2CODE_IN_APP: "1", PLAN2CODE_EMBED_ORIGIN: appUi.origin } : {}),
|
||||
};
|
||||
// Never announce to a real app window this shell may have inherited.
|
||||
for (const k of ["PLAN2CODE_APP_TOKEN", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_CONSOLE_SID", "PLAN2CODE_APP_VERSION"]) delete ENV[k];
|
||||
if (!appUi) delete ENV.PLAN2CODE_IN_APP;
|
||||
fs.mkdirSync(HOME, { recursive: true });
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
let browser = null;
|
||||
@@ -687,7 +700,10 @@ async function main() {
|
||||
...(typeof args.browser === "string" ? { executablePath: args.browser } : {}),
|
||||
args: ["--no-first-run", "--no-default-browser-check", "--mute-audio"],
|
||||
});
|
||||
for (const name of names) {
|
||||
if (appUi) {
|
||||
for (const name of names) await captureAppShot(name, { browser, origin: appUi.origin, project, cli, post, stage, root: ROOT, out: OUT });
|
||||
}
|
||||
for (const name of appUi ? [] : names) {
|
||||
const spec = table[name];
|
||||
const where = spec.repo
|
||||
? makeGitProject()
|
||||
@@ -709,6 +725,7 @@ async function main() {
|
||||
if (args.snapshot) fs.writeFileSync(path.resolve(String(args.snapshot)), JSON.stringify(SNAP));
|
||||
} finally {
|
||||
if (browser) await browser.close();
|
||||
if (appUi) await appUi.close();
|
||||
if (project) cli(project, "stop", "--all");
|
||||
removeScratch();
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Writes labeled placeholder pictures for the desktop app and the Implementation
|
||||
// Loop (docs/screenshots/app-*.webp, loop-*.webp) so the docs and the landing page
|
||||
// carry their final markup before the owner has captured the real window.
|
||||
// Replace each file with the real capture (same name, same 2560x1600 size);
|
||||
// nothing else needs editing. The shot list (state, window size, theme) is in
|
||||
// specs/polish-3-2/phase-11.md's completion summary. Dev-only.
|
||||
//
|
||||
// node scripts/make-app-placeholders.mjs [--browser <path>] [--force]
|
||||
//
|
||||
// Never overwrites a file that exists unless --force: a real capture stays.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { launchBrowser } from "./browser.mjs";
|
||||
|
||||
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||
const DIR = path.join(ROOT, "docs", "screenshots");
|
||||
const SHOTS = [
|
||||
["app-launch-dark", "The launch card", "Which agent, model and effort to start on"],
|
||||
["app-terminal-dark", "The app with the terminal docked", "The dashboard beside the agent's terminal"],
|
||||
["loop-setup-dark", "Implementation Loop setup", "The setup screen before a run"],
|
||||
["loop-banner-dark", "The Loop mid-run", "The banner while a phase builds"],
|
||||
["loop-stop-dark", "The Loop's stop screen", "Why it stopped, with the evidence"],
|
||||
];
|
||||
|
||||
const force = process.argv.includes("--force");
|
||||
const flag = process.argv.indexOf("--browser");
|
||||
const browser = await launchBrowser(flag > 0 ? { executablePath: process.argv[flag + 1] } : {});
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
for (const [name, title, line] of SHOTS) {
|
||||
const out = path.join(DIR, `${name}.webp`);
|
||||
if (fs.existsSync(out) && !force) {
|
||||
console.log(`${name}.webp exists, kept`);
|
||||
continue;
|
||||
}
|
||||
const data = await page.evaluate(
|
||||
([t, l]) => {
|
||||
const c = document.createElement("canvas");
|
||||
c.width = 2560;
|
||||
c.height = 1600;
|
||||
const g = c.getContext("2d");
|
||||
g.fillStyle = "#171513";
|
||||
g.fillRect(0, 0, 2560, 1600);
|
||||
g.strokeStyle = "#46403a";
|
||||
g.setLineDash([24, 16]);
|
||||
g.lineWidth = 4;
|
||||
g.strokeRect(60, 60, 2440, 1480);
|
||||
g.fillStyle = "#f0ece5";
|
||||
g.textAlign = "center";
|
||||
g.font = "700 96px sans-serif";
|
||||
g.fillText(t, 1280, 740);
|
||||
g.fillStyle = "#b6afa3";
|
||||
g.font = "400 56px sans-serif";
|
||||
g.fillText(l, 1280, 840);
|
||||
g.fillStyle = "#e0a24a";
|
||||
g.font = "600 44px sans-serif";
|
||||
g.fillText("Placeholder: the real capture goes here", 1280, 960);
|
||||
return c.toDataURL("image/webp", 0.85).split(",")[1];
|
||||
},
|
||||
[title, line],
|
||||
);
|
||||
fs.writeFileSync(out, Buffer.from(data, "base64"));
|
||||
console.log(`${name}.webp ${Math.round(fs.statSync(out).size / 1024)} KB`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/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 <path>]
|
||||
//
|
||||
// The five Plannys are the console's own step poses (the <svg data-pose> 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 <svg> from the console page, by its data-pose.
|
||||
function pose(html, name) {
|
||||
const m = new RegExp(`<svg class="pose[^"]*" data-pose="${name}"[\\s\\S]*?</svg>`).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(`<i style="left:${x.toFixed(2)}%;top:${y.toFixed(2)}%;width:${blue ? 3 : 2 + Math.round(rand())}px;height:${blue ? 3 : 2 + Math.round(rand())}px;background:${blue ? "var(--accent)" : "var(--ink-3)"};opacity:${(0.35 + rand() * 0.5).toFixed(2)}"></i>`);
|
||||
}
|
||||
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 = `<!doctype html>
|
||||
<html data-theme="dark"><head><meta charset="utf-8">
|
||||
<link rel="stylesheet" href="${css("tokens.css")}">
|
||||
<link rel="stylesheet" href="${css("poses.css")}">
|
||||
<style>
|
||||
*, *::before, *::after { animation: none !important; transition: none !important; }
|
||||
html, body { margin: 0; background: var(--bg); }
|
||||
.banner { position: relative; width: 1024px; height: 300px; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); }
|
||||
.sky i { position: absolute; border-radius: 50%; }
|
||||
.words { position: absolute; left: 44px; top: 62px; }
|
||||
h1 { margin: 0; font: 700 74px/1 var(--serif); letter-spacing: -1px; color: var(--ink); }
|
||||
h1 b { color: var(--accent); font-weight: 700; }
|
||||
.tag { margin: 22px 0 0; font-size: 23px; color: var(--ink-2); }
|
||||
.tag em { font-style: normal; color: var(--accent); }
|
||||
.foot { margin: 22px 0 0; font-size: 12px; font-weight: 600; letter-spacing: 2.4px; text-transform: uppercase; color: var(--ink-3); }
|
||||
.steps { position: absolute; left: 462px; right: 40px; top: 86px; display: flex; justify-content: space-between; }
|
||||
.path { position: absolute; left: 470px; right: 52px; top: 176px; border-top: 2px dashed var(--rule-2); }
|
||||
.step { width: 104px; text-align: center; position: relative; }
|
||||
.step .pose { height: 92px; width: auto; margin: 0 auto; display: block; }
|
||||
.step span { display: block; margin-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--ink-2); }
|
||||
</style></head><body>
|
||||
<div class="banner">
|
||||
<div class="sky">${stars()}</div>
|
||||
<div class="words">
|
||||
<h1>Plan<b>2</b>Code</h1>
|
||||
<p class="tag">Plan it. Approve it. <em>Let it build.</em></p>
|
||||
<p class="foot">${FOOT}</p>
|
||||
</div>
|
||||
<div class="path"></div>
|
||||
<div class="steps">${STEPS.map(([id, label]) => `<div class="step">${pose(index, id)}<span>${label}</span></div>`).join("")}</div>
|
||||
</div>
|
||||
</body></html>`;
|
||||
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 });
|
||||
}
|
||||
Reference in new issue
Block a user