Skip to content

Instantly share code, notes, and snippets.

@morlay
Last active August 29, 2015 14:08
Show Gist options
  • Save morlay/52ee01f8dd4c12947153 to your computer and use it in GitHub Desktop.
Save morlay/52ee01f8dd4c12947153 to your computer and use it in GitHub Desktop.
a gulp extend
var through = require('through');
var gutil = require('gulp-util');
var path = require('path');
module.exports = function() {
var gulp = this;
this.isWatching = false;
this.setWatcher = function() {
this.isWatching = true;
};
this.watcher = function() {
if (this.isWatching) {
return gulp.watch.apply(gulp, arguments);
}
return null;
};
this.pipeTimer = function(taskname) {
taskname = taskname || '~~~';
var startTime = new Date();
return through(
function() {
},
function() {
if (gulp.isWatching) {
this.on('end', function() {
var time = new Date() - startTime;
gutil.log('Watcher:',
'\'' + gutil.colors.cyan(taskname) + '\'',
're-bundle after',
gutil.colors.magenta(time > 1000 ? time / 1000 + ' s' : time + ' ms'));
});
}
this.queue(null);
});
};
// --watch
if (gutil.env.watch) {
this.setWatcher();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment