14 lines
1.3 KiB
JavaScript
14 lines
1.3 KiB
JavaScript
'use strict';
|
|
const fs=require('fs');
|
|
const path=require('path');
|
|
|
|
const root=path.resolve(__dirname,'..');
|
|
const packageJson=JSON.parse(fs.readFileSync(path.join(root,'package.json'),'utf8'));
|
|
const config=JSON.parse(fs.readFileSync(path.join(root,'build-config.json'),'utf8'));
|
|
if(!/^[0-9]+\.[0-9]+\.[0-9]+$/.test(packageJson.version))throw new Error('package.json version must use major.minor.patch');
|
|
const appVersion=packageJson.version.split('.').slice(0,2).join('.');
|
|
for(const key of['SAVE_SCHEMA','STORAGE_SCHEMA','IDB_LAYOUT_VERSION','FIELD_STORAGE_FORMAT','GAMEPLAY_DATA_VERSION','GENERATOR_VERSION'])if(!Number.isSafeInteger(config[key])||config[key]<1)throw new Error(`Invalid ${key}`);
|
|
if(typeof config.WORLD_GENERATION!=='string'||!config.WORLD_GENERATION)throw new Error('Invalid WORLD_GENERATION');
|
|
const meta={APP_VERSION:appVersion,PACKAGE_VERSION:packageJson.version,...config};
|
|
const source=`'use strict';\n// Generated from package.json and build-config.json. Do not edit.\n(function attachBuildMeta(root,factory){\n const api=factory();\n if(typeof module==='object'&&module.exports)module.exports=api;\n if(root)root.BendBuildMeta=api;\n})(typeof globalThis!=='undefined'?globalThis:this,()=>Object.freeze(${JSON.stringify(meta,null,2)}));\n`;
|
|
fs.writeFileSync(path.join(root,'build-meta.js'),source);
|