| 1 | #!/usr/bin/env node |
| 2 | import { readFileSync, readdirSync, statSync, existsSync } from "node:fs"; |
| 3 | import path from "node:path"; |
| 4 | import { fileURLToPath } from "node:url"; |
| 5 | |
| 6 | const webRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); |
| 7 | const repoRoot = path.resolve(webRoot, ".."); |
| 8 | |
| 9 | const FORBIDDEN = [ |
| 10 | /scripted[-_ ]demo/i, |
| 11 | /scripted[_ ]local/i, |
| 12 | /website-demo/i, |
| 13 | /scripted (test |local )?model/i, |
| 14 | /CODEWHALE_SIMULATOR/, |
| 15 | /\(unenforced\)/, |
| 16 | /names and text in them are placeholders/i, |
| 17 | /taken against a test fixture/i, |
| 18 | ]; |
| 19 | |
| 20 | const ROOTS = [ |
| 21 | "web/lib/terminal-captures", |
| 22 | "web/lib/i18n/dictionaries", |
| 23 | "web/lib/content", |
| 24 | "web/gt-catalog", |
| 25 | "web/data/desktop-media.json", |
| 26 | "README.md", |
| 27 | "docs/i18n", |
| 28 | ]; |
| 29 | |
| 30 | function* walk(target) { |
| 31 | if (!existsSync(target)) return; |
| 32 | if (statSync(target).isFile()) { |
| 33 | yield target; |
| 34 | return; |
| 35 | } |
| 36 | for (const name of readdirSync(target)) { |
| 37 | if (name.endsWith(".test.ts")) continue; |
| 38 | yield* walk(path.join(target, name)); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | const errors = []; |
| 43 | for (const root of ROOTS) { |
| 44 | for (const file of walk(path.join(repoRoot, root))) { |
| 45 | const text = readFileSync(file, "utf8"); |
| 46 | for (const pattern of FORBIDDEN) { |
| 47 | const match = text.match(pattern); |
| 48 | if (match) errors.push(`${path.relative(repoRoot, file)}: "${match[0]}"`); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | const provenance = JSON.parse(readFileSync(path.join(webRoot, "lib/terminal-captures/released/provenance.json"), "utf8")); |
| 54 | if (provenance.model?.scripted !== false) errors.push("released capture provenance must record model.scripted = false"); |
| 55 | |
| 56 | if (errors.length) { |
| 57 | console.error(`media honesty check failed: scripted or simulated media is named in public files:\n- ${errors.join("\n- ")}`); |
| 58 | process.exit(1); |
| 59 | } |
| 60 | |
| 61 | const latest = JSON.parse(readFileSync(path.join(webRoot, "data/latest-published-release.json"), "utf8")); |
| 62 | const captured = provenance.binary?.release_tag ?? null; |
| 63 | if (captured !== latest.tag) { |
| 64 | console.warn( |
| 65 | `media freshness: the home terminal frames come from ${captured ?? `an unpublished build (${provenance.binary?.version_line})`}, and the latest published release is ${latest.tag}. Re-capture them from ${latest.tag} when it is the release the site describes.`, |
| 66 | ); |
| 67 | } |
| 68 | console.log("media honesty check passed"); |
| 69 |