index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. var util = require('util');
  3. var Orchestrator = require('orchestrator');
  4. var gutil = require('gulp-util');
  5. var deprecated = require('deprecated');
  6. var vfs = require('vinyl-fs');
  7. function Gulp() {
  8. Orchestrator.call(this);
  9. }
  10. util.inherits(Gulp, Orchestrator);
  11. Gulp.prototype.task = Gulp.prototype.add;
  12. Gulp.prototype.run = function() {
  13. // `run()` is deprecated as of 3.5 and will be removed in 4.0
  14. // Use task dependencies instead
  15. // Impose our opinion of "default" tasks onto orchestrator
  16. var tasks = arguments.length ? arguments : ['default'];
  17. this.start.apply(this, tasks);
  18. };
  19. Gulp.prototype.src = vfs.src;
  20. Gulp.prototype.dest = vfs.dest;
  21. Gulp.prototype.watch = function(glob, opt, fn) {
  22. if (typeof opt === 'function' || Array.isArray(opt)) {
  23. fn = opt;
  24. opt = null;
  25. }
  26. // Array of tasks given
  27. if (Array.isArray(fn)) {
  28. return vfs.watch(glob, opt, function() {
  29. this.start.apply(this, fn);
  30. }.bind(this));
  31. }
  32. return vfs.watch(glob, opt, fn);
  33. };
  34. // Let people use this class from our instance
  35. Gulp.prototype.Gulp = Gulp;
  36. // Deprecations
  37. deprecated.field('gulp.env has been deprecated. ' +
  38. 'Use your own CLI parser instead. ' +
  39. 'We recommend using yargs or minimist.',
  40. console.warn,
  41. Gulp.prototype,
  42. 'env',
  43. gutil.env
  44. );
  45. Gulp.prototype.run = deprecated.method('gulp.run() has been deprecated. ' +
  46. 'Use task dependencies or gulp.watch task triggering instead.',
  47. console.warn,
  48. Gulp.prototype.run
  49. );
  50. var inst = new Gulp();
  51. module.exports = inst;