events.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. var log = require('gulplog');
  3. var prettyTime = require('pretty-hrtime');
  4. var ansi = require('../../../shared/ansi');
  5. var exit = require('../../../shared/exit');
  6. var formatError = require('../format-error');
  7. // Wire up logging events
  8. function logEvents(gulpInst) {
  9. // Exit with 0 or 1
  10. var failed = false;
  11. process.once('exit', function(code) {
  12. if (code === 0 && failed) {
  13. exit(1);
  14. }
  15. });
  16. // Total hack due to poor error management in orchestrator
  17. gulpInst.on('err', function() {
  18. failed = true;
  19. });
  20. gulpInst.on('task_start', function(e) {
  21. // TODO: batch these
  22. // so when 5 tasks start at once it only logs one time with all 5
  23. log.info('Starting', '\'' + ansi.cyan(e.task) + '\'...');
  24. });
  25. gulpInst.on('task_stop', function(e) {
  26. var time = prettyTime(e.hrDuration);
  27. log.info(
  28. 'Finished', '\'' + ansi.cyan(e.task) + '\'',
  29. 'after', ansi.magenta(time)
  30. );
  31. });
  32. gulpInst.on('task_err', function(e) {
  33. var msg = formatError(e);
  34. var time = prettyTime(e.hrDuration);
  35. log.error(
  36. '\'' + ansi.cyan(e.task) + '\'',
  37. ansi.red('errored after'),
  38. ansi.magenta(time)
  39. );
  40. log.error(msg);
  41. });
  42. gulpInst.on('task_not_found', function(err) {
  43. log.error(
  44. ansi.red('Task \'' + err.task + '\' is not in your gulpfile')
  45. );
  46. log.error('Please check the documentation for proper gulpfile formatting');
  47. exit(1);
  48. });
  49. }
  50. module.exports = logEvents;