|
| 1 | +import fs from 'node:fs'; |
| 2 | + |
| 3 | +const INDEX_PATH = 'index.html'; |
| 4 | +const OPEN = '<script id="demo-data" type="application/json">'; |
| 5 | +const CLOSE = '</' + 'script>'; |
| 6 | + |
| 7 | +function extract() { |
| 8 | + const html = fs.readFileSync(INDEX_PATH, 'utf8'); |
| 9 | + const start = html.indexOf(OPEN); |
| 10 | + if (start === -1) throw new Error('demo-data opening tag not found in index.html'); |
| 11 | + const jsonStart = start + OPEN.length; |
| 12 | + const end = html.indexOf(CLOSE, jsonStart); |
| 13 | + if (end === -1) throw new Error('demo-data closing tag not found in index.html'); |
| 14 | + return JSON.parse(html.slice(jsonStart, end).trim()); |
| 15 | +} |
| 16 | + |
| 17 | +const data = extract(); |
| 18 | +const requiredTopLevel = [ |
| 19 | + 'meta','categories','people','appearances','roster','topRoster','expansionRoster' |
| 20 | +]; |
| 21 | +for (const key of requiredTopLevel) { |
| 22 | + if (!(key in data)) throw new Error(`missing top-level key ${key}`); |
| 23 | +} |
| 24 | +for (const key of ['categories','people','appearances','roster','expansionRoster']) { |
| 25 | + if (!Array.isArray(data[key])) throw new Error(`${key} must be an array`); |
| 26 | +} |
| 27 | +const minimums = { people: 90, roster: 190, expansionRoster: 100, appearances: 500, categories: 10 }; |
| 28 | +for (const [key, min] of Object.entries(minimums)) { |
| 29 | + if (data[key].length < min) throw new Error(`${key} count too low: ${data[key].length} < ${min}`); |
| 30 | +} |
| 31 | +const firstAppearance = data.appearances[0] || {}; |
| 32 | +for (const key of ['id','personId','startsAt','title','location','sourcePack']) { |
| 33 | + if (!(key in firstAppearance)) throw new Error(`appearance schema missing ${key}`); |
| 34 | +} |
| 35 | +console.log(JSON.stringify({ |
| 36 | + status: 'validation_passed', |
| 37 | + people: data.people.length, |
| 38 | + roster: data.roster.length, |
| 39 | + expansionRoster: data.expansionRoster.length, |
| 40 | + appearances: data.appearances.length, |
| 41 | + categories: data.categories.length, |
| 42 | + version: data.meta?.version || null, |
| 43 | + lastDataUpdate: data.meta?.lastDataUpdate || null |
| 44 | +}, null, 2)); |
0 commit comments