Track the duration of parts of your gulp tasks
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE.md
README.md
index.js
package.json

README.md

gulp-duration Flattr this!experimental

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.

gulp-duration

Usage

gulp-duration

stream = duration([name])

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.

stream.start

Resets the stream's "start time" to the current time. Use this in your pipeline to only track the duration after a certain event.

Example

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/'))
  }
})

License

MIT. See LICENSE.md for details.