synclounge/config/index.js

48 lines
1019 B
JavaScript
Raw Normal View History

const nconf = require('nconf');
2020-07-21 21:28:48 +00:00
const fs = require('fs');
const defaults = require('./defaults');
2020-07-21 21:28:48 +00:00
// Parses, saves, and returns the config
const saveConfig = (file) => {
nconf
.argv({
separator: '__',
parseValues: true,
})
.env({
separator: '__',
lowerCase: true,
parseValues: true,
whitelist: Object.keys(defaults).concat([
'autojoin__server',
'autojoin__room',
'autojoin__password',
'authentication__mechanism',
'authentication__type',
'authentication__authorized',
'custom_server__name',
'custom_server__location',
'custom_server__url',
'custom_server__image',
'default_slplayer_quality',
]),
})
.file({ file });
nconf.defaults(defaults);
// Filter out the weird stuff
const {
type, $0: firstArg, _: command, modern, ...config
} = nconf.get();
fs.writeFileSync(file, JSON.stringify(config));
return config;
};
module.exports = saveConfig;