Newer
Older
import fs from 'fs';
import debug from 'debug';
import path from 'path';
import env2obj from 'env2obj';
const log = debug('helper:config:info');
const error = debug('helper:config:error');
/**
* Create a config.
* @param {String} basedir path of config file - default = PWD
* @param {prefix} prefix - of env config variables
* e.g. APP_TITLE="hi" will be config.title
*/
this.file = {};
if (fs.existsSync(path.join(basedir, 'config.js'))) {
this.file = require(path.join(basedir, 'config.js'), 'utf-8')[env];
} else {
this.fileDefault = {};
if (fs.existsSync(path.join(basedir, 'config.default.js'))) {
this.fileDefault =
require(path.join(basedir, 'config.default.js'), 'utf-8')[env]
} else {
debg('file', 'did not use ', path.join(basedir, 'config.default.js'))
this.config = _.merge(this.fileDefault, this.file, this.env);
const config = new Config();
exports.default = config.config;