• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gulpjs / gulp-cli / 15379317059

01 Jun 2025 08:53PM UTC coverage: 97.865%. Remained the same
15379317059

push

github

web-flow
chore: release 3.1.0 (#273)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

314 of 335 branches covered (93.73%)

596 of 609 relevant lines covered (97.87%)

122.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.09
/lib/shared/translate.js
1
'use strict';
2

3
var util = require('util');
158✔
4

5
var chalk = require('chalk');
158✔
6
var messages = require('@gulpjs/messages');
158✔
7

8
var tildify = require('./tildify');
158✔
9
var formatTime = require('./log/format-hrtime');
158✔
10

11
function Timestamp() {
12
  this.now = new Date();
468✔
13
}
14

15
Timestamp.prototype[util.inspect.custom] = function (depth, opts) {
158✔
16
  var timestamp = this.now.toLocaleTimeString('en', { hour12: false });
468✔
17
  return '[' + opts.stylize(timestamp, 'date') + ']';
468✔
18
};
19

20
function getDefaultMessage(data) {
21
  switch (data.tag) {
2,185!
22
    case messages.PRELOAD_BEFORE: {
23
      return 'Preloading external module: ' + chalk.magenta(data.name);
14✔
24
    }
25
    case messages.PRELOAD_SUCCESS: {
26
      return 'Preloaded external module: ' + chalk.magenta(data.name)
10✔
27
    }
28
    case messages.PRELOAD_FAILURE: {
29
      return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data.name);
5✔
30
    }
31
    case messages.PRELOAD_ERROR: {
32
      return chalk.yellow(data.error.toString());
5✔
33
    }
34
    case messages.LOADER_SUCCESS: {
35
      return 'Loaded external module: ' + chalk.magenta(data.name);
2✔
36
    }
37
    case messages.LOADER_FAILURE: {
38
      return chalk.yellow('Failed to load external module: ') + chalk.magenta(data.name);
1✔
39
    }
40
    case messages.LOADER_ERROR: {
41
      return chalk.yellow(data.error.toString());
1✔
42
    }
43
    case messages.NODE_FLAGS: {
44
      var nodeFlags = chalk.magenta(data.flags.join(', '));
8✔
45
      return 'Node flags detected: ' + nodeFlags;
8✔
46
    }
47
    case messages.RESPAWNED: {
48
      var pid = chalk.magenta(data.pid);
8✔
49
      return 'Respawned to PID: ' + pid;
8✔
50
    }
51
    case messages.MISSING_GULPFILE: {
52
      return chalk.red('No gulpfile found');
4✔
53
    }
54
    case messages.CWD_CHANGED: {
55
      return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd));
45✔
56
    }
57
    case messages.UNSUPPORTED_GULP_VERSION: {
58
      return chalk.red('Unsupported gulp version', data.version)
1✔
59
    }
60
    case messages.DESCRIPTION: {
61
      return 'Tasks for ' + chalk.magenta(tildify(data.path));
11✔
62
    }
63
    case messages.GULPFILE: {
64
      return 'Using gulpfile ' + chalk.magenta(tildify(data.path));
55✔
65
    }
66
    case messages.TASK_START: {
67
      return "Starting '" + chalk.cyan(data.task) + "'..."
115✔
68
    }
69
    case messages.TASK_STOP: {
70
      return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(formatTime(data.duration));
86✔
71
    }
72
    case messages.TASK_FAILURE: {
73
      return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' + chalk.magenta(formatTime(data.duration));
20✔
74
    }
75
    case messages.TASK_MISSING: {
76
      if (data.similar) {
2✔
77
        return chalk.red('Task never defined: ' + data.task + ' - did you mean? ' + data.similar.join(', '))
1✔
78
          + '\nTo list available tasks, try running: gulp --tasks';
79
      } else {
80
        return chalk.red('Task never defined: ' + data.task) +
1✔
81
          '\nTo list available tasks, try running: gulp --tasks';
82
      }
83
    }
84
    case messages.TASK_SYNC: {
85
      return chalk.red('The following tasks did not complete: ') + chalk.cyan(data.tasks) + "\n"
3✔
86
        + chalk.red('Did you forget to signal async completion?');
87
    }
88
    case messages.MISSING_NODE_MODULES: {
89
      return chalk.red('Local modules not found in') + ' ' + chalk.magenta(tildify(data.cwd));
2✔
90
    }
91
    case messages.MISSING_GULP: {
92
      return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd));
2✔
93
    }
94
    case messages.YARN_INSTALL: {
95
      return chalk.red('Try running: yarn install');
1✔
96
    }
97
    case messages.NPM_INSTALL: {
98
      return chalk.red('Try running: npm install');
1✔
99
    }
100
    case messages.YARN_INSTALL_GULP: {
101
      return chalk.red('Try running: yarn add gulp');
1✔
102
    }
103
    case messages.NPM_INSTALL_GULP: {
104
      return chalk.red('Try running: npm install gulp');
1✔
105
    }
106
    case messages.GULPLOG_DEPRECATED: {
107
      return chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!");
×
108
    }
109
    case messages.COMPLETION_TYPE_MISSING: {
110
      return 'Missing completion type';
1✔
111
    }
112
    case messages.COMPLETION_TYPE_UNKNOWN: {
113
      return 'echo "gulp autocompletion rules for' + " '" + data.name + "' " + 'not found"'
1✔
114
    }
115
    case messages.ARGV_ERROR: {
116
      return data.message;
1✔
117
    }
118
    case messages.EXEC_ERROR: {
119
      return data.message;
×
120
    }
121
    case messages.TASK_ERROR: {
122
      return data.message;
10✔
123
    }
124
    case messages.USAGE: {
125
      return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks';
5✔
126
    }
127
    case messages.FLAG_HELP: {
128
      return chalk.gray('Show this help.');
6✔
129
    }
130
    case messages.FLAG_VERSION: {
131
      return chalk.gray('Print the global and local gulp versions.');
6✔
132
    }
133
    case messages.FLAG_PRELOAD: {
134
      return chalk.gray(
6✔
135
        'Will preload a module before running the gulpfile. ' +
136
        'This is useful for transpilers but also has other applications.'
137
      );
138
    }
139
    case messages.FLAG_GULPFILE: {
140
      return chalk.gray(
6✔
141
        'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' +
142
        'This will set the CWD to the gulpfile directory as well.'
143
      )
144
    }
145
    case messages.FLAG_CWD: {
146
      return chalk.gray(
6✔
147
        'Manually set the CWD. The search for the gulpfile, ' +
148
        'as well as the relativity of all requires will be from here.'
149
      );
150
    }
151
    case messages.FLAG_TASKS: {
152
      return chalk.gray('Print the task dependency tree for the loaded gulpfile.');
6✔
153
    }
154
    case messages.FLAG_TASKS_SIMPLE: {
155
      return chalk.gray('Print a plaintext list of tasks for the loaded gulpfile.');
6✔
156
    }
157
    case messages.FLAG_TASKS_JSON: {
158
      return chalk.gray(
6✔
159
        'Print the task dependency tree, ' +
160
        'in JSON format, for the loaded gulpfile.'
161
      );
162
    }
163
    case messages.FLAG_TASKS_DEPTH: {
164
      return chalk.gray('Specify the depth of the task dependency tree.');
6✔
165
    }
166
    case messages.FLAG_COMPACT_TASKS: {
167
      return chalk.gray(
6✔
168
        'Reduce the output of task dependency tree by printing ' +
169
        'only top tasks and their child tasks.'
170
      );
171
    }
172
    case messages.FLAG_SORT_TASKS: {
173
      return chalk.gray('Will sort top tasks of task dependency tree.');
6✔
174
    }
175
    case messages.FLAG_COLOR: {
176
      return chalk.gray(
6✔
177
        'Will force gulp and gulp plugins to display colors, ' +
178
        'even when no color support is detected.'
179
      );
180
    }
181
    case messages.FLAG_NO_COLOR: {
182
      return chalk.gray(
6✔
183
        'Will force gulp and gulp plugins to not display colors, ' +
184
        'even when color support is detected.'
185
      );
186
    }
187
    case messages.FLAG_SILENT: {
188
      return chalk.gray('Suppress all gulp logging.');
6✔
189
    }
190
    case messages.FLAG_CONTINUE: {
191
      return chalk.gray('Continue execution of tasks upon failure.');
6✔
192
    }
193
    case messages.FLAG_SERIES: {
194
      return chalk.gray('Run tasks given on the CLI in series (the default is parallel).');
6✔
195
    }
196
    case messages.FLAG_LOG_LEVEL: {
197
      return chalk.gray(
6✔
198
        'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' +
199
        '-LLL is default.'
200
      );
201
    }
202
    case messages.TASK_NAME: {
203
      return chalk.cyan(data.name);
389✔
204
    }
205
    case messages.TASK_DESCRIPTION: {
206
      return chalk.white(data.description);
10✔
207
    }
208
    case messages.TASK_FLAG: {
209
      return chalk.magenta(data.flag);
7✔
210
    }
211
    case messages.TASK_FLAG_DESCRIPTION: {
212
      return chalk.white('…' + data.description);
6✔
213
    }
214
    case messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: {
215
      return chalk.white('└');
228✔
216
    }
217
    case messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: {
218
      return chalk.white('├');
161✔
219
    }
220
    case messages.BOX_DRAWINGS_LIGHT_HORIZONTAL: {
221
      return chalk.white('─');
574✔
222
    }
223
    case messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL: {
224
      return chalk.white('┬');
204✔
225
    }
226
    case messages.BOX_DRAWINGS_LIGHT_VERTICAL: {
227
      return chalk.white('│');
69✔
228
    }
229
    default: {
230
      return data;
13✔
231
    }
232
  }
233
}
234

235
function getDefaultTimestamp() {
236
  return util.inspect(new Timestamp(), { colors: !!chalk.supportsColor });
468✔
237
}
238

239
function buildTranslations(cfg) {
240
  cfg = cfg || {};
309✔
241

242
  return {
309✔
243
    message: function (data) {
244
      // Don't allow an `undefined` message through
245
      if (typeof data === 'undefined') {
2,292!
246
        data = Object.create(null);
×
247
      }
248

249
      var message;
250
      if (typeof cfg.message === 'function') {
2,292✔
251
        try {
1,212✔
252
          message = cfg.message(data);
1,212✔
253
        } catch (err) {
254
          console.error('A problem occurred with the user-defined `message()` function.');
×
255
          console.error('Please correct your `.gulp.*` config file.');
×
256
        }
257
      }
258

259
      // If the user has provided a message, return it
260
      if (message) {
2,292✔
261
        return message;
59✔
262
      }
263

264
      // Users can filter messages by explicitly returning `false`
265
      if (message === false) {
2,233✔
266
        return '';
48✔
267
      }
268

269
      // If the user hasn't returned a message or silenced it with `false`
270
      // get the default message. Will return the first argument if the message
271
      // is not defined in the `@gulpjs/messages` package
272
      return getDefaultMessage(data);
2,185✔
273
    },
274
    timestamp: function (data) {
275
      // Don't allow an `undefined` message through
276
      if (typeof data === 'undefined') {
483!
277
        data = Object.create(null);
×
278
      }
279

280
      var time;
281
      if (typeof cfg.timestamp === 'function') {
483✔
282
        try {
15✔
283
          time = cfg.timestamp(data);
15✔
284
        } catch (err) {
285
          console.error('A problem occurred with the user-defined `timestamp()` function.');
×
286
          console.error('Please correct your `.gulp.*` config file.');
×
287
        }
288
      }
289

290
      // If the user has provided a timestamp, return it
291
      if (time) {
483!
292
        return time;
×
293
      }
294

295
      // Users can filter timestamps by explicitly returning `false`
296
      if (time === false) {
483✔
297
        return '';
15✔
298
      }
299

300
      return getDefaultTimestamp();
468✔
301
    }
302
  }
303
}
304

305
module.exports = buildTranslations;
158✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc