1

I am learning some tooling and would like to use gulp for automating certain task.

My problem is I am unable to chain the tasks one after another. Below is my minimal code illustrating the issue.


The package.json has "gulp": "^4.0.2" and below is my gulpFile.js:

var gulp = require('gulp');

function showMessage(message) {
    setTimeout(() => {
        console.log(message);
    }, 500);
}

gulp.task('task1', async () => {
    showMessage("task 1 executed")
});

gulp.task('task2', async () => {
    showMessage("task 2 executed")
});

gulp.task('chainExample', gulp.series('task1', 'task2'));

When calling the chainExample task, the task1 and task2 console output are executed after the task are being completed:

$ gulp chainExample
[01:11:24] Using gulpfile ..\gulpfile.js
[01:11:24] Starting 'chainExample'...
[01:11:24] Starting 'task1'...
[01:11:24] Finished 'task1' after 2.21 ms
[01:11:24] Starting 'task2'...
[01:11:24] Finished 'task2' after 819 μs
[01:11:24] Finished 'chainExample' after 7.68 ms
task 1 executed
task 2 executed

What I am trying to accomplish is to have console outputs of respective tasks within its Starting and Finished lines.


I also tried using gulp4-run-sequence with no luck and same output:

var runSequence = require('gulp4-run-sequence');
gulp.task('chainExample1', function(done) {
    runSequence('task1', 'task2', function() {
        done();
    });
});

Please shed some lights on how I can chain the tasks in a right way. Many thanks!

Raul
  • 800
  • 1
  • 7
  • 22
  • You Can Find Your Answer Here: https://stackoverflow.com/questions/29946662/gulp-tasks-chaining – Thabt Al Dobosh Aug 02 '20 at 23:50
  • @ThabtAlDobosh Thanks for your comment, I had seen the [question](https://stackoverflow.com/questions/29946662/gulp-tasks-chaining) before asking and also used the `run-sequence` and `gulp4-run-sequence` (if you look at the bottom of my question). Could you elaborate please? – Raul Aug 03 '20 at 00:12

0 Answers0