Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added exec util functions for shelling out.

  • Loading branch information...
commit df5b4ec1462c53eb4d14af33adfd0a62048e7b68 1 parent 92d0ec0
Matthew Eernisse mde authored
2  Jakefile
View
@@ -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 () {
3  bin/cli.js 100644 → 100755
View
@@ -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
1  lib/api.js
View
@@ -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) {
56 lib/utils.js
View
@@ -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 tests/Jakefile
View
@@ -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);
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.