Add support for a .js config file

master
Dragory 2018-08-08 01:32:22 +03:00
parent 9b9d5d313f
commit 2cecbc3e46
2 changed files with 11 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## v2.16.0
* Add support for a .js config file (export config with `module.exports`)
## v2.15.2
* Update several other packages as well

View File

@ -9,7 +9,8 @@ const configFiles = [
'config.json',
'config.json5',
'config.json.json',
'config.json.txt'
'config.json.txt',
'config.js'
];
let foundConfigFile;
@ -28,8 +29,12 @@ if (! foundConfigFile) {
// Parse the config using JSON5
try {
if (foundConfigFile.endsWith('.js')) {
userConfig = require(`../${foundConfigFile}`);
} else {
const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile);
userConfig = json5.parse(raw);
}
} catch (e) {
throw new Error(`Error reading config file! The error given was: ${e.message}`);
}