Closed jasondecamp closed 8 years ago
There's no need for promises, you just have to add the callback to run-sequence, as shown in the docs:
gulp.task('build', function(callback) {
sequence(['js','html','assets','libs','sass'],'inject', callback);
});
Also there's no reason to return it.
Whilst there is no need for promises, I find returning them slightly more elegant that using a "done" callback, would be nice to have the option to use this style.
+1
I solved it by wrapping a Promise myself:
// index.js
import gulp from "gulp";
import runSequence from "run-sequence";
import c from "./const";
gulp.task(c.BUILD, () => {
return new Promise((res, rej) => {
runSequence(
c.UNIT_TEST,
c.DEL_DIST,
c.COPY_DIST,
c.KILL_CACHE,
[
c.BUILD_CSS,
c.BUILD_JS,
c.BUILD_HTML,
c.BUILD_IMG,
],
res // done now promise resolver
)
});
});
gulp.task(c.DEPLOY, () => {
return new Promise((res, rej) => {
runSequence(
c.BUILD,
c.DEPLOY_DEV,
res // done now promise resolver
);
});
});
Those are my main
entry points, the deps tasks are basic stream-based gulp tasks, like:
// uglify
import gulp from "gulp";
import uglify from "gulp-uglify";
import babel from "gulp-babel";
import c from "./const";
gulp.task(c.BUILD_JS, () => {
return gulp.src([
'dist/**/*.js'
])
.pipe(babel({
plugins: [
'transform-es2015-template-literals'
]
}))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
With new node async/await feature it would be quite useful to return a promise when callback is not passed.
gulp.task('build', async () => {
await asyncFunc();
// Some other code...
await runSequence(['js', 'html', 'assets', 'libs', 'sass'], 'inject');
});
I currently have a few tasks set up using run-sequence and it would be beneficial for one sequence to be able to call another sequence as part of the flow. Currently it does not appear that it supports this. Here is an example:
For now I guess I can just write out all of the build sequence within the default sequence, but that is unnecessary repetition that I would rather avoid.