removed asyncblock. using shelljs where appropriate.

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/329aafbc
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/329aafbc
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/329aafbc

Branch: refs/heads/cordova-client
Commit: 329aafbc662f5fbb386fba5698ff32c0753690f4
Parents: 04bd249
Author: Fil Maj <maj....@gmail.com>
Authored: Sun Sep 23 11:11:30 2012 -0700
Committer: Fil Maj <maj....@gmail.com>
Committed: Sun Sep 23 11:11:30 2012 -0700

----------------------------------------------------------------------
 spec/helper.js             |   11 +++---
 src/build.js               |    1 -
 src/emulate.js             |    7 ++--
 src/metadata/ios_parser.js |   14 ++-----
 src/platform.js            |   73 +++++++++++++++++----------------------
 src/plugin.js              |   62 ++++++++++++++-------------------
 src/util.js                |   26 ++++---------
 7 files changed, 78 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/spec/helper.js
----------------------------------------------------------------------
diff --git a/spec/helper.js b/spec/helper.js
index 9baa536..98b2228 100644
--- a/spec/helper.js
+++ b/spec/helper.js
@@ -1,24 +1,23 @@
 jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
 
-var cp = require('child_process'),
+var shell = require('shelljs'),
     path = require('path'),
     fs = require('fs'),
     android_project = path.join(__dirname, 'fixtures', 'projects', 'native', 
'android'),
     wrench = require('wrench'),
     cpr = wrench.copyDirSyncRecursive;
 
-var orig_exec = cp.exec;
+var orig_exec = shell.exec;
 
-cp.exec = function(cmd, cb) {
+shell.exec = function(cmd, opts) {
     // Match various commands to exec
     if (cmd.match(/android.bin.create/)) {
         var r = new RegExp(/android.bin.create"\s"([\/\\\w-_\.]*)"/);
         var dir = r.exec(cmd)[1];
         cpr(android_project, dir);
         fs.chmodSync(path.join(dir, 'cordova', 'debug'), '754');
-        cb();
-        return;
+        return {code:0};
     }
     // Fire off to original exec
-    orig_exec.apply(null, arguments);
+    return orig_exec.apply(null, arguments);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index f916bc6..31a28ab 100644
--- a/src/build.js
+++ b/src/build.js
@@ -1,6 +1,5 @@
 var cordova_util  = require('./util'),
     path          = require('path'),
-    exec          = require('child_process').exec,
     config_parser = require('./config_parser'),
     fs            = require('fs'),
     shell         = require('shelljs'),

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index a7825c1..b227c1e 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -1,6 +1,6 @@
 var cordova_util = require('./util'),
     path = require('path'),
-    exec = require('child_process').exec,
+    shell = require('shelljs'),
     config_parser = require('./config_parser'),
     fs = require('fs'),
     util = require('util');
@@ -19,9 +19,8 @@ module.exports = function emulate () {
     // Iterate over each added platform and shell out to debug command
     platforms.map(function(platform) {
         var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 
'emulate');
-        exec(cmd, function(err, stderr, stdout) {
-            if (err) throw 'An error occurred while emulating/deploying the ' 
+ platform + ' project.' + err;
-        });
+        var em = shell.exec(cmd, {silent:true});
+        if (em.code > 0) throw 'An error occurred while emulating/deploying 
the ' + platform + ' project.' + em.output;
     });
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 26eb498..e353ad4 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -1,7 +1,6 @@
 var fs   = require('fs'),
     path = require('path'),
     xcode = require('xcode'),
-    asyncblock = require('asyncblock'),
     config_parser = require('../config_parser');
 
 module.exports = function ios_parser(project) {
@@ -14,6 +13,7 @@ module.exports = function ios_parser(project) {
     }
     this.path = project;
     this.pbxproj = path.join(this.xcodeproj, 'project.pbxproj');
+
 };
 module.exports.prototype = {
     update_from_config:function(config, callback) {
@@ -21,17 +21,11 @@ module.exports.prototype = {
         } else throw 'update_from_config requires a config_parser object';
 
         var name = config.name();
-
         var proj = new xcode.project(this.pbxproj);
+
         var parser = this;
-        asyncblock(function(flow) {
-            proj.parse(flow.set({
-                key:'parse',
-                firstArgIsError:false,
-                responseFormat:['err','hash']
-            }));
-            var parse = flow.get('parse');
-            if (parse.err) throw 'An error occured during parsing of 
project.pbxproj. Start weeping.';
+        proj.parse(function(err,hash) {
+            if (err) throw 'An error occured during parsing of 
project.pbxproj. Start weeping.';
             else {
                 proj.updateProductName(name);
                 fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8');

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 9544727..7ed3360 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -4,12 +4,10 @@ var config_parser = require('./config_parser'),
     fs            = require('fs'),
     wrench        = require('wrench'),
     rmrf          = wrench.rmdirSyncRecursive,
-    exec          = require('child_process').exec,
     path          = require('path'),
     android_parser= require('./metadata/android_parser'),
     ios_parser    = require('./metadata/ios_parser'),
-    asyncblock    = require('asyncblock');
-
+    shell         = require('shelljs');
 
 module.exports = function platform(command, target, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
@@ -30,49 +28,42 @@ module.exports = function platform(command, target, 
callback) {
             } else return 'No platforms added. Use `cordova platform add 
<platform>`.';
             break;
         case 'add':
-            asyncblock(function(flow) {
-                var output = path.join(projectRoot, 'platforms', target);
+            var output = path.join(projectRoot, 'platforms', target);
 
-                // If the Cordova library for this platform is missing, get it.
-                if (!cordova_util.havePlatformLib(target)) {
-                    cordova_util.getPlatformLib(target, flow);
-                }
+            // If the Cordova library for this platform is missing, get it.
+            if (!cordova_util.havePlatformLib(target)) {
+                cordova_util.getPlatformLib(target);
+            }
 
-                // Create a platform app using the ./bin/create scripts that 
exist in each repo.
-                // TODO: eventually refactor to allow multiple versions to be 
created.
-                // Check if output directory already exists.
-                if (fs.existsSync(output)) {
-                    throw 'Platform "' + target + '" already exists' 
+            // Create a platform app using the ./bin/create scripts that exist 
in each repo.
+            // TODO: eventually refactor to allow multiple versions to be 
created.
+            // Check if output directory already exists.
+            if (fs.existsSync(output)) {
+                throw 'Platform "' + target + '" already exists' 
+            } else {
+                // directory doesn't exist, run platform's create script
+                var bin = path.join(__dirname, '..', 'lib', target, 'bin', 
'create');
+                var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
+                var name = cfg.name().replace(/\W/g,'_');
+                var command = util.format('"%s" "%s" "%s" "%s"', bin, output, 
pkg, name);
+                var create = shell.exec(command, {silent:true});
+                if (create.code > 0) {
+                    throw ('An error occured during creation of ' + target + ' 
sub-project. ' + create.output);
                 } else {
-                    // directory doesn't exist, run platform's create script
-                    var bin = path.join(__dirname, '..', 'lib', target, 'bin', 
'create');
-                    var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
-                    var name = cfg.name().replace(/\W/g,'_');
-                    var command = util.format('"%s" "%s" "%s" "%s"', bin, 
output, pkg, name);
-                    child = exec(command, flow.set({
-                        key:'create',
-                        firstArgIsError:false,
-                        responseFormat:['err', 'stdout', 'stderr']
-                    }));
-                    var bfrs = flow.get('create');
-                    if (bfrs.err) {
-                        throw ('An error occured during creation of ' + target 
+ ' sub-project. ' + bfrs.err);
-                    } else {
-                        cfg.add_platform(target);
-                        switch(target) {
-                            case 'android':
-                                var android = new android_parser(output);
-                                android.update_from_config(cfg);
-                                if (callback) callback();
-                                break;
-                            case 'ios':
-                                var ios = new ios_parser(output);
-                                ios.update_from_config(cfg, callback);
-                                break;
-                        }
+                    cfg.add_platform(target);
+                    switch(target) {
+                        case 'android':
+                            var android = new android_parser(output);
+                            android.update_from_config(cfg);
+                            if (callback) callback();
+                            break;
+                        case 'ios':
+                            var ios = new ios_parser(output);
+                            ios.update_from_config(cfg, callback);
+                            break;
                     }
                 }
-            });
+            }
             break;
         case 'remove':
             // Remove the platform from the config.xml

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 20755c3..a5bdd4e 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -4,10 +4,9 @@ var cordova_util  = require('./util'),
     cpr           = wrench.copyDirSyncRecursive,
     fs            = require('fs'),
     path          = require('path'),
+    shell         = require('shelljs'),
     config_parser = require('./config_parser'),
     plugin_parser = require('./plugin_parser'),
-    exec          = require('child_process').exec,
-    asyncblock    = require('asyncblock'),
     ls            = fs.readdirSync;
 
 module.exports = function plugin(command, target, callback) {
@@ -73,42 +72,33 @@ module.exports = function plugin(command, target, callback) 
{
             var wwwContents = ls(pluginWww);
             var cli = path.join(__dirname, '..', 'node_modules', 
'pluginstall', 'cli.js');
 
-            asyncblock(function(flow) {
-                // Iterate over all matchin app-plugin platforms in the 
project and install the
-                // plugin.
-                intersection.forEach(function(platform) {
-                    var cmd = util.format('%s %s "%s" "%s"', cli, platform, 
path.join(projectRoot, 'platforms', platform), target);
-                    var key = 'pluginstall-' + platform;
-                    exec(cmd, flow.set({
-                      key:key,
-                      firstArgIsError:false,
-                      responseFormat:['err', 'stdout', 'stderr']
-                    }));
-                    var buffers = flow.get(key);
-                    if (buffers.err) throw 'An error occured during plugin 
installation for ' + platform + '. ' + buffers.err;
-                });
-                
-                // Add the plugin web assets to the www folder as well
-                // TODO: assumption that web assets go under www folder
-                // inside plugin dir; instead should read plugin.xml
-                wwwContents.forEach(function(asset) {
-                    asset = path.resolve(path.join(pluginWww, asset));
-                    var info = fs.lstatSync(asset);
-                    var name = asset.substr(asset.lastIndexOf('/')+1);
-                    var wwwPath = path.join(projectWww, name);
-                    if (info.isDirectory()) {
-                        cpr(asset, wwwPath);
-                    } else {
-                        fs.writeFileSync(wwwPath, fs.readFileSync(asset));
-                    }
-                });
-
-                // Finally copy the plugin into the project
-                cpr(target, path.join(pluginPath, targetName));
-
-                if (callback) callback();
+            // Iterate over all matchin app-plugin platforms in the project 
and install the
+            // plugin.
+            intersection.forEach(function(platform) {
+                var cmd = util.format('%s %s "%s" "%s"', cli, platform, 
path.join(projectRoot, 'platforms', platform), target);
+                var plugin_cli = shell.exec(cmd, {silent:true});
+                if (plugin_cli.code > 0) throw 'An error occured during plugin 
installation for ' + platform + '. ' + cli.output;
             });
+            
+            // Add the plugin web assets to the www folder as well
+            // TODO: assumption that web assets go under www folder
+            // inside plugin dir; instead should read plugin.xml
+            wwwContents.forEach(function(asset) {
+                asset = path.resolve(path.join(pluginWww, asset));
+                var info = fs.lstatSync(asset);
+                var name = asset.substr(asset.lastIndexOf('/')+1);
+                var wwwPath = path.join(projectWww, name);
+                if (info.isDirectory()) {
+                    cpr(asset, wwwPath);
+                } else {
+                    fs.writeFileSync(wwwPath, fs.readFileSync(asset));
+                }
+            });
+
+            // Finally copy the plugin into the project
+            cpr(target, path.join(pluginPath, targetName));
 
+            if (callback) callback();
             break;
         case 'remove':
             // TODO: remove plugin. requires pluginstall to

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/329aafbc/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 13bf5e7..bf047be 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,7 +1,7 @@
 var fs         = require('fs'),
     path       = require('path'),
     util       = require('util'),
-    exec       = require('child_process').exec;
+    shell      = require('shelljs');
 
 var repos = {
     ios:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git',
@@ -37,7 +37,7 @@ module.exports = {
      * @param flow I/O object to handle synchronous sys calls
      * @throws Javascript Error on failure
      */
-    getPlatformLib: function getPlatformLib(target, flow) {
+    getPlatformLib: function getPlatformLib(target) {
         if (!repos[target]) {
             // TODO: this is really a pretty terrible pattern because it kills 
             //       excecution immediately and prevents cleanup routines. 
However,
@@ -53,26 +53,16 @@ module.exports = {
         var cmd = util.format('git clone %s "%s"', repos[target], outPath);
 
         console.log('Cloning ' + repos[target] + ', this may take a while...');
-        exec(cmd, flow.set({
-            key:'cloning',
-            firstArgIsError:false,
-            responseFormat:['err', 'stdout', 'stderr']
-        }));
-        var buffers = flow.get('cloning');
-        if (buffers.err) {
-            throw ('An error occured during git-clone of ' + repos[target] + 
'. ' + buffers.err);
+        var clone = shell.exec(cmd, {silent:true});
+        if (clone.code > 0) {
+            throw ('An error occured during git-clone of ' + repos[target] + 
'. ' + clone.output);
         }
 
         // Check out the right version.
         cmd = util.format('cd "%s" && git checkout %s', outPath, 
cordova_lib_tag);
-        exec(cmd, flow.set({
-            key:'tagcheckout',
-            firstArgIsError:false,
-            responseFormat:['err', 'stdout', 'stderr']
-        }));
-        buffers = flow.get('tagcheckout');
-        if (buffers.err) {
-            throw ('An error occured during git-checkout of ' + outPath + ' to 
tag ' + cordova_lib_tag + '. ' + buffers.err);
+        var checkout = shell.exec(cmd, {silent:true});
+        if (checkout.code > 0) {
+            throw ('An error occured during git-checkout of ' + outPath + ' to 
tag ' + cordova_lib_tag + '. ' + checkout.output);
         }
     }
 };

Reply via email to