ripple-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brentlint...@apache.org
Subject [1/2] git commit: Fix RIPPLE-61: search for locally installed cordova module before expecting to find it globally installed
Date Thu, 26 Jun 2014 13:52:35 GMT
Repository: incubator-ripple
Updated Branches:
  refs/heads/master b008bcec9 -> 62b454393


Fix RIPPLE-61: search for locally installed cordova module before expecting to find it globally
installed


Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/036e0ef6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/036e0ef6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/036e0ef6

Branch: refs/heads/master
Commit: 036e0ef6253b90241ab05f29f180591fdaeaf874
Parents: 2e208dc
Author: Marko Raatikka <make@kapsi.fi>
Authored: Thu May 15 16:58:07 2014 +0300
Committer: Marko Raatikka <make@kapsi.fi>
Committed: Thu May 15 16:58:07 2014 +0300

----------------------------------------------------------------------
 lib/server/emulate/hosted.js | 54 ++++++++++++++++++++++++++++-----------
 1 file changed, 39 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/036e0ef6/lib/server/emulate/hosted.js
----------------------------------------------------------------------
diff --git a/lib/server/emulate/hosted.js b/lib/server/emulate/hosted.js
index 515262f..44cd4e8 100644
--- a/lib/server/emulate/hosted.js
+++ b/lib/server/emulate/hosted.js
@@ -124,6 +124,17 @@ function remoteInjection(opts) {
 }
 
 function localInjection() {
+
+    var cordovaPrepare;
+
+    try {
+        cordovaPrepare = require.resolve('cordova') ? require('cordova/src/prepare') : null;
+    }
+    catch (e) {
+        console.log('INFO: '.green +
+            'Could not find cordova as a local module. Expecting to find it installed globally.');
+    }
+
     function inject(file, req, res) {
         fs.readFile(file, "utf-8", function (err, data) {
             if (err) { throw new Error(err); }
@@ -161,23 +172,36 @@ function localInjection() {
     }
 
     return function (req, res, next) {
+
+        var callback = function (err) {
+            if (err) {
+                console.error('Failed to execute command: cordova prepare. '.red +
+                    'Make sure you\'ve installed cordova.'.red);
+            }
+
+            // make ripple compatible with phonegap
+            // as of version 3.0 phonegap uses phonegap.js instead of cordova.js
+            // but the files are identical
+            if (req.query.phonegap) {
+                var path = './platforms/' + req.staticPlatform + '/assets/www';
+                fs.readFile(path + '/cordova.js', function(err, data) {
+                    if(err) throw err;
+                    console.log('... copying cordova.js to phonegap.js');
+                    fs.writeFileSync(path + '/phonegap.js', data);
+                });
+            }
+            console.log('... done.');
+            handle(req, res, next);
+        };
+
         if (req.query.enableripple && req.staticPlatform) {
             console.log('refreshing project (platform: ' + req.staticPlatform + ') ...');
-            exec('cordova prepare ' + req.staticPlatform, function () {
-                // make ripple compatible with phonegap
-                // as of version 3.0 phonegap uses phonegap.js instead of cordova.js
-                // but the files are identical
-                if(req.query.phonegap) {
-                    var path = './platforms/' + req.staticPlatform + '/assets/www';
-                    fs.readFile(path + '/cordova.js', function(err, data) {
-                        if(err) throw err;
-                        console.log('... copying cordova.js to phonegap.js');
-                        fs.writeFileSync(path + '/phonegap.js', data);
-                    });
-                }
-                console.log('... done.');
-                handle(req, res, next);
-            });
+            if (!!cordovaPrepare) {
+                cordovaPrepare({ platforms: [ req.staticPlatform ] }).then(callback).done();
+            }
+            else {
+                exec('cordova prepare ' + req.staticPlatform, callback);
+            }
         }
         else {
             handle(req, res, next);


Mime
View raw message