Skip to content

Commit

Permalink
Added exec util functions for shelling out.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Nov 17, 2011
1 parent 92d0ec0 commit df5b4ec
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Jakefile
@@ -1,5 +1,5 @@
var fs = require('fs')
, pkg = JSON.parse(fs.readFileSync('package.json').toString())
, pkg = JSON.parse(fs.readFileSync('./package.json').toString())
, version = pkg.version

var t = new jake.PackageTask('jake', 'v' + version, function () {
Expand Down
3 changes: 3 additions & 0 deletions bin/cli.js 100644 → 100755
Expand Up @@ -22,6 +22,7 @@ var args = process.argv.slice(2)
, fs = require('fs')
, jake = require(libPath + '/jake.js')
, api = require(libPath + '/api.js')
, utils = require(libPath + '/utils.js')
, Program = require(libPath + '/program.js').Program
, program = new Program()
, Loader = require(libPath + '/loader.js').Loader
Expand Down Expand Up @@ -49,6 +50,8 @@ if (!program.preemptiveOption()) {
global[p] = api[p];
}

jake.exec = utils.exec;

// Get convenient refs to FileList, PackageTask
jake.FileList = require(libPath + '/file_list').FileList
jake.PackageTask = require(libPath + '/package_task').PackageTask
Expand Down
1 change: 1 addition & 0 deletions lib/api.js
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*
*/
var exec = require('child_process').exec;

var api = new (function () {
this.task = function (name, prereqs, action, async) {
Expand Down
56 changes: 56 additions & 0 deletions lib/utils.js
@@ -0,0 +1,56 @@
/*
* Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


var exec = require('child_process').exec
, utils = new (function () {

this.exec = function (arr, callback, opts) {
var options = opts || {}
, stdout = options.stdout
, stderr = options.stderr
, breakOnError = options.breakOnError
var run = function (cmd) {
exec(cmd, function (err, stdout, stderr) {
var next;
if (err && breakOnError) {
this.fail('Error: ' + JSON.stringify(err));
}
if (stderr && options.stderr) {
console.log('Error: ' + stderr);
}
if (stdout && options.stdout) {
console.log(stdout);
}
next = arr.shift();
if (next) {
run(next);
}
else {
if (callback) {
callback();
}
}
});
};
run(arr.shift());
};

})();

module.exports = utils;
14 changes: 14 additions & 0 deletions tests/Jakefile
Expand Up @@ -154,4 +154,18 @@ namespace('bar', function() {
});
});

desc('Tests jake.exec API call');
task('testExec', function () {
var cmds = [
'echo "testing"'
, 'true'
, 'echo "seems to work"'
]
, callback = function () {
complete();
};
jake.exec(cmds, callback, {stdout: true});
}, true);



0 comments on commit df5b4ec

Please sign in to comment.