-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
37 lines (33 loc) · 829 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const fs = require('fs');
const pkg = require('./package');
const extend = require('extend');
const resolve = require('resolve');
const root = process.cwd();
const { CONFIG_DIR = 'config', NODE_ENV = 'development' } = process.env;
const load = name => {
var filename;
try {
filename = resolve.sync(name, {
basedir: root,
moduleDirectory: CONFIG_DIR,
extensions: ['.js', '.json', '.yaml', '.yml'],
});
} catch (e) { }
if (!filename) return {};
if (/\.ya?ml$/.test(filename)) {
const data = fs.readFileSync(filename, 'utf8')
return require('js-yaml').safeLoad(data);
}
return require(filename);
};
const config = defaults => {
return extend(true,
defaults,
pkg,
load('default'),
load(NODE_ENV),
load('local'),
);
};
module.exports = config;