demo version
This commit is contained in:
parent
fbb282a801
commit
672d6daa8e
125 changed files with 17918 additions and 1481 deletions
37
config.js
37
config.js
|
@ -1,37 +0,0 @@
|
|||
const fs = require('fs');
|
||||
const process = require('process');
|
||||
|
||||
class Config {
|
||||
constructor(location, disallow_arg_overide) {
|
||||
//possible race if deleted after check, but we live with it I guess
|
||||
|
||||
const looking = location;
|
||||
|
||||
if (typeof disallow_arg_overide === undefined || disallow_arg_overide === null || !disallow_arg_overide) {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length > 0) {
|
||||
looking = args[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(looking)) {
|
||||
const rawSettings = fs.readFileSync(looking, 'utf8');
|
||||
this.settings = JSON.parse(rawSettings);
|
||||
}
|
||||
}
|
||||
|
||||
get(config) {
|
||||
if (this.settings.hasOwnProperty(config.key)) {
|
||||
const value = this.settings[config.key];
|
||||
if (config.hasOwnProperty('transform')) {
|
||||
return config.transform(value);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} else {
|
||||
return config.default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Config;
|
Loading…
Add table
Add a link
Reference in a new issue