cdbrelease/config.js
Aaron Suen 0029e9a3cf Fix broken --edit option
Also, only do screenshots if metadata editing
is enabled.
2021-02-28 08:17:48 -05:00

85 lines
1.7 KiB
JavaScript

'use strict';
const path = require('path');
const minimist = require('minimist');
const proto = {};
const config = Object.create(proto);
module.exports = config;
const defaults = {
conf: path.join(process.env.HOME, '.cdbrelease.json'),
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,
edit: false,
type: undefined,
title: 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 new Error('invalid config layer name');
layers[name] = obj;
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))
config[k] = `${config[k]}`.split(';');
else
config[k] = [config[k]];
});
return config;
}
proto.set = set;
set('cmdline', minimist(process.argv.slice(2)));