Updated Branches:
  refs/heads/cordova-client 5854abda3 -> 4fd3ccb59

modified add platform: created a variable for checkout tag, moved get platform 
logic to seperate function, added error checking when platform already exists, 
added error checking for invalid platform name. updated instructions to not 
install as sudo. changed lstatsync to existsSync


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/4fd3ccb5
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/4fd3ccb5
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/4fd3ccb5

Branch: refs/heads/cordova-client
Commit: 4fd3ccb59a9b09e3d3f3927746cc8bd7797f2898
Parents: 5854abd
Author: Mike Reinstein <reinstein.m...@gmail.com>
Authored: Sat Sep 15 18:01:22 2012 -0400
Committer: Fil Maj <maj....@gmail.com>
Committed: Sat Sep 22 19:22:13 2012 -0700

----------------------------------------------------------------------
 README.md       |    6 ++-
 src/build.js    |    2 +-
 src/platform.js |   90 ++++++++++++++++++++++++++++++-------------------
 src/util.js     |    9 +----
 4 files changed, 61 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4fd3ccb5/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 9f92aa5..f71547a 100644
--- a/README.md
+++ b/README.md
@@ -21,15 +21,17 @@ v2.1.0rc1 and above.
 # Install
 
 Eventually this will be available via npm. For now you must install manually:
-
+ 
 ```
 git clone https://github.com/filmaj/cordova-client.git
 cd cordova-client
-sudo npm install -g
+npm install -g
 ```
 
 the -g flag installs cordova globally, so you can access the tool via `cordova`
 
+**NOTE**: on Mac OS X, you may want to change the owner of the cordova 
directory that npm installs to. This will allow you to run cordova as local 
user without requiring root permissions. Assuming your node_modules directory 
is in `/usr/local/lib/`, you can do this by running: `sudo chown -R <username> 
/usr/local/lib/node_modules/cordova`
+
 
 ## Subcommands
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4fd3ccb5/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index d2e0d88..3938c0f 100644
--- a/src/build.js
+++ b/src/build.js
@@ -49,7 +49,7 @@ module.exports = function build (callback) {
 
                     // TODO: update activity name
                     break;
-            } 
+            }
 
             // Clean out the existing www.
             rmrf(assetsPath);

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4fd3ccb5/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 2daaab9..023387a 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -15,6 +15,54 @@ var repos = {
     
android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git'
 };
 
+/**
+ * checkout a platform from the git repo
+ * @param target string platform to get (enum of 'ios' or 'android' for now)
+ * @param cfg project configuration object
+ * @param flow I/O object to handle synchronous sys calls
+ * @throws Javascript Error on failure
+ */
+function get_platform_lib(target, cfg, flow) {
+    if (!repos[target]) {
+        // TODO: this is really a pretty terrible pattern because it kills 
+        //       excecution immediately and prevents cleanup routines. However,
+        //       I don't want to just spew a stack trace to the user either. 
+        console.error('platform "' + target + '" not found.');
+        process.exit(1);
+    }
+    // specify which project tag to check out. minimum tag is 2.1.0rc1
+    var cordova_lib_tag = '2.1.0';
+
+    // Shell out to git.
+    var outPath = path.join(__dirname, '..', 'lib', target);
+    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) {
+        cfg.remove_platform(target);
+        throw ('An error occured during git-clone of ' + repos[target] + '. ' 
+ buffers.err);
+    }
+
+    // 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) {
+        cfg.remove_platform(target);
+        throw ('An error occured during git-checkout of ' + outPath + ' to tag 
' + cordova_lib_tag + '. ' + buffers.err);
+    }
+}
+
 module.exports = function platform(command, target, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
@@ -37,46 +85,18 @@ module.exports = function platform(command, target, 
callback) {
             asyncblock(function(flow) {
                 var output = path.join(projectRoot, 'platforms', target);
 
-                // Do we have the cordova library for this platform?
+                // If the Cordova library for this platform is missing, get it.
                 if (!cordova_util.havePlatformLib(target)) {
-                    // Shell out to git.
-                    var outPath = path.join(__dirname, '..', 'lib', target);
-                    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);
-                    }
-
-                    // Check out the right version. Currently: 2.1.0.
-                    cmd = 'cd "%s" && git checkout 2.1.0';
-                    if (target == "android") cmd = 'cd "%s" && git checkout 
47daaaf';
-                    cmd = util.format(cmd, outPath);
-                    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 2.1.0rc1. ' + buffers.err);
-                    }
+                    get_platform_lib(target, cfg, flow);
                 }
 
                 // 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 dir already exists.
-                try {
-                    fs.lstatSync(output);
-                    // TODO: this platform dir already exists. what do we do?
-                } catch(e) {
-                    // Doesn't exist, continue.
+                // 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,'_');

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4fd3ccb5/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 46a7d8d..6f3057b 100644
--- a/src/util.js
+++ b/src/util.js
@@ -22,13 +22,6 @@ module.exports = {
     // Cordova implementation
     havePlatformLib: function havePlatformLib(platform) {
         var dir = path.join(__dirname, '..', 'lib', platform);
-        try {
-            fs.lstatSync(dir);
-            // Have it!
-            return true;
-        } catch(e) {
-            // Don't have it.
-            return false;
-        }
+        return fs.existsSync(dir);
     }
 };

Reply via email to