Reputation: 9379
I have a task that goes like this:
var gulp = require('gulp');
gulp.task('doStuff', ['a', 'b', 'c'], function () {
console.log("success");
});
I have read the docs, and from what I understood, this is what should happen:
This is what actually happens:
I was surprised to find out that if I accept a callback in the other functions, though, that callback is my function. I.e. if I do:
var gulp = require('gulp');
gulp.task('a', function (callback) {
callback();
});
This will run my code.
I'd like my function to be executed only once, and only after all other tasks have run. What am I missing, or misinterpreting? What can I do?
By the way, this may be relevant: most of my other tasks do things like generating files, and they return such files. Like:
var gulp = require('gulp');
var rename = require('gulp-rename');
var someLogic = require('someLogicIImplementedSomewhereElse');
var path = "../../somepath";
gulp.task('foo', function() {
return gulp.src(path)
.pipe(someLogic())
.pipe(rename("renamed.js"))
.pipe(gulp.dest(path));
});
Upvotes: 1
Views: 4908
Reputation: 1087
Make sure that a, b and c either return something or execute the callback.
Try the following example:
gulp.task('a', function (done) {
done();
});
gulp.task('b', function (done) {
return gulp.src('.');
});
gulp.task('c', function (done) {
done();
});
gulp.task('stuff', ['a', 'b', 'c'], function () {
console.log("success");
});
Here is the output of gulp stuff
- Starting 'a'...
- Finished 'a' after 48 μs
- Starting 'b'...
- Starting 'c'...
- Finished 'c' after 6.03 μs
- Finished 'b' after 9.14 ms
- Starting 'stuff'...
- success
- Finished 'stuff' after 38 μs
Upvotes: 3