Skip to content

Instantly share code, notes, and snippets.

@johnmdonahue
Created May 13, 2012 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnmdonahue/2671849 to your computer and use it in GitHub Desktop.
Save johnmdonahue/2671849 to your computer and use it in GitHub Desktop.
How to handle pre-req flow using Jake.exec
// I'm trying to accomplish something like below.
// Is there a best practice for using Jake.exec in a pre-req that's also a stand alone task?
// The default task below will execute in arbitrary order - I am assuming because exec is async.
// Seems like the invoke/complete pattern could be used but using pre-reqs I'm at a loss.
// Are there other options to enforce procedure order here?
var spawn = require('child_process').spawn
desc('Do thing 1');
task('thing1', [], function () {
console.log('--> Thing 1... Starting')
var cmds = ['node -e "console.log(\'--> Thing 1... Executing\')"']
, 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) })
jake.exec(cmds, function () {
console.log('--> Thing 1... Done')
}, {stdout: true});
}, {async: false});
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')
}, {stdout: true});
}, {async: false});
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 () {
console.log('* Default... Done')
}, {stdout: true});
}, {async: false});
/*
⚡ jake
--> Thing 1... Starting
--> Thing 2... Starting
* Default... Starting
--> Thing 1... I'm doing a spawned process in thing 1
--> Thing 2... Executing
--> Thing 2... Done
* Default... Executing
* Default... Done
--> Thing 1... Executing
--> Thing 1... Done
*/
@johnmdonahue
Copy link
Author

@mde If you get some time, any pointers here would be greatly appreciated! Let me know if this needs any clarification. Thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment