22 lines
1.2 KiB
JavaScript
22 lines
1.2 KiB
JavaScript
'use strict';
|
|
const fs=require('fs');
|
|
const path=require('path');
|
|
|
|
const root=path.resolve(__dirname,'..');
|
|
const sourcePath=path.join(root,'store-catalog.json');
|
|
const targetPath=path.join(root,'store-catalog.generated.js');
|
|
const catalog=JSON.parse(fs.readFileSync(sourcePath,'utf8'));
|
|
|
|
if(!Array.isArray(catalog)||catalog.length===0)throw new Error('Store catalog must be a non-empty array');
|
|
const ids=new Set();
|
|
for(const item of catalog){
|
|
if(!item||typeof item!=='object'||typeof item.id!=='string'||!/^[A-Za-z0-9:_-]+$/.test(item.id))throw new Error('Store catalog contains an invalid item ID');
|
|
if(ids.has(item.id))throw new Error(`Duplicate store item: ${item.id}`);
|
|
if(!Number.isSafeInteger(item.cost)||item.cost<=0)throw new Error(`Invalid cost for ${item.id}`);
|
|
if(item.cursorStyle!==null&&typeof item.cursorStyle!=='string')throw new Error(`Invalid cursorStyle for ${item.id}`);
|
|
if(typeof item.scoreLens!=='boolean')throw new Error(`Invalid scoreLens for ${item.id}`);
|
|
ids.add(item.id);
|
|
}
|
|
|
|
const body=`'use strict';\n// Generated from store-catalog.json by scripts/generate-store-catalog.js. Do not edit.\nglobalThis.BendStoreCatalog=Object.freeze(${JSON.stringify(catalog)}.map(item=>Object.freeze(item)));\n`;
|
|
fs.writeFileSync(targetPath,body);
|