An implementation of Gulp 4.x's lastRun
method for Gulp 3.x.
This is a utility, not a plugin. It does not act on files or streams nor does it meet other requirements defined by Gulp to be considered a plugin.
To take advantage of a helpful feature from Gulp 4.x without waiting for it to be released or upgrading from 3.x to 4.x. The original intent is to provide a timestamp value that can be used for filtering.
npm install --save-dev gulp3-last-run
Use Gulp 3 Last Run in combination with gulp-filter-since:
const gulp = require('gulp');
const gulp3LastRun = require('gulp3-last-run');
const gulpLoadPlugins = require('gulp-load-plugins');
const $ = gulpLoadPlugins();
const taskLastRun = gulp3LastRun(gulp);
gulp.task('scripts', function(){
const lastRunMs = taskLastRun.retrieveThenCapture('scripts');
return gulp.src('app/scripts/**/*.js')
.pipe($.filterSince(lastRunMs))
.pipe($.babel())
.pipe(gulp.dest('dist/scripts'))
;
});
gulp.task('watch', ['scripts'], function(){
gulp.watch('app/scripts/**/*.js', ['scripts']);
});
or, use it in combination with vinyl-filter-since and gulp-if:
const gulp = require('gulp');
const gulp3LastRun = require('gulp3-last-run');
const gulpLoadPlugins = require('gulp-load-plugins');
const vinylFilterSince = require('vinyl-filter-since');
const $ = gulpLoadPlugins();
const taskLastRun = gulp3LastRun(gulp);
gulp.task('scripts', function(){
const lastRunMs = taskLastRun.retrieveThenCapture('scripts');
return gulp.src('app/scripts/**/*.js')
.pipe($.if(!!lastRunMs, vinylFilterSince(lastRunMs)))
.pipe($.babel())
.pipe(gulp.dest('dist/scripts'))
;
});
gulp.task('watch', ['scripts'], function(){
gulp.watch('app/scripts/**/*.js', ['scripts']);
});
Returns a plain object containing static methods that act on a reference to a gulp object to get and set last run times. It is basically a wrapper for the last-run module.
Type: Object
A reference to the gulp
module.
retrieveThenCapture
is a convenience method not found in the last-run module. It executes the retrieve
method then the capture
method with a single method call.
- Retrieves the current last run for a given task, as a number representing milliseconds.
- Immediately captures a new last run time
- Returns the retrieved last run value (whatever it was before the capture). Returns undefined if the task function has not been previously captured.
Type: String
A string that is used to retrieve the task function from the gulp instance. The task function is then used as the fn
argument for last-run module method arguments.
Type: Object
Options for each method can be provided as option and will be passed to their respective last-run methods if provided.
Type: Number
Assuming
lastRun(fn)
returns 1426000001111,lastRun(fn, 1000)
returns 1426000001000.
Type: Number
If passed the optional timestamp, captures that time instead of
Date.now()
. The captured timestamp can then be retrieved using thelastRun
function.Source: lastRun.capture(fn, [timestamp])
taskLastRun.capture(taskName[, timestamp]),
taskLastRun.release(taskName), and
taskLastRun.retrieve(taskName[, timeResolution])
Type: String
A string that is used to retrieve the task function from the gulp instance. The task function is then used as the fn
argument for last-run module method arguments.
Other arguments are passed directly to their last-run module counterparts. gulp3-last-run's retrieve
method is the counter part for last-run's main method.
See last-run's API documentation for more information about each of these methods.