-
-
Save mde/2689923 to your computer and use it in GitHub Desktop.
How to handle pre-req flow using Jake.exec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var spawn = require('child_process').spawn; | |
desc('Do thing 1'); | |
task('thing1', [], function () { | |
var cmds = ['node -e "console.log(\'--> Thing 1... Executing\')"']; | |
console.log('--> Thing 1... Starting'); | |
jake.exec(cmds, function () { | |
var echo = spawn('echo', | |
["--> Thing 1... I'm doing a spawned process in thing 1"]) | |
, data = ''; | |
echo.stdout.on('data', function (d) { | |
data += d; | |
}); | |
echo.stdout.on('end', function () { | |
console.log(data); | |
}); | |
echo.on('exit', function () { | |
console.log('--> Thing 1... Done'); | |
complete(); | |
}); | |
}, {stdout: true}); | |
}, {async: true}); | |
desc('Do thing 2'); | |
task('thing2', [], function () { | |
console.log('--> Thing 2... Starting'); | |
var cmds = ['node -e "console.log(\'--> Thing 2... Executing\')"']; | |
jake.exec(cmds, function () { | |
console.log('--> Thing 2... Done'); | |
complete(); | |
}, {stdout: true}); | |
}, {async: true}); | |
desc('Do thing 3'); | |
task('thing3', [], function () { | |
console.log('--> Thing 3... Starting'); | |
var cmds = ['node -e "console.log(\'--> Thing 3... Executing\')"']; | |
jake.exec(cmds, function () { | |
console.log('--> Thing 3... Done'); | |
complete(); | |
}, {stdout: true}); | |
}, {async: true}); | |
desc('Do all the things'); | |
task('default', ['thing1', 'thing2'], function () { | |
console.log('* Default... Starting'); | |
var cmds = ['node -e "console.log(\'* Default... Executing\')"' ]; | |
jake.exec(cmds, function () { | |
var thing = jake.Task.thing3; | |
thing.addListener('complete', function () { | |
console.log('* Default... Done'); | |
complete(); | |
}); | |
thing.invoke(); | |
}, {stdout: true}); | |
}, {async: true}); | |
/* | |
jake | |
--> Thing 1... Starting | |
--> Thing 1... Executing | |
--> Thing 1... I'm doing a spawned process in thing 1 | |
--> Thing 1... Done | |
--> Thing 2... Starting | |
--> Thing 2... Executing | |
--> Thing 2... Done | |
* Default... Starting | |
* Default... Executing | |
--> Thing 3... Starting | |
--> Thing 3... Executing | |
--> Thing 3... Done | |
* Default... Done | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I should have been clearer that the code above is a working version of what you seemed to be wanting here, including how to use
spawn
(even though you shouldn't really need it) and how to useinvoke
.Yes, the entire reason for having an "async:true" flag for tasks is so you can break things down into smaller units of code for reusability, and still ensure prereqs execute sequentially. You should always flag a task that does asynchronous work as async and use
complete
, even if it's initially a standalone task.