Reputation: 14440
I have a global task that must run in sequence (synchronous) some sub-tasks. I used the task's dependencies mechanism to handle that "synchronous" logic :
// main task
gulp.task('deploy', ['build', 'upload', 'extract', 'migrate'], function() {
// task returns a stream
});
// sub tasks
gulp.task('migrate', ['extract'], function() {
// task returns a stream
});
gulp.task('extract', ['upload'], function() {
// task returns a stream
});
gulp.task('upload', ['build'], function() {
// task returns a stream
});
gulp.task('build', [], function() {
// task returns a stream
});
Dependencies works well and run all in sequence.
But now, how can I call migrate
without executing extract>upload>build
.
Because, sometimes I'll want to call manually :
gulp build
gulp upload
gulp extract
And I don't want each tasks to re-run all dependencies ...
Thanks
Upvotes: 2
Views: 479
Reputation: 41
if you need the 2 version approach like I do, the following solution will do:
gulp.task('deploy:build', ['build'], function () {
gulp.start('deploy');
}
Now I can call deploy without having a dependency on build.
Upvotes: 0
Reputation: 15409
What I've done is define (2) versions of each task I want to isolate, but have them call the same logic so I'm not repeating myself.
For example, in my current project, I have an e2e-tests-development
task that depends on build-development
, which builds both the server and the client before running e2e tests. Sometimes I just want to re-run the tests and not re-build the entire application.
My e2e-tests-development.js
file looks roughly like this:
var gulp = require('gulp');
// Omitted...
gulp.task('e2e-tests-development',
['build-development'],
_task);
gulp.task('e2e-tests-development-isolated',
[], // no dependencies for the isolated version of the task.
_task);
function _task() {
// Omitted...
}
And obviously you'd invoke gulp
with e2e-tests-development-isolated
instead of e2e-tests-development
if you want to just run that task.
(Of course what gulp
really needs is a --no-depedencies
flag from the command-line...)
Upvotes: 1
Reputation: 14440
In the end, the run-sequence plugin does really well the job :
var runner = require('run-sequence');
// main task
gulp.task('deploy', [], function() {
runner(
'build',
'upload',
'extract',
'migrate'
);
});
// sub tasks
gulp.task('migrate', ['extract'], function() {
// task returns a stream
});
gulp.task('extract', ['upload'], function() {
// task returns a stream
});
gulp.task('upload', ['build'], function() {
// task returns a stream
});
gulp.task('build', ['clean:build'], function() {
// task returns a stream
});
gulp.task('clean:build', [], function() {
// task returns a stream
});
This way I can independently call any sub-task without re-executing previous subtaks...
Upvotes: 0