Closed miparnisari closed 8 years ago
Good idea. Would love to see a pull request.
Oh, I thought this was already possible and I just wasn't seeing it haha.
I'm not sure how to go about this. I'm not a Node expert but it seems that if the node scripts returned a stream that can then be piped into another command it should work?
Jep. This works.
command()
.pipe(...)
.pipe(...)
.pipe(...)
;
Hmm.. I changed the gulp task to this:
gulp.task('gen', function () {
return gulp.src('.')
.pipe(prompt.confirm({
message: 'Clear Redis and regenerate SQL DB?',
default: false
}))
.pipe(run('redis-cli flushall'))
.pipe(run('node config/gen.js'))
.pipe(run('node config/fill_users.js'))
});
And this is what I got. Notice how the order of execution is wrong for the node scripts:
λ gulp gen
[23:09:18] Using gulpfile ~\Documents\app\gulpfile.js
[23:09:18] Starting 'gen'...
? Clear Redis and regenerate SQL DB? Yes
$ redis-cli flushall
OK
$ node config/fill_users.js
finished creating users
$ node config/gen.js
DB dropped.
[23:09:47] Finished 'gen' after 29 s
Not sure if this might be a problem or not, but this is the gen.js
script. When run on its own it takes some time.
var sequelize = require('sequelize');
return sequelize
.query('SET FOREIGN_KEY_CHECKS = 0')
.then(function () {
return models.sequelize.sync({ force: true })
})
.then(function () {
return models.sequelize.query('SET FOREIGN_KEY_CHECKS = 1')
})
.then(function () {
console.log('DB dropped.');
process.exit(0);
})
.catch(function (err) {
console.error(err);
process.exit(-1);
})
I want to run two commands, namely
redis-cli flushall
and a custom scriptnode gen.js
in sequence. This is my current task:However, I see two issues with that code:
1) If I want to add more commands, this quickly becomes callback hell. I would like something cleaner as in with Promises, with
then
. 2) The result I get is this:...but I expected this: