synclounge/SettingsHelper.js

37 lines
943 B
JavaScript
Raw Normal View History

2018-07-20 04:31:44 +00:00
2019-04-20 08:03:44 +00:00
const args = require('args-parser')(process.argv);
const settings = require('./settings.json');
2018-07-20 12:28:08 +00:00
const defaults = {
2019-04-20 08:03:44 +00:00
webroot: '',
serverroot: '',
accessUrl: '',
autoJoin: false,
autoJoinServer: '',
autoJoinRoom: '',
autoJoinPassword: '',
};
2018-07-20 04:31:44 +00:00
module.exports = function () {
const fields = [
'webroot',
'serverroot',
'accessUrl',
'autoJoin',
'autoJoinServer',
'autoJoinRoom',
2019-04-20 08:03:44 +00:00
'autoJoinPassword',
];
2018-07-20 12:28:08 +00:00
// Load and export our settings in preference of ENV -> args
2019-04-20 08:03:44 +00:00
const output = {};
2018-07-20 04:31:44 +00:00
for (let i = 0; i < fields.length; i++) {
2019-04-20 08:03:44 +00:00
const setting = fields[i];
2018-07-20 13:02:13 +00:00
// console.log('Processing setting', setting)
// console.log(args[setting], process.env[setting], defaults[setting])
2019-04-20 08:03:44 +00:00
output[setting] = args[setting] || process.env[setting] || settings[setting] || defaults[setting];
process.env[setting] = output[setting];
2018-07-20 04:31:44 +00:00
}
2018-07-20 13:02:13 +00:00
// console.log('Our settings are', output)
2019-04-20 08:03:44 +00:00
return output;
};