node.js - How do I get Gulp tasks to fire sequentially when firing shell commands in an async.series helper function? -
i have multiple gulp tasks send series of commands shell. second task dependent on first. how make ensure commands sent async.series in first task complete before second task executed.
gulp.task('task1', function(cb) { process.chdir(__dirname); process.chdir('path'); var cmdarray = getcmdsfortask1(); runseries(cmdarray, 'task 1'); return cb(); }); gulp.task('task2',['task1'], function() { process.chdir(__dirname); process.chdir('task2_path'); var cmd2 = getcmdfortask2(); runseries([cmd2], 'task 2'); }); var runseries = function(cmdarray, taskname) { async.series(cmdarray, function(err, results) { results.foreach( function(result) { gutil.log(gutil.colors.cyan(taskname + ' complete:') + gutil.colors.white(result) ); }); }); };
thanks much!
you're on right track using async.series. 1 missing piece haven't told original task when it's done.
gulp.task('task1', function(cb) { process.chdir(__dirname); process.chdir('path'); var cmdarray = getcmdsfortask1(); runseries(cmdarray, 'task 1', cb); }); gulp.task('task2',['task1'], function(cb) { process.chdir(__dirname); process.chdir('task2_path'); var cmd2 = getcmdfortask2(); runseries([cmd2], 'task 2', cb); }); var runseries = function(cmdarray, taskname, cb) { async.series(cmdarray, function(err, results) { results.foreach( function(result) { gutil.log(gutil.colors.cyan(taskname + ' complete:') + gutil.colors.white(result) ); }); cb(err); }); };
note how took in callback each task, , called when async.series complete.
Comments
Post a Comment