Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (51 loc) · 1.72 KB
/
Copy pathindex.js
File metadata and controls
63 lines (51 loc) · 1.72 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const path = require('path'),
_ = require('lodash');
module.exports = function (config) {
let args = process.argv.slice(_.findIndex(process.argv, a => path.resolve(__dirname, a) === __filename) + 1);
global.args = {};
for (let arg of args) {
if (arg.indexOf('=') !== -1) {
let parts = arg.split('=');
let key = parts[0];
key = _.camelCase(key);
let value = parts[1];
if (value && (value[0]==='[' || value[0] === '{')){
try {
//value = value.replace(/'/g, '"');
value = JSON.parse(value);
} catch(exp){
console.error('bad json');
}
}
if (!isNaN(value)){
value = +value;
}
if (value === 'false' || value === 'true'){
value = (value !== 'false');
}
_.set(config, key, value);
} else {
global.args[arg] = true;
}
}
_.each(process.env, function(value, key){
key = _.camelCase(key);
if (config.hasOwnProperty(key)){
if (value && (value[0] === '{' || value[0] === '[')){
try {
value = JSON.parse(value);
} catch(exp){
console.log('error parsing config: ' + key + ', value: ' + value);
}
config[key] = value;
} else if (value === 'false' || value === 'true'){
config[key] = value === 'true';
} else {
if (!isNaN(value)){
value = +value;
}
config[key] = value;
}
}
});
}