Reputation: 73
I have the following gulp-tasks defined. They should revision static files and replace links to them.
var config = require('./config');
var gulp = require('gulp');
var rev = require('gulp-rev');
var revNapkin = require('gulp-rev-napkin');
var revReplace = require('gulp-rev-replace');
var runSequence = require('run-sequence');
var manifest_src = gulp.src('./' + config.base.dest + '/manifest.json');
var revStatic = function() {
return gulp.src([config.base.dest + '/**/*', '!' + config.base.dest + '/**/*+(css|js|json|html)'])
.pipe(rev())
.pipe(gulp.dest(config.base.dest))
.pipe(revNapkin({verbose: false}))
.pipe(rev.manifest(config.base.dest + '/manifest.json', {merge: true}))
.pipe(gulp.dest(''));
}
var revUpdateRef = function() {
return gulp.src(config.base.dest + '/**/**.{css,js}')
.pipe(revReplace({manifest: manifest_src}))
.pipe(gulp.dest(config.base.dest));
}
var revCSSJS = function() {
return gulp.src(config.base.dest + '/**/*.{css,js}')
.pipe(rev())
.pipe(gulp.dest(config.base.dest))
.pipe(revNapkin({verbose: false}))
.pipe(rev.manifest(config.base.dest + '/manifest.json', {merge: true}))
.pipe(gulp.dest(''));
}
var revUpdateHTML = function() {
return gulp.src(config.base.dest + '/**/*.html')
.pipe(revReplace({manifest: manifest_src}))
.pipe(gulp.dest(config.base.dest));
}
var revTask = function(cb) {
runSequence('rev:static', 'rev:updateRef', 'rev:cssjs', 'rev:updateHTML', cb)
}
gulp.task('rev:static', revStatic);
module.exports = revStatic;
gulp.task('rev:updateRef', revUpdateRef);
module.exports = revUpdateRef;
gulp.task('rev:cssjs', revCSSJS);
module.exports = revCSSJS;
gulp.task('rev:updateHTML', revUpdateHTML);
module.exports = revUpdateHTML;
gulp.task('rev', revTask);
module.exports = revTask;
If I run the tasks each other by hand everything is fine. However if I ran the task 'rev' that consist of all the rev tasks run by run-sequence the last task 'rev:updateHTML' is not finished.
My console output looks like this
~/working/gulp-workflow/$gulp rev
[14:33:41] Using gulpfile ~/working/gulp-workflow/gulpfile.js
[14:33:41] Starting 'rev'...
[14:33:41] Starting 'rev:static'...
[14:33:41] Finished 'rev:static' after 204 ms
[14:33:41] Starting 'rev:updateRef'...
[14:33:41] Finished 'rev:updateRef' after 38 ms
[14:33:41] Starting 'rev:cssjs'...
[14:33:41] Finished 'rev:cssjs' after 26 ms
[14:33:41] Starting 'rev:updateHTML'...
~/working/gulp-workflow/$
I can´t find any error in my tasks, but I guess there is an error with the stream running async. I hope you can help me and point out my error.
Upvotes: 3
Views: 1047
Reputation: 303
If I am not totally wrong, gulp does not recognize, if the task has been finished or not. Therefore you can use done
as a parameter and execute it whenever pipe has been finished. So actually something like this:
var revUpdateHTML = function(done) {
return gulp.src(config.base.dest + '/**/*.html')
.pipe(revReplace({manifest: manifest_src}))
.pipe(gulp.dest(config.base.dest))
.on('end', function() {
done();
});
}
Upvotes: 2