sync-task.js 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. var log = require('gulplog');
  3. var ansi = require('../../../shared/ansi');
  4. var tasks = {};
  5. function warn() {
  6. var taskKeys = Object.keys(tasks);
  7. if (!taskKeys.length) {
  8. return;
  9. }
  10. var taskNames = taskKeys.map(function(key) {
  11. return tasks[key];
  12. }).join(', ');
  13. process.exitCode = 1;
  14. log.warn(
  15. ansi.red('The following tasks did not complete:'),
  16. ansi.cyan(taskNames)
  17. );
  18. log.warn(
  19. ansi.red('Did you forget to signal async completion?')
  20. );
  21. }
  22. function start(e) {
  23. tasks[e.uid] = e.name;
  24. }
  25. function clear(e) {
  26. delete tasks[e.uid];
  27. }
  28. function clearAll() {
  29. tasks = {};
  30. }
  31. function logSyncTask(gulpInst, opts) {
  32. process.once('exit', warn);
  33. gulpInst.on('start', start);
  34. gulpInst.on('stop', clear);
  35. // When not running in --continue mode, we need to clear everything on error to avoid
  36. // false positives.
  37. gulpInst.on('error', opts.continue ? clear : clearAll);
  38. }
  39. module.exports = logSyncTask;