cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [16/43] git commit: Fix `cordova prepare` now that plugin assets are copied on (un)install
Date Thu, 09 May 2013 23:00:18 GMT
Fix `cordova prepare` now that plugin assets are copied on (un)install

This change introduces a new platform/foo/.staging/www directory, into
which plugin assets are installed by plugman. cordova prepare copies
these on top of the platform-specific www directory.

The platform-specific www directories are still deleted and recreated on
every prepare.

Uninstallation is working, plugman tests are passing, CLI tests are
broken but this change isn't the problem.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/2a5407e8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/2a5407e8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/2a5407e8

Branch: refs/heads/master
Commit: 2a5407e8bf840c9f004eab7a147fd69824409167
Parents: 655776c
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Wed May 8 15:26:31 2013 -0400
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Wed May 8 17:17:41 2013 -0400

----------------------------------------------------------------------
 src/metadata/android_parser.js    |   14 ++++++++++++++
 src/metadata/blackberry_parser.js |   14 ++++++++++++++
 src/metadata/ios_parser.js        |   14 ++++++++++++++
 src/platform.js                   |   10 +++++-----
 src/plugin.js                     |   19 +++++++++++++------
 src/prepare.js                    |    9 +--------
 6 files changed, 61 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index 70e952a..be3015c 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -126,6 +126,10 @@ module.exports.prototype = {
         return path.join(this.path, 'assets', 'www');
     },
 
+    staging_dir: function() {
+        return path.join(this.path, '.staging', 'www');
+    },
+
     update_www:function() {
         var projectRoot = util.isCordova(this.path);
         var www = util.projectWww(projectRoot);
@@ -151,11 +155,21 @@ module.exports.prototype = {
         }
     },
 
+    // update the overrides folder into the www folder
+    update_staging:function() {
+        var projectRoot = util.isCordova(this.path);
+        if (fs.existsSync(this.staging_dir())) {
+            var staging = path.join(this.staging_dir(), '*');
+            shell.cp('-rf', staging, this.www_dir());
+        }
+    },
+
     update_project:function(cfg, callback) {
         var platformWww = path.join(this.path, 'assets');
         this.update_from_config(cfg);
         this.update_www();
         this.update_overrides();
+        this.update_staging();
         // delete any .svn folders copied over
         util.deleteSvnFolders(platformWww);
         if (callback) callback();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 5bd6d84..16fcbad 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -64,6 +64,7 @@ module.exports.prototype = {
         self.update_from_config(cfg);
         self.update_www();
         self.update_overrides();
+        self.update_staging();
         util.deleteSvnFolders(this.www_dir());
 
         // Do we have BB config?
@@ -89,6 +90,10 @@ module.exports.prototype = {
         return path.join(this.path, 'www');
     },
 
+    staging_dir: function() {
+        return path.join(this.path, '.staging', 'www');
+    },
+
     update_www:function() {
         var projectRoot = util.isCordova(this.path);
         var www = util.projectWww(projectRoot);
@@ -129,6 +134,15 @@ module.exports.prototype = {
         }
     },
 
+    // update the overrides folder into the www folder
+    update_staging:function() {
+        var projectRoot = util.isCordova(this.path);
+        if (fs.existsSync(this.staging_dir())) {
+            var staging = path.join(this.staging_dir(), '*');
+            shell.cp('-rf', staging, this.www_dir());
+        }
+    },
+
     write_project_properties:function() {
         // TODO: eventually support all blackberry sub-platforms
         var projectRoot = util.isCordova(this.path);

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index e3b19fd..5e83ed3 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -137,6 +137,10 @@ module.exports.prototype = {
         return path.join(this.path, 'www');
     },
 
+    staging_dir: function() {
+        return path.join(this.path, '.staging', 'www');
+    },
+
     update_www:function() {
         var projectRoot = util.isCordova(this.path);
         var www = util.projectWww(projectRoot);
@@ -163,11 +167,21 @@ module.exports.prototype = {
         }
     },
 
+    // update the overrides folder into the www folder
+    update_staging:function() {
+        var projectRoot = util.isCordova(this.path);
+        if (fs.existsSync(this.staging_dir())) {
+            var staging = path.join(this.staging_dir(), '*');
+            shell.cp('-rf', staging, this.www_dir());
+        }
+    },
+
     update_project:function(cfg, callback) {
         var self = this;
         this.update_from_config(cfg, function() {
             self.update_www();
             self.update_overrides();
+            self.update_staging();
             util.deleteSvnFolders(self.www_dir());
             if (callback) callback();
         });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 587e687..1e51c6c 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -26,6 +26,7 @@ var config_parser     = require('./config_parser'),
     android_parser    = require('./metadata/android_parser'),
     ios_parser        = require('./metadata/ios_parser'),
     blackberry_parser = require('./metadata/blackberry_parser'),
+    plugman           = require('plugman'),
     shell             = require('shelljs');
 
 var parsers = {
@@ -107,12 +108,11 @@ module.exports = function platform(command, targets, callback) {
                                 var pluginsDir = path.join(projectRoot, 'plugins');
                                 var plugins = fs.readdirSync(pluginsDir);
                                 plugins && plugins.forEach(function(plugin) {
-                                    var cli = path.join(__dirname, '..', 'node_modules',
'plugman', 'main.js');
-                                    var cmd = util.format('"%s" --platform "%s" --project
"%s" --plugin "%s" --plugins_dir "%s"', cli, target, output, path.basename(plugin), pluginsDir);
-                                    var result = shell.exec(cmd, { silent: true });
-                                    if (result.code > 0) {
-                                        throw new Error('An error occurred while installing
the ' + path.basename(plugin) + ' plugin: ' + result.output);
+                                    if (!fs.statSync(path.join(projectRoot, 'plugins', plugin)).isDirectory())
{
+                                        return;
                                     }
+
+                                    plugman.install(target, output, path.basename(plugin),
pluginsDir, {}, parser.staging_dir());
                                 });
                                 end();
                             });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 9f3138d..355157d 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -24,12 +24,16 @@ var cordova_util  = require('./util'),
     shell         = require('shelljs'),
     config_parser = require('./config_parser'),
     hooker        = require('./hooker'),
-    core_platforms= require('../platforms'),
-    platform      = require('./platform'),
     plugin_parser = require('./plugin_parser'),
     ls            = fs.readdirSync,
     plugman       = require('plugman');
 
+var parsers = {
+    "android": require('./metadata/android_parser'),
+    "ios": require('./metadata/ios_parser'),
+    "blackberry": require('./metadata/blackberry_parser')
+};
+
 module.exports = function plugin(command, targets, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
@@ -84,10 +88,11 @@ module.exports = function plugin(command, targets, callback) {
                 plugman.fetch(target, pluginsDir, false);
                 
                 // Iterate over all platforms in the project and install the plugin.
-                // TODO add cli_variables if it's important (last argument) ?
                 platforms.forEach(function(platform) {
-                    plugman.install(platform, path.join(projectRoot, 'platforms', platform),

-                                    names[index], pluginsDir, {});
+                    var platformRoot = path.join(projectRoot, 'platforms', platform);
+                    var parser = new parsers[platform](platformRoot);
+                    plugman.install(platform, platformRoot,
+                                    names[index], pluginsDir, {}, parser.staging_dir());
                 });
 
                 hooks.fire('after_plugin_add');
@@ -118,7 +123,9 @@ module.exports = function plugin(command, targets, callback) {
                     // If this is a web-only plugin with no platform tags, this step
                     // is not needed and we just --remove the plugin below.
                     intersection.forEach(function(platform) {
-                        plugman.uninstall(platform, path.join(projectRoot, 'platforms', platform),
targetName, path.join(projectRoot, 'plugins'));
+                        var platformRoot = path.join(projectRoot, 'platforms', platform);
+                        var parser = new parsers[platform](platformRoot);
+                        plugman.uninstall(platform, platformRoot, targetName, path.join(projectRoot,
'plugins'), {}, parser.staging_dir());
                     });
 
                     // Finally remove the plugin dir from plugins/

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/2a5407e8/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index 0b6d060..06a6a18 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -75,13 +75,6 @@ module.exports = function prepare(platforms, callback) {
     platforms.forEach(function(platform) {
         var platformPath = path.join(projectRoot, 'platforms', platform);
         var parser = new parsers[platform](platformPath);
-        parser.update_project(cfg, function() {
-            // Call plugman --prepare for each platform.
-            var cmd = util.format('%s --prepare --platform "%s" --project "%s" --www "%s"
--plugins_dir "%s"', cli, platform, platformPath, parser.www_dir(), path.join(projectRoot,
'plugins'));
-            var plugman_call = shell.exec(cmd, {silent:true});
-            if (plugman_call.code > 0) throw new Error('An error occurred during plugman
--prepare for ' + platform + ': ' + plugman_call.output);
-
-            end();
-        });
+        parser.update_project(cfg, end);
     });
 };


Mime
View raw message