UNPKG

747 BJavaScriptView Raw
1const _ = require('lodash');
2const { configFileName } = require('../consts');
3const config = require('../default.config.json');
4
5class Config {
6 constructor() {
7 this.config = config;
8 this.merge();
9 }
10
11 get all() {
12 return this.config;
13 }
14
15 get(path, defaultValue) {
16 return _.get(this.config, path, defaultValue);
17 }
18
19 set(path, value) {
20 _.set(this.config, path, value);
21 }
22
23 merge() {
24 try {
25 const userConfig = require(`${process.cwd()}/${configFileName}`); // eslint-disable-line
26 this.config = { ...config, ...userConfig };
27 } catch (e) {
28 this.config = {
29 ...this.config,
30 ...this.config.default,
31 };
32 }
33 }
34}
35
36const configure = new Config();
37
38module.exports = configure;