Throw error on unsupported setting
This should help weed out old junk settings from old versions of CDB config.master
parent
f0bd56193c
commit
987dbaa9c5
|
@ -29,7 +29,8 @@ module.exports = async gitexport => {
|
|||
proc.stdout.on('data', x => buff += x.toString());
|
||||
await proc.promise;
|
||||
const comm = buff.match(/^[0-9a-f]{40}\s/);
|
||||
if(!comm) throw `no commit hash found for ${config.branch}`;
|
||||
if(!comm)
|
||||
throw new Error(`no commit hash found for ${config.branch}`);
|
||||
const commit = comm[0].trim();
|
||||
|
||||
const zipfile = path.join(ziptmp, 'release.zip');
|
||||
|
|
77
config.js
77
config.js
|
@ -7,19 +7,69 @@ const proto = {};
|
|||
const config = Object.create(proto);
|
||||
module.exports = config;
|
||||
|
||||
const layers = {};
|
||||
const layord = 'default conffile gitjson gitlua cmdline'.split(' ');
|
||||
const defaults = {
|
||||
conf: path.join(process.env.HOME, '.cdbrelease.json'),
|
||||
|
||||
const arrays = ['screenshots', 'tags', 'content_warnings'];
|
||||
srcrepo: undefined,
|
||||
branch: 'master',
|
||||
|
||||
execgit: 'git',
|
||||
exectar: 'tar',
|
||||
execlua: 'lua5.1',
|
||||
|
||||
cdbjson: false,
|
||||
cdbjsonpath: '.cdb.json',
|
||||
cdblua: false,
|
||||
cdbluapath: '.cdbrelease.lua',
|
||||
|
||||
root: 'https://content.minetest.net/api',
|
||||
token: null,
|
||||
timeout: 60,
|
||||
|
||||
user: null,
|
||||
pkg: null,
|
||||
|
||||
version: undefined,
|
||||
|
||||
type: undefined,
|
||||
title: undefined,
|
||||
name: undefined,
|
||||
short_description: undefined,
|
||||
tags: undefined,
|
||||
content_warnings: undefined,
|
||||
license: undefined,
|
||||
media_license: undefined,
|
||||
long_description: undefined,
|
||||
repo: undefined,
|
||||
website: undefined,
|
||||
issue_tracker: undefined,
|
||||
forums: undefined,
|
||||
maintainers: undefined,
|
||||
screenshots: undefined
|
||||
};
|
||||
|
||||
proto.allowed = {};
|
||||
Object.keys(defaults)
|
||||
.forEach(k => proto.allowed[k] = true);
|
||||
|
||||
const arrays = [
|
||||
'tags',
|
||||
'content_warnings',
|
||||
'maintainers',
|
||||
'screenshots'
|
||||
];
|
||||
|
||||
const layers = {};
|
||||
const layord = 'conffile gitjson gitlua cmdline'.split(' ');
|
||||
|
||||
function set(name, obj) {
|
||||
if(!layord.find(x => x === name))
|
||||
throw Error('invalid config layer name');
|
||||
throw new Error('invalid config layer name');
|
||||
layers[name] = obj;
|
||||
|
||||
Object.keys(config)
|
||||
.forEach(k => delete config[k]);
|
||||
layord.forEach(k => Object.assign(config, layers[k] || {}));
|
||||
Object.assign(config, defaults);
|
||||
layord.forEach(lk => Object.assign(config, layers[lk] || {}));
|
||||
delete config._;
|
||||
arrays.filter(k => config[k] && !Array.isArray(config[k]))
|
||||
.forEach(k => {
|
||||
if((typeof config[k] === 'string' || config[k] instanceof String))
|
||||
|
@ -32,16 +82,3 @@ function set(name, obj) {
|
|||
proto.set = set;
|
||||
|
||||
set('cmdline', minimist(process.argv.slice(2)));
|
||||
|
||||
set('default', {
|
||||
conf: path.join(process.env.HOME, '.cdbrelease.json'),
|
||||
branch: 'master',
|
||||
execlua: 'lua5.1',
|
||||
cdbjsonpath: '.cdb.json',
|
||||
cdbluapath: '.cdbrelease.lua',
|
||||
root: 'https://content.minetest.net/api',
|
||||
token: null,
|
||||
user: null,
|
||||
pkg: null,
|
||||
timeout: 60,
|
||||
});
|
||||
|
|
6
index.js
6
index.js
|
@ -59,6 +59,12 @@ function missingConfig(...opts) {
|
|||
.sort();
|
||||
if(missing.length)
|
||||
throw missingConfig(...missing);
|
||||
const excess = Object.keys(config)
|
||||
.filter(k => !config.allowed[k])
|
||||
.sort();
|
||||
if(excess.length)
|
||||
throw new Error(`unsupported options: ${
|
||||
excess.map(JSON.stringify).join(', ')}`);
|
||||
|
||||
await Promise.all([
|
||||
config.edit && cdbedit(),
|
||||
|
|
Loading…
Reference in New Issue