diff --git a/Jakefile b/Jakefile index b5e67884..a1553929 100644 --- a/Jakefile +++ b/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 () { diff --git a/bin/cli.js b/bin/cli.js old mode 100644 new mode 100755 index c066a9a1..1e1b3557 --- a/bin/cli.js +++ b/bin/cli.js @@ -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 @@ -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 diff --git a/lib/api.js b/lib/api.js index cf442e37..c11ef97f 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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) { diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..ef1c6e43 --- /dev/null +++ b/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; diff --git a/tests/Jakefile b/tests/Jakefile index 1cb52301..375cfd07 100644 --- a/tests/Jakefile +++ b/tests/Jakefile @@ -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); + +