OverZealous / run-sequence

Run a series of dependent gulp tasks in order
MIT License
961 stars 56 forks source link

Feature Request: run-sequence returns a promise itself #60

Closed jasondecamp closed 8 years ago

jasondecamp commented 8 years ago

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:

var sequence = require('run-sequence');
gulp.task('default', function() {
  return sequence('build',['watch','webserver']);
});
gulp.task('build', function() {
  return sequence(['js','html','assets','libs','sass'],'inject');
});

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.

OverZealous commented 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);
});
OverZealous commented 8 years ago

Also there's no reason to return it.

keirlawson commented 8 years ago

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.

pyrsmk commented 8 years ago

+1

ericmdantas commented 8 years ago

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'));    
});
juan-ferrer-toribio commented 6 years ago

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');
});