/
index.js
40 lines (33 loc) · 862 Bytes
/
index.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
38
39
40
/**
* Merge config main.ini + env.ini into js-array
*/
var ini = require('ini'),
fs = require('fs'),
merge = require('merge');
var config = merge.recursive(
parseConfig('main'),
parseConfig('env')
);
/**
* Parse /config/name.ini
*
* @param {string} name Filename
* @returns {array} Parameters
*/
function parseConfig(name) {
name = process.cwd() + '/config/' + name + '.ini';
return ini.parse(fs.readFileSync(name, 'utf-8'));
}
/**
* Apply one section of the config on itself
* For instance, apply test section for test environment
*
* @param {string} section Section of ini-config
*/
config.apply = function(section) {
if (this[section] === undefined) {
throw new Error('Section "' + section + '" not found in config');
}
merge.recursive(this, this[section]);
};
module.exports = config;