Loading configs asynchronously now as well as with better error logging for the user
This commit is contained in:
@@ -6,22 +6,29 @@ const fs = require('fs')
|
||||
* @returns {Config} { path }
|
||||
*/
|
||||
function get_config(parser) {
|
||||
|
||||
const a = parser.parse_args()
|
||||
const defaultcfg = `${process.env.HOME || process.env.USERPROFILE}/.config/freechat/config.json`
|
||||
|
||||
// we'll just assume that the config is there as per the installation process
|
||||
const path = (a['config']) ? a['config'] : defaultcfg
|
||||
const file_contents = fs.readFileSync(path)
|
||||
const file_json = JSON.parse(file_contents)
|
||||
let ret = { path: path }
|
||||
|
||||
fs.readFile(path, (err, data) => {
|
||||
if(err) {
|
||||
console.log('No valid config found')
|
||||
process.exit()
|
||||
}
|
||||
const file_json = JSON.parse(data)
|
||||
for(const key of Object.keys(file_json)) {
|
||||
if(key == 'path') { continue } // don't overwrite the old path
|
||||
else {
|
||||
ret[key] = file_json[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// now we'll just blindly construct the config object from here on out
|
||||
let ret = { path: path }
|
||||
for(const key of Object.keys(file_json)) {
|
||||
if(key == 'path') { continue } // don't overwrite the old path
|
||||
else {
|
||||
ret[key] = file_json[key]
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user