index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. const path = require('path');
  3. const fancyLog = require('fancy-log');
  4. const through = require('through2');
  5. const tildify = require('tildify');
  6. const stringifyObject = require('stringify-object');
  7. const chalk = require('chalk');
  8. const plur = require('plur');
  9. const prop = chalk.blue;
  10. module.exports = options => {
  11. options = Object.assign({
  12. logger: fancyLog,
  13. title: 'gulp-debug:',
  14. minimal: true,
  15. showFiles: true,
  16. showCount: true
  17. }, options);
  18. if (process.argv.includes('--verbose')) {
  19. options.verbose = true;
  20. options.minimal = false;
  21. options.showFiles = true;
  22. options.showCount = true;
  23. }
  24. let count = 0;
  25. return through.obj((file, enc, cb) => {
  26. if (options.showFiles) {
  27. const full =
  28. '\n' +
  29. (file.cwd ? 'cwd: ' + prop(tildify(file.cwd)) : '') +
  30. (file.base ? '\nbase: ' + prop(tildify(file.base)) : '') +
  31. (file.path ? '\npath: ' + prop(tildify(file.path)) : '') +
  32. (file.stat && options.verbose ? '\nstat: ' + prop(stringifyObject(file.stat, {indent: ' '}).replace(/[{}]/g, '').trim()) : '') +
  33. '\n';
  34. const output = options.minimal ? prop(path.relative(process.cwd(), file.path)) : full;
  35. options.logger(options.title + ' ' + output);
  36. }
  37. count++;
  38. cb(null, file);
  39. }, cb => {
  40. if (options.showCount) {
  41. options.logger(options.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
  42. }
  43. cb();
  44. });
  45. };