index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var util = require('util');
  3. var Undertaker = require('undertaker');
  4. var vfs = require('vinyl-fs');
  5. var watch = require('glob-watcher');
  6. function Gulp() {
  7. Undertaker.call(this);
  8. // Bind the functions for destructuring
  9. this.watch = this.watch.bind(this);
  10. this.task = this.task.bind(this);
  11. this.series = this.series.bind(this);
  12. this.parallel = this.parallel.bind(this);
  13. this.registry = this.registry.bind(this);
  14. this.tree = this.tree.bind(this);
  15. this.lastRun = this.lastRun.bind(this);
  16. this.src = this.src.bind(this);
  17. this.dest = this.dest.bind(this);
  18. this.symlink = this.symlink.bind(this);
  19. }
  20. util.inherits(Gulp, Undertaker);
  21. Gulp.prototype.src = vfs.src;
  22. Gulp.prototype.dest = vfs.dest;
  23. Gulp.prototype.symlink = vfs.symlink;
  24. Gulp.prototype.watch = function(glob, opt, task) {
  25. if (typeof opt === 'string' || typeof task === 'string' ||
  26. Array.isArray(opt) || Array.isArray(task)) {
  27. throw new Error('watching ' + glob + ': watch task has to be ' +
  28. 'a function (optionally generated by using gulp.parallel ' +
  29. 'or gulp.series)');
  30. }
  31. if (typeof opt === 'function') {
  32. task = opt;
  33. opt = {};
  34. }
  35. opt = opt || {};
  36. var fn;
  37. if (typeof task === 'function') {
  38. fn = this.parallel(task);
  39. }
  40. return watch(glob, opt, fn);
  41. };
  42. // Let people use this class from our instance
  43. Gulp.prototype.Gulp = Gulp;
  44. var inst = new Gulp();
  45. module.exports = inst;