-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
env-flags.js
56 lines (45 loc) · 1.29 KB
/
env-flags.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var path = require('path');
var copyProps = require('copy-props');
var mergeCliOpts = require('./cli-flags');
var toEnvFromConfig = {
configPath: 'flags.gulpfile',
configBase: 'flags.gulpfile',
preload: 'flags.preload',
nodeFlags: 'flags.nodeFlags',
};
function overrideEnvFlags(env, config, cliOpts) {
cliOpts = mergeCliOpts(cliOpts, config);
// This must reverse because `flags.gulpfile` determines 2 different properties
var reverse = true;
env = copyProps(env, config, toEnvFromConfig, convert, reverse);
env.config = {
flags: cliOpts,
};
if (config.description) {
env.config.description = config.description;
}
return env
function convert(configInfo, envInfo) {
if (envInfo.keyChain === 'configBase') {
if (cliOpts.gulpfile === undefined) {
return path.dirname(configInfo.value);
}
return;
}
if (envInfo.keyChain === 'configPath') {
if (cliOpts.gulpfile === undefined) {
return configInfo.value;
}
return;
}
if (envInfo.keyChain === 'preload') {
return [].concat(envInfo.value, configInfo.value);
}
/* istanbul ignore else */
if (envInfo.keyChain === 'nodeFlags') {
return [].concat(configInfo.value || []);
}
}
}
module.exports = overrideEnvFlags;