UNPKG

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