/** * `pnpm lint:copy` — every file a player could read text from, checked for * forbidden words and names (CLAUDE.md §5.6). The rules live in * @rosea/content (copy-lint.ts, forbidden.ts) and are tested there. * * Not scanned: .agents/ and docs/, where the forbidden words may appear because * they are being discussed (§5.6 rule 4). The one exception is docs/LETTER.md: * it lives with the docs but a player reads it (letter-slot.md L6). */ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'; import { extname, join, relative } from 'node:path'; import { fileURLToPath } from 'node:url'; import { lintCopy } from '@rosea/content'; const root = fileURLToPath(new URL('..', import.meta.url)); /** Directories walked, and the extensions read in them. */ const TARGETS: readonly { dir: string; ext: readonly string[] }[] = [ { dir: 'packages/ui/src', ext: ['.ts', '.svelte', '.css'] }, { dir: 'apps/rosea/src', ext: ['.ts', '.svelte', '.css'] }, // Store listings, once they exist, live here and are player-facing too (§8). { dir: 'store', ext: ['.md', '.txt', '.json'] }, // The Aula page's brief and each release's notes: a stranger reads them (fabrica-release.md F11). { dir: '.fabrica/aula', ext: ['.md'] }, { dir: '.fabrica/notes', ext: ['.md'] } ]; /** Single files: the page shell, the config that builds the web manifest, the Letter, and the Aula page's text. */ const FILES: readonly string[] = [ 'apps/rosea/index.html', 'apps/rosea/vite.config.ts', 'docs/LETTER.md', 'AULA.md', // Written by `fabrica notes` from commit subjects during a release; read when it is there, so the // release's `notes-copy` step stops a forbidden word before it reaches the page (fabrica-release.md F11). 'target/notes/release-notes.md' ]; function walk(dir: string, ext: readonly string[]): string[] { if (!existsSync(dir)) return []; return readdirSync(dir).flatMap((entry) => { const full = join(dir, entry); if (statSync(full).isDirectory()) return walk(full, ext); return ext.includes(extname(entry)) ? [full] : []; }); } const files = [ ...TARGETS.flatMap(({ dir, ext }) => walk(join(root, dir), ext)), ...FILES.map((f) => join(root, f)).filter((f) => existsSync(f)) ]; if (files.length === 0) { console.error('lint:copy found no files to check. A check that reads nothing is not a pass.'); process.exit(1); } // `--list` prints what would be read and checks nothing: the seam tools/release tests the list through. if (process.argv.includes('--list')) { for (const file of files) console.log(relative(root, file).replace(/\\/g, '/')); process.exit(0); } let problems = 0; for (const file of files) { for (const p of lintCopy(readFileSync(file, 'utf8'))) { problems += 1; console.error(`${relative(root, file).replace(/\\/g, '/')}:${p.line} ${p.message}`); } } console.log(`lint:copy: ${files.length} files checked, ${problems} problem${problems === 1 ? '' : 's'}`); process.exit(problems === 0 ? 0 : 1);