cdbrelease/config.js
2021-02-27 18:25:03 -05:00

48 lines
1.1 KiB
JavaScript

'use strict';
const path = require('path');
const minimist = require('minimist');
const proto = {};
const config = Object.create(proto);
module.exports = config;
const layers = {};
const layord = 'default conffile gitjson gitlua cmdline'.split(' ');
const arrays = ['screenshots', 'tags', 'content_warnings'];
function set(name, obj) {
if(!layord.find(x => x === name))
throw Error('invalid config layer name');
layers[name] = obj;
Object.keys(config)
.forEach(k => delete config[k]);
layord.forEach(k => Object.assign(config, layers[k] || {}));
arrays.filter(k => config[k] && !Array.isArray(config[k]))
.forEach(k => {
if((typeof config[k] === 'string' || config[k] instanceof String))
config[k] = `${config[k]}`.split(';');
else
config[k] = [config[k]];
});
return config;
}
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,
});