// The guides' pictures, drawn by `just look` from the line above each, so // none is ever taken by hand or goes stale unseen: // // // ![Lantern Hikers, as alice sees it](shots/group.png) // // node harness/shots.mjs [docs/guides/.md ...] `just shots` // // Each guide is drawn over a fresh world of its own, its pictures in the // order the page has them: a seed or a sent form early in a guide is // there for every picture after it, as the reader's own group would be. // Each picture is drawn at desktop size, light as shots/.png and // dark as shots/-dark.png, beside the guides; the docs site shows // the one the reader's scheme asks for. With no guides named, every guide. // // Beside each is shots/.txt, what the picture shows as text: its // headings, buttons, labels and words, as the page's accessibility tree // has them, with what differs from one world to the next (times, DIDs, // ports, a new password) put as a placeholder. Pixels differ between any // two runs; these do not, unless the console does. // // node harness/shots.mjs --check [guide ...] // // draws them all again and compares only the text, writing nothing: it // fails naming each picture whose page has changed, as the e2e check // runs it, so a guide whose console moved on is drawn again // (`just shots`) and its words read against the new pictures. // // A world kept up by `just look-up` would bring its own state into the // pictures, so none may be up. import { spawn } from 'node:child_process'; import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { basename, dirname, join, resolve } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); export const guides = join(root, 'docs/guides'); export const shotsDir = join(guides, 'shots'); /// The options a guide's line may not give: each picture is drawn at the /// one size, in both schemes, where this puts it. const OWN = ['--out', '--name', '--desktop', '--phone', '--light', '--dark', '--all', '--up']; /// A line's words, as a shell splits them: quoted, or not. const words = (line) => [...line.matchAll(/'([^']*)'|"([^"]*)"|(\S+)/g)].map((m) => m[1] ?? m[2] ?? m[3]); /// The pictures a guide's text has: each with the line it is on, its /// name, its words for `just look`, and what is wrong with it, if anything. export function shotsIn(text) { const lines = text.split('\n'); const out = []; lines.forEach((line, i) => { const look = line.match(/^\s*$/); const image = line.match(/!\[[^\]]*\]\(shots\/([^)\s]+)\)/); if (look) { const next = lines[i + 1]?.match(/^\s*!\[[^\]]*\]\(shots\/([a-z0-9-]+)\.png\)$/); const args = words(look[1]); const own = args.find((a) => OWN.includes(a)); const problem = !next ? 'a look line with no picture under it' : own ? `${own}: a guide's picture is drawn at one size in both schemes` : !/^(\/|apps:\/)/.test(args[0] ?? '') ? 'a look line starts with the page, as /g/riders.groups.test' : null; out.push({ line: i + 1, name: next?.[1], args, problem }); } else if (image && !/^\s*