3

I am using gulp. I want to run 'connect task after the 'build-dev' task has done.
Here is what I wrote:

gulp.task('dev', [ 'build-dev' ], function() {
    return gulp.run([ 'connect' ]);
});

This causes a warning:

gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.

How can I fix it?

Naor
  • 23,465
  • 48
  • 152
  • 268

3 Answers3

1

Create "connect" as a new task with a dependency on "build-dev" and "dev"?

https://stackoverflow.com/a/26390567/125680

Edit: ok, got you.

According to this:

https://github.com/gulpjs/gulp/issues/96

There's no set way to do this in gulp yet so they recommend the run-sequence module:

https://www.npmjs.org/package/run-sequence

Community
  • 1
  • 1
Colin Ramsay
  • 16,086
  • 9
  • 52
  • 57
  • connect can't be dependency on build-dev because it can run also after build-staging. – Naor Dec 08 '14 at 13:13
0

My current solution is to use promises:

var build = function() {
    return new Promise(function(fulfill, reject) {
        // assuming usage like 'build(args, callback)'
        build(args, function(err) {
            if (err) {
                console.log('build failed');
                reject(err);
            } else {
                console.log('build succeeded');
                fulfill();
            }
        });
    });
};
var connect = function() {
    return new Promise(function(fulfill, reject) {
        // assuming usage like 'connect(address, callback)'
        connect(address, function(err) {
            if (err) {
                console.log('connect failed');
                reject(err);
            } else {
                console.log('connect succeeded');
                fulfill();
            }
        });
    });
};
gulp.task('dev', function() {
    return build().then(function() {
        return connect();
    });
});
martin770
  • 1,271
  • 11
  • 15
-3

To Use task dependencies, you should rewrite this:

gulp.task('dev', [ 'build-dev' ], function() {
  return gulp.run([ 'connect' ]);
});

to this:

gulp.task('dev', [ 'build-dev', 'connect' ]);
Kobe Luo
  • 83
  • 1
  • 1