- Generate lan-client/precons.js from precon-decks/precon-index.json so PRECON_DATA is always available for local/offline mode (163 precons) - Add scripts/generate-precons-js.js for regeneration when precons update - Fix _loadBackendPrecons() to re-render the precon tab UI when backend precons load successfully (was only updating status indicator text, not populating the dropdown) Without precons.js, PRECON_DATA was undefined and the dropdown showed 'No precon data loaded' even though 163 .dck files exist in the repo.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Generate lan-client/precons.js from precon-decks/precon-index.json
|
|
* Usage: node scripts/generate-precons-js.js
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const indexPath = path.join(__dirname, '..', 'precon-decks', 'precon-index.json');
|
|
const outputPath = path.join(__dirname, '..', 'lan-client', 'precons.js');
|
|
|
|
const index = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
|
|
|
|
let js = '// Auto-generated from precon-decks/precon-index.json\n';
|
|
js += '// Run: node scripts/generate-precons-js.js to regenerate\n';
|
|
js += 'var PRECON_DATA = [\n';
|
|
|
|
index.forEach(function(p, i) {
|
|
const entry = {
|
|
id: (p.fileName || p.name || '').replace('.dck', ''),
|
|
name: p.name || '',
|
|
commander: p.commander || (p.commanders && p.commanders[0]) || '',
|
|
set: p.set || '',
|
|
fileName: p.fileName || '',
|
|
colors: p.colors || [],
|
|
year: p.year || 0,
|
|
};
|
|
js += ' ' + JSON.stringify(entry);
|
|
js += (i < index.length - 1) ? ',\n' : '\n';
|
|
});
|
|
|
|
js += '];\n';
|
|
|
|
fs.writeFileSync(outputPath, js);
|
|
console.log(`Generated ${outputPath} with ${index.length} precon entries`);
|