// duplicate ids in an object literal overwrite silently. this is the only place // that would ever notice. run it after writing philes. import { PHILES, TOTAL } from '../src/philes.js'; import { readFileSync, readdirSync } from 'fs'; const src = readFileSync(new URL('../src/philes.js', import.meta.url), 'utf8'); const ids = [...src.matchAll(/^ {2}'([a-z0-9-]+)': \{/gm)].map(m => m[1]); const dupes = ids.filter((id, i) => ids.indexOf(id) !== i); const used = new Set(); // ids live in a lot of shapes now: phile('x'), phile: 'x', and bare entries in // data tables. so: does the quoted id appear anywhere outside philes.js at all. for (const d of ['../src/', '../src/levels/']) { const dir = new URL(d, import.meta.url); for (const f of readdirSync(dir)) { if (!f.endsWith('.js') || f === 'philes.js') continue; const t = readFileSync(new URL(f, dir), 'utf8'); for (const id of ids) if (t.includes(`'${id}'`)) used.add(id); } } const missing = [...used].filter(id => !PHILES[id]); const orphan = ids.filter(id => !used.has(id)); console.log(`${ids.length}/${TOTAL} written ยท ${ids.length - orphan.length} findable`); if (dupes.length) console.log('DUPLICATE IDS (silently overwritten):', dupes.join(' ')); if (missing.length) console.log('REFERENCED BUT NOT WRITTEN:', missing.join(' ')); if (orphan.length) console.log(`not yet placed in a level (${orphan.length}):`, orphan.join(' ')); process.exit(dupes.length || missing.length ? 1 : 0);