Track the duration of parts of your gulp tasks.
Useful, for example, when running a periodic watch-like task but not using
gulp.watch
or gulp's task dependency system.
Creates a new pass-through duration stream. When this stream is closed, it will log the amount of time since its creation to your terminal.
Optionally, you can pass a name
to use when logging – defaults to
gulp-duration
.
Resets the stream's "start time" to the current time. Use this in your pipeline to only track the duration after a certain event.
Here's a simple example:
var duration = require('gulp-duration')
var uglify = require('gulp-uglify')
var concat = require('gulp-concat')
var gulp = require('gulp')
gulp.task('interval', function() {
setInterval(function() {
gulp.src('./*.js')
.pipe(concat())
.pipe(uglify())
.pipe(duration('rebuilding files'))
.pipe(gulp.dest('./dist'))
}, 5000)
})
And something a little less trivial:
var source = require('vinyl-source-stream')
var uglify = require('gulp-uglify')
var watchify = require('watchify')
var gulp = require('gulp')
gulp.task('example', function() {
var bundler = watchify({
entries: ['./index.js']
}).on('update', rebundle)
return rebundle()
function rebundle() {
var uglifyTimer = duration('uglify time')
var bundleTimer = duration('bundle time')
return bundler.bundle()
.pipe(source('bundle.js'))
.pipe(bundleTimer)
// start just before uglify recieves its first file
.once('data', uglifyTimer.start)
.pipe(uglify())
.pipe(uglifyTimer)
.pipe(gulp.dest('example/'))
}
})
MIT. See LICENSE.md for details.