incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [5/7] git commit: moved lib cloning to util module. `npm test` now makes sure libraries are all cloend down before running tests.
Date Sun, 23 Sep 2012 18:20:01 GMT
moved lib cloning to util module. `npm test` now makes sure libraries are all cloend down before
running tests.


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

Branch: refs/heads/cordova-client
Commit: f9c043ebe25b11b30847edebfed04916f3c198e2
Parents: 10f372b
Author: Fil Maj <maj.fil@gmail.com>
Authored: Sat Sep 22 21:04:47 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Sat Sep 22 21:04:47 2012 -0700

----------------------------------------------------------------------
 package.json      |    2 +-
 src/platform.js   |   54 +-----------------------------------------------
 src/util.js       |   53 ++++++++++++++++++++++++++++++++++++++++++++++-
 test_bootstrap.js |   17 +++++++++++++++
 4 files changed, 71 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/f9c043eb/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 6d46f3d..9f419e1 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
     "cordova": "./bin/cordova"
   },
   "scripts": {
-    "test": "./node_modules/jasmine-node/bin/jasmine-node --color spec"
+    "test": "node test_bootstrap.js && ./node_modules/jasmine-node/bin/jasmine-node
--color spec"
   },
   "repository": {
     "type": "git",

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/f9c043eb/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 023387a..9544727 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -10,58 +10,6 @@ var config_parser = require('./config_parser'),
     ios_parser    = require('./metadata/ios_parser'),
     asyncblock    = require('asyncblock');
 
-var repos = {
-    ios:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git',
-    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());
@@ -87,7 +35,7 @@ module.exports = function platform(command, target, callback) {
 
                 // If the Cordova library for this platform is missing, get it.
                 if (!cordova_util.havePlatformLib(target)) {
-                    get_platform_lib(target, cfg, flow);
+                    cordova_util.getPlatformLib(target, flow);
                 }
 
                 // Create a platform app using the ./bin/create scripts that exist in each
repo.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/f9c043eb/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 6f3057b..13bf5e7 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,5 +1,12 @@
 var fs         = require('fs'),
-    path       = require('path');
+    path       = require('path'),
+    util       = require('util'),
+    exec       = require('child_process').exec;
+
+var repos = {
+    ios:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git',
+    android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git'
+};
 
 module.exports = {
     // Runs up the directory chain looking for a .cordova directory.
@@ -23,5 +30,49 @@ module.exports = {
     havePlatformLib: function havePlatformLib(platform) {
         var dir = path.join(__dirname, '..', 'lib', platform);
         return fs.existsSync(dir);
+    },
+    /**
+     * checkout a platform from the git repo
+     * @param target string platform to get (enum of 'ios' or 'android' for now)
+     * @param flow I/O object to handle synchronous sys calls
+     * @throws Javascript Error on failure
+     */
+    getPlatformLib: function getPlatformLib(target, 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) {
+            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) {
+            throw ('An error occured during git-checkout of ' + outPath + ' to tag ' + cordova_lib_tag
+ '. ' + buffers.err);
+        }
     }
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/f9c043eb/test_bootstrap.js
----------------------------------------------------------------------
diff --git a/test_bootstrap.js b/test_bootstrap.js
new file mode 100644
index 0000000..41e51dc
--- /dev/null
+++ b/test_bootstrap.js
@@ -0,0 +1,17 @@
+var fs = require('fs'),
+    path = require('path'),
+    util = require('./src/util'),
+    asyncblock = require('asyncblock'),
+    platforms = require('./platforms');
+
+// Simply detects whether all platform libs have been cloned.
+
+asyncblock(function(flow) {
+    platforms.forEach(function(p) {
+        if (!fs.existsSync(path.join(__dirname, 'lib', p))) {
+            util.getPlatformLib(p, flow);
+        }
+    });
+    process.exit(0);
+});
+


Mime
View raw message