import { readFile, writeFile } from 'node:fs/promises'; import { createHash } from 'node:crypto'; const root=new URL('../',import.meta.url); const manifest=JSON.parse(await readFile(new URL('levels/versions/provenance.json',root),'utf8')); const archives={}; for(const source of manifest.versions) { const bytes=await readFile(new URL(source.archivePath,root)); if(createHash('sha256').update(bytes).digest('hex')!==source.sha256)throw new Error(`Historical archive changed: ${source.version}`); const levels=JSON.parse(bytes.toString('utf8')); if(levels.length!==source.levelCount)throw new Error(`Historical level count changed: ${source.version}`); archives[source.version]=levels; } await writeFile(new URL('src/levels-archive.js',root),'// Generated by npm run levels:versions from byte-preserved historical JSON.\nexport const ARCHIVED_LEVELS = '+JSON.stringify(archives)+';\n'); console.log('Historical versions synchronized: '+Object.entries(archives).map(([id,levels])=>`${id} (${levels.length} levels)`).join(', '));