-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
translate.js
305 lines (287 loc) · 9.62 KB
/
translate.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
'use strict';
var util = require('util');
var chalk = require('chalk');
var messages = require('@gulpjs/messages');
var tildify = require('./tildify');
var formatTime = require('./log/format-hrtime');
function Timestamp() {
this.now = new Date();
}
Timestamp.prototype[util.inspect.custom] = function (depth, opts) {
var timestamp = this.now.toLocaleTimeString('en', { hour12: false });
return '[' + opts.stylize(timestamp, 'date') + ']';
};
function getDefaultMessage(data) {
switch (data.tag) {
case messages.PRELOAD_BEFORE: {
return 'Preloading external module: ' + chalk.magenta(data.name);
}
case messages.PRELOAD_SUCCESS: {
return 'Preloaded external module: ' + chalk.magenta(data.name)
}
case messages.PRELOAD_FAILURE: {
return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data.name);
}
case messages.PRELOAD_ERROR: {
return chalk.yellow(data.error.toString());
}
case messages.LOADER_SUCCESS: {
return 'Loaded external module: ' + chalk.magenta(data.name);
}
case messages.LOADER_FAILURE: {
return chalk.yellow('Failed to load external module: ') + chalk.magenta(data.name);
}
case messages.LOADER_ERROR: {
return chalk.yellow(data.error.toString());
}
case messages.NODE_FLAGS: {
var nodeFlags = chalk.magenta(data.flags.join(', '));
return 'Node flags detected: ' + nodeFlags;
}
case messages.RESPAWNED: {
var pid = chalk.magenta(data.pid);
return 'Respawned to PID: ' + pid;
}
case messages.MISSING_GULPFILE: {
return chalk.red('No gulpfile found');
}
case messages.CWD_CHANGED: {
return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd));
}
case messages.UNSUPPORTED_GULP_VERSION: {
return chalk.red('Unsupported gulp version', data.version)
}
case messages.DESCRIPTION: {
return 'Tasks for ' + chalk.magenta(tildify(data.path));
}
case messages.GULPFILE: {
return 'Using gulpfile ' + chalk.magenta(tildify(data.path));
}
case messages.TASK_START: {
return "Starting '" + chalk.cyan(data.task) + "'..."
}
case messages.TASK_STOP: {
return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(formatTime(data.duration));
}
case messages.TASK_FAILURE: {
return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' + chalk.magenta(formatTime(data.duration));
}
case messages.TASK_MISSING: {
if (data.similar) {
return chalk.red('Task never defined: ' + data.task + ' - did you mean? ' + data.similar.join(', '))
+ '\nTo list available tasks, try running: gulp --tasks';
} else {
return chalk.red('Task never defined: ' + data.task) +
'\nTo list available tasks, try running: gulp --tasks';
}
}
case messages.TASK_SYNC: {
return chalk.red('The following tasks did not complete: ') + chalk.cyan(data.tasks) + "\n"
+ chalk.red('Did you forget to signal async completion?');
}
case messages.MISSING_NODE_MODULES: {
return chalk.red('Local modules not found in') + ' ' + chalk.magenta(tildify(data.cwd));
}
case messages.MISSING_GULP: {
return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd));
}
case messages.YARN_INSTALL: {
return chalk.red('Try running: yarn install');
}
case messages.NPM_INSTALL: {
return chalk.red('Try running: npm install');
}
case messages.YARN_INSTALL_GULP: {
return chalk.red('Try running: yarn add gulp');
}
case messages.NPM_INSTALL_GULP: {
return chalk.red('Try running: npm install gulp');
}
case messages.GULPLOG_DEPRECATED: {
return chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!");
}
case messages.COMPLETION_TYPE_MISSING: {
return 'Missing completion type';
}
case messages.COMPLETION_TYPE_UNKNOWN: {
return 'echo "gulp autocompletion rules for' + " '" + data.name + "' " + 'not found"'
}
case messages.ARGV_ERROR: {
return data.message;
}
case messages.EXEC_ERROR: {
return data.message;
}
case messages.TASK_ERROR: {
return data.message;
}
case messages.USAGE: {
return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks';
}
case messages.FLAG_HELP: {
return chalk.gray('Show this help.');
}
case messages.FLAG_VERSION: {
return chalk.gray('Print the global and local gulp versions.');
}
case messages.FLAG_PRELOAD: {
return chalk.gray(
'Will preload a module before running the gulpfile. ' +
'This is useful for transpilers but also has other applications.'
);
}
case messages.FLAG_GULPFILE: {
return chalk.gray(
'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' +
'This will set the CWD to the gulpfile directory as well.'
)
}
case messages.FLAG_CWD: {
return chalk.gray(
'Manually set the CWD. The search for the gulpfile, ' +
'as well as the relativity of all requires will be from here.'
);
}
case messages.FLAG_TASKS: {
return chalk.gray('Print the task dependency tree for the loaded gulpfile.');
}
case messages.FLAG_TASKS_SIMPLE: {
return chalk.gray('Print a plaintext list of tasks for the loaded gulpfile.');
}
case messages.FLAG_TASKS_JSON: {
return chalk.gray(
'Print the task dependency tree, ' +
'in JSON format, for the loaded gulpfile.'
);
}
case messages.FLAG_TASKS_DEPTH: {
return chalk.gray('Specify the depth of the task dependency tree.');
}
case messages.FLAG_COMPACT_TASKS: {
return chalk.gray(
'Reduce the output of task dependency tree by printing ' +
'only top tasks and their child tasks.'
);
}
case messages.FLAG_SORT_TASKS: {
return chalk.gray('Will sort top tasks of task dependency tree.');
}
case messages.FLAG_COLOR: {
return chalk.gray(
'Will force gulp and gulp plugins to display colors, ' +
'even when no color support is detected.'
);
}
case messages.FLAG_NO_COLOR: {
return chalk.gray(
'Will force gulp and gulp plugins to not display colors, ' +
'even when color support is detected.'
);
}
case messages.FLAG_SILENT: {
return chalk.gray('Suppress all gulp logging.');
}
case messages.FLAG_CONTINUE: {
return chalk.gray('Continue execution of tasks upon failure.');
}
case messages.FLAG_SERIES: {
return chalk.gray('Run tasks given on the CLI in series (the default is parallel).');
}
case messages.FLAG_LOG_LEVEL: {
return chalk.gray(
'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' +
'-LLL is default.'
);
}
case messages.TASK_NAME: {
return chalk.cyan(data.name);
}
case messages.TASK_DESCRIPTION: {
return chalk.white(data.description);
}
case messages.TASK_FLAG: {
return chalk.magenta(data.flag);
}
case messages.TASK_FLAG_DESCRIPTION: {
return chalk.white('…' + data.description);
}
case messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: {
return chalk.white('└');
}
case messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: {
return chalk.white('├');
}
case messages.BOX_DRAWINGS_LIGHT_HORIZONTAL: {
return chalk.white('─');
}
case messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL: {
return chalk.white('┬');
}
case messages.BOX_DRAWINGS_LIGHT_VERTICAL: {
return chalk.white('│');
}
default: {
return data;
}
}
}
function getDefaultTimestamp() {
return util.inspect(new Timestamp(), { colors: !!chalk.supportsColor });
}
function buildTranslations(cfg) {
cfg = cfg || {};
return {
message: function (data) {
// Don't allow an `undefined` message through
if (typeof data === 'undefined') {
data = Object.create(null);
}
var message;
if (typeof cfg.message === 'function') {
try {
message = cfg.message(data);
} catch (err) {
console.error('A problem occurred with the user-defined `message()` function.');
console.error('Please correct your `.gulp.*` config file.');
}
}
// If the user has provided a message, return it
if (message) {
return message;
}
// Users can filter messages by explicitly returning `false`
if (message === false) {
return '';
}
// If the user hasn't returned a message or silenced it with `false`
// get the default message. Will return the first argument if the message
// is not defined in the `@gulpjs/messages` package
return getDefaultMessage(data);
},
timestamp: function (data) {
// Don't allow an `undefined` message through
if (typeof data === 'undefined') {
data = Object.create(null);
}
var time;
if (typeof cfg.timestamp === 'function') {
try {
time = cfg.timestamp(data);
} catch (err) {
console.error('A problem occurred with the user-defined `timestamp()` function.');
console.error('Please correct your `.gulp.*` config file.');
}
}
// If the user has provided a timestamp, return it
if (time) {
return time;
}
// Users can filter timestamps by explicitly returning `false`
if (time === false) {
return '';
}
return getDefaultTimestamp();
}
}
}
module.exports = buildTranslations;