Run a gulp task programatically with promises 🍭
The recommended way to run tasks programatically in Gulp is to use the series
method.
const { series } = require('gulp')
const { myTask } = require('./tasks')
const done = (error) => {
if(error) { // error }
// success
}
series(myTask)(done)
For more info about this, refer to bach which is the module Gulp uses to run tasks.
Cause gulp.start
is undocumented and there is no easy alternative to start tasks and do something else after its done. Works with gulp 3 and will be updated when gulp 4 is released.
const gulp = require('gulp')
const runTask = require('gulp-run-promise')(gulp)
runTask('some-random-task').then(() => {
// Do something else
}).catch((error) => {
console.error(`Error: ${error}`);
})
This works by listening to err
and stop
events emitted by orchestrator which is what gulp uses under the hood to run tasks. If you just want to run your gulp tasks sequentially or just control the order of execution you should not use this and check out the excellent run-sequence instead.