-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
env-config.js
179 lines (138 loc) · 4.84 KB
/
env-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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
var path = require('path');
var chalk = require('chalk');
var copyProps = require('copy-props');
var mergeCliOpts = require('./cli-flags');
var messages = require("../../../messages");
var toEnvFromConfig = {
configPath: 'flags.gulpfile',
configBase: 'flags.gulpfile',
preload: 'flags.preload',
nodeFlags: 'flags.nodeFlags',
};
function overrideEnvConfig(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,
};
env.config.flags.getMessage = function(msg, data) {
if (msg === messages.PRELOAD_BEFORE) {
return 'Preloading external module: ' + chalk.magenta(data);
}
if (msg === messages.PRELOAD_SUCCESS) {
return 'Preloaded external module: ' + chalk.magenta(data)
}
if (msg === messages.PRELOAD_FAILURE) {
return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data);
}
if (msg === messages.PRELOAD_ERROR) {
return chalk.yellow(data.toString());
}
if (msg === messages.LOADER_SUCCESS) {
return 'Loaded external module: ' + chalk.magenta(data);
}
if (msg === messages.LOADER_FAILURE) {
return chalk.yellow('Failed to load external module: ') + chalk.magenta(data);
}
if (msg === messages.LOADER_ERROR) {
return chalk.yellow(data.toString());
}
if (msg === messages.NODE_FLAGS) {
var nodeFlags = chalk.magenta(data.join(', '));
return 'Node flags detected: ' + nodeFlags;
}
if (msg === messages.RESPAWNED) {
var pid = chalk.magenta(data);
return 'Respawned to PID: ' + pid;
}
if (msg === messages.GULPFILE_NOT_FOUND) {
return chalk.red('No gulpfile found');
}
if (msg === messages.CWD_CHANGED) {
return 'Working directory changed to ' + chalk.magenta(data);
}
if (msg === messages.UNSUPPORTED_GULP_VERSION) {
return chalk.red('Unsupported gulp version', data)
}
if (msg === messages.DESCRIPTION) {
return 'Tasks for ' + chalk.magenta(data);
}
if (msg === messages.GULPFILE) {
return 'Using gulpfile ' + chalk.magenta(data);
}
if (msg === messages.TASK_START) {
return "Starting '" + chalk.cyan(data.task) + "'..."
}
if (msg === messages.TASK_STOP) {
return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration);
}
if (msg === messages.TASK_ERROR) {
return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration);
}
if (msg === messages.TASK_MISSING) {
return chalk.red('Task \'' + data.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting';
}
if (msg === messages.SYNC_TASK) {
return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?');
}
if (msg === messages.MISSING_NODE_MODULES) {
return chalk.red('Local modules not found in') + ' ' + chalk.magenta(data);
}
if (msg === messages.MISSING_GULP) {
return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(data);
}
if (msg === messages.YARN_INSTALL) {
return chalk.red('Try running: yarn install');
}
if (msg === messages.NPM_INSTALL) {
return chalk.red('Try running: npm install');
}
if (msg === messages.YARN_INSTALL_GULP) {
return chalk.red('Try running: yarn add gulp');
}
if (msg === messages.NPM_INSTALL_GULP) {
return chalk.red('Try running: npm install gulp');
}
if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) {
return chalk.white('└');
}
if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT) {
return chalk.white('├');
}
if (msg === messages.BOX_DRAWINGS_LIGHT_HORIZONTAL) {
return chalk.white('─');
}
if (msg === messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL) {
return chalk.white('┬');
}
if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL) {
return chalk.white('│');
}
};
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 = overrideEnvConfig;