Switch config parser to JSON5. Accept multiple config file names.
parent
685ccdd226
commit
cd96c70f1c
|
@ -2,5 +2,8 @@
|
||||||
/.idea
|
/.idea
|
||||||
/node_modules
|
/node_modules
|
||||||
/config.json
|
/config.json
|
||||||
|
/config.json5
|
||||||
|
/config.json.json
|
||||||
|
/config.json.txt
|
||||||
/welcome.png
|
/welcome.png
|
||||||
/update.sh
|
/update.sh
|
||||||
|
|
|
@ -1279,6 +1279,21 @@
|
||||||
"jsonify": "0.0.0"
|
"jsonify": "0.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"json5": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
|
||||||
|
"requires": {
|
||||||
|
"minimist": "1.2.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"minimist": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"jsonify": {
|
"jsonify": {
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"eris": "^0.8.4",
|
"eris": "^0.8.4",
|
||||||
"humanize-duration": "^3.12.1",
|
"humanize-duration": "^3.12.1",
|
||||||
|
"json5": "^1.0.1",
|
||||||
"knex": "^0.14.2",
|
"knex": "^0.14.2",
|
||||||
"mime": "^1.3.4",
|
"mime": "^1.3.4",
|
||||||
"moment": "^2.21.0",
|
"moment": "^2.21.0",
|
||||||
|
|
|
@ -1,11 +1,37 @@
|
||||||
|
const json5 = require('json5');
|
||||||
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
let userConfig;
|
let userConfig;
|
||||||
|
|
||||||
|
// Try to find our config file from several options
|
||||||
|
const configFiles = [
|
||||||
|
'config.json',
|
||||||
|
'config.json5',
|
||||||
|
'config.json.json',
|
||||||
|
'config.json.txt'
|
||||||
|
];
|
||||||
|
|
||||||
|
let foundConfigFile;
|
||||||
|
|
||||||
|
for (const configFile of configFiles) {
|
||||||
try {
|
try {
|
||||||
userConfig = require('../config');
|
fs.accessSync(__dirname + '/../' + configFile);
|
||||||
|
foundConfigFile = configFile;
|
||||||
|
break;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! foundConfigFile) {
|
||||||
|
throw new Error(`Could not find config.json!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the config using JSON5
|
||||||
|
try {
|
||||||
|
const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile);
|
||||||
|
userConfig = json5.parse(raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Config file could not be found or read! The error given was: ${e.message}`);
|
throw new Error(`Error reading config file! The error given was: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
|
|
Loading…
Reference in New Issue