Last active
August 29, 2015 14:08
-
-
Save morlay/52ee01f8dd4c12947153 to your computer and use it in GitHub Desktop.
a gulp extend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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