This commit is contained in:
2021-11-21 11:18:28 +01:00
parent 7a358eb836
commit 230b10b2a3
9339 changed files with 892519 additions and 62 deletions

View File

@@ -0,0 +1,50 @@
'use strict';
var log = require('gulplog');
var prettyTime = require('pretty-hrtime');
var ansi = require('../../../shared/ansi');
var formatError = require('../format-error');
// Wire up logging events
function logEvents(gulpInst) {
var loggedErrors = [];
gulpInst.on('start', function(evt) {
/* istanbul ignore next */
// TODO: batch these
// so when 5 tasks start at once it only logs one time with all 5
var level = evt.branch ? 'debug' : 'info';
log[level]('Starting', '\'' + ansi.cyan(evt.name) + '\'...');
});
gulpInst.on('stop', function(evt) {
var time = prettyTime(evt.duration);
/* istanbul ignore next */
var level = evt.branch ? 'debug' : 'info';
log[level](
'Finished', '\'' + ansi.cyan(evt.name) + '\'',
'after', ansi.magenta(time)
);
});
gulpInst.on('error', function(evt) {
var msg = formatError(evt);
var time = prettyTime(evt.duration);
var level = evt.branch ? 'debug' : 'error';
log[level](
'\'' + ansi.cyan(evt.name) + '\'',
ansi.red('errored after'),
ansi.magenta(time)
);
// If we haven't logged this before, log it and add to list
if (loggedErrors.indexOf(evt.error) === -1) {
log.error(msg);
loggedErrors.push(evt.error);
}
});
}
module.exports = logEvents;

View File

@@ -0,0 +1,43 @@
'use strict';
var isObject = require('isobject');
function getTask(gulpInst) {
return function(name) {
var task = gulpInst.task(name);
return {
description: getDescription(task),
flags: getFlags(task),
};
};
}
function getDescription(task) {
if (typeof task.description === 'string') {
return task.description;
}
/* istanbul ignore else */
if (typeof task.unwrap === 'function') {
var origFn = task.unwrap();
if (typeof origFn.description === 'string') {
return origFn.description;
}
}
return undefined;
}
function getFlags(task) {
if (isObject(task.flags)) {
return task.flags;
}
/* istanbul ignore else */
if (typeof task.unwrap === 'function') {
var origFn = task.unwrap();
if (isObject(origFn.flags)) {
return origFn.flags;
}
}
return undefined;
}
module.exports = getTask;

View File

@@ -0,0 +1,52 @@
'use strict';
var log = require('gulplog');
var ansi = require('../../../shared/ansi');
var tasks = {};
function warn() {
var taskKeys = Object.keys(tasks);
if (!taskKeys.length) {
return;
}
var taskNames = taskKeys.map(function(key) {
return tasks[key];
}).join(', ');
process.exitCode = 1;
log.warn(
ansi.red('The following tasks did not complete:'),
ansi.cyan(taskNames)
);
log.warn(
ansi.red('Did you forget to signal async completion?')
);
}
function start(e) {
tasks[e.uid] = e.name;
}
function clear(e) {
delete tasks[e.uid];
}
function clearAll() {
tasks = {};
}
function logSyncTask(gulpInst, opts) {
process.once('exit', warn);
gulpInst.on('start', start);
gulpInst.on('stop', clear);
// When not running in --continue mode, we need to clear everything on error to avoid
// false positives.
gulpInst.on('error', opts.continue ? clear : clearAll);
}
module.exports = logSyncTask;

View File

@@ -0,0 +1,7 @@
'use strict';
function logTasksSimple(nodes) {
console.log(nodes.join('\n').trim());
}
module.exports = logTasksSimple;