synclounge/SettingsHelper.js

34 lines
874 B
JavaScript
Raw Normal View History

2018-07-20 04:31:44 +00:00
const args = require('args-parser')(process.argv)
2018-07-20 12:28:08 +00:00
const defaults = {
'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',
'autoJoinPassword'
]
2018-07-20 12:28:08 +00:00
// Load and export our settings in preference of ENV -> args
2018-07-20 04:31:44 +00:00
let output = {}
for (let i = 0; i < fields.length; i++) {
let 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])
2018-07-20 12:28:08 +00:00
output[setting] = args[setting] || process.env[setting] || defaults[setting]
2018-07-20 12:39:36 +00:00
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)
2018-07-20 04:31:44 +00:00
return output
}