scripts/fixtures/ holds the scripts that produced the 2026-11-11 fixtures, with a README on running them safely into a copy. Run in order they reproduce the content of every fixture they touch. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
24 lines
1.2 KiB
JavaScript
24 lines
1.2 KiB
JavaScript
import fs from 'node:fs'
|
|
// Fixture regeneration aid (see scripts/fixtures/README.md). Written during the 2026-11-11 build, kept for reference.
|
|
// Writes into fixtures/ unless FIXTURES_OUT names another directory (with a trailing slash).
|
|
const FIX = process.env.FIXTURES_OUT ?? new URL('../../fixtures/', import.meta.url).pathname
|
|
const SOL = new URL('../../js/solutions/', import.meta.url).href
|
|
const HERE = new URL('./', import.meta.url).pathname
|
|
const dir = FIX
|
|
const walk = (x) => {
|
|
if (Array.isArray(x)) return x.map(walk)
|
|
if (x && typeof x === 'object') {
|
|
const o = Object.fromEntries(Object.entries(x).map(([k, v]) => [k, walk(v)]))
|
|
return ('snake' in o && 'nextDir' in o && !('queued' in o)) ? { ...o, queued: null } : o
|
|
}
|
|
return x
|
|
}
|
|
for (const f of fs.readdirSync(dir)) {
|
|
const txt = fs.readFileSync(dir + f, 'utf8')
|
|
if (!f.endsWith('.json')) continue
|
|
const before = JSON.parse(txt)
|
|
const after = walk(before)
|
|
// Only rewrite a file whose content changed; a file with no game states keeps its formatting.
|
|
if (JSON.stringify(after) !== JSON.stringify(before)) { fs.writeFileSync(dir + f, JSON.stringify(after, null, 2) + '\n'); console.log('updated', f) }
|
|
}
|