Add support for a .js config file
parent
9b9d5d313f
commit
2cecbc3e46
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v2.16.0
|
||||||
|
* Add support for a .js config file (export config with `module.exports`)
|
||||||
|
|
||||||
## v2.15.2
|
## v2.15.2
|
||||||
* Update several other packages as well
|
* Update several other packages as well
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ const configFiles = [
|
||||||
'config.json',
|
'config.json',
|
||||||
'config.json5',
|
'config.json5',
|
||||||
'config.json.json',
|
'config.json.json',
|
||||||
'config.json.txt'
|
'config.json.txt',
|
||||||
|
'config.js'
|
||||||
];
|
];
|
||||||
|
|
||||||
let foundConfigFile;
|
let foundConfigFile;
|
||||||
|
@ -28,8 +29,12 @@ if (! foundConfigFile) {
|
||||||
|
|
||||||
// Parse the config using JSON5
|
// Parse the config using JSON5
|
||||||
try {
|
try {
|
||||||
|
if (foundConfigFile.endsWith('.js')) {
|
||||||
|
userConfig = require(`../${foundConfigFile}`);
|
||||||
|
} else {
|
||||||
const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile);
|
const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile);
|
||||||
userConfig = json5.parse(raw);
|
userConfig = json5.parse(raw);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Error reading config file! The error given was: ${e.message}`);
|
throw new Error(`Error reading config file! The error given was: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue