/** * `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). */ 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'] } ]; /** Single files: the page shell and the config that builds the web manifest. */ const FILES: readonly string[] = ['apps/rosea/index.html', 'apps/rosea/vite.config.ts']; 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); } 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);