20 lines
1.1 KiB
JavaScript
20 lines
1.1 KiB
JavaScript
|
|
const { internal } = require('../config/environment.cjs');
|
||
|
|
|
||
|
|
function assertInstallableConfig(config) {
|
||
|
|
const variant = config.extra?.environment;
|
||
|
|
if (!['dev', 'prod'].includes(variant)) throw Error('Explicit App environment required');
|
||
|
|
if (!config.updates?.enabled || !config.updates.codeSigningCertificate) throw Error('Installable App requires signed updates');
|
||
|
|
const url = new URL(config.updates.url);
|
||
|
|
// Loopback is valid for local preview, never for an APK delivered to phones.
|
||
|
|
internal(url.origin, false);
|
||
|
|
if (url.pathname !== `/updates/${variant}` || url.search || url.hash) throw Error('Update channel must match App environment');
|
||
|
|
if (config.updates.codeSigningMetadata?.keyid !== variant) throw Error('Update signing key must match App environment');
|
||
|
|
if (config.android?.package !== (variant === 'dev' ? 'cn.cmvr.wms.dev' : 'cn.cmvr.wms')) throw Error('App package/environment mismatch');
|
||
|
|
return url.toString();
|
||
|
|
}
|
||
|
|
module.exports = { assertInstallableConfig };
|
||
|
|
if (require.main === module) {
|
||
|
|
const config = require('../app.config.js')();
|
||
|
|
console.log(`Installable ${config.extra.environment} App: ${assertInstallableConfig(config)}`);
|
||
|
|
}
|