index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  17. util.inherits(Gulp, Undertaker);
  18. Gulp.prototype.src = vfs.src;
  19. Gulp.prototype.dest = vfs.dest;
  20. Gulp.prototype.symlink = vfs.symlink;
  21. Gulp.prototype.watch = function(glob, opt, task) {
  22. if (typeof opt === 'string' || typeof task === 'string' ||
  23. Array.isArray(opt) || Array.isArray(task)) {
  24. throw new Error('watching ' + glob + ': watch task has to be ' +
  25. 'a function (optionally generated by using gulp.parallel ' +
  26. 'or gulp.series)');
  27. }
  28. if (typeof opt === 'function') {
  29. task = opt;
  30. opt = {};
  31. }
  32. opt = opt || {};
  33. var fn;
  34. if (typeof task === 'function') {
  35. fn = this.parallel(task);
  36. }
  37. return watch(glob, opt, fn);
  38. };
  39. // Let people use this class from our instance
  40. Gulp.prototype.Gulp = Gulp;
  41. var inst = new Gulp();
  42. module.exports = inst;