Add support for a .js config file
parent
9b9d5d313f
commit
2cecbc3e46
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile);
|
||||
userConfig = json5.parse(raw);
|
||||
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}`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue