You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ka...@apache.org on 2014/07/11 22:00:59 UTC

git commit: CB-6512: platform add was using wrong www/cordova.js

Repository: cordova-lib
Updated Branches:
  refs/heads/master a4c780ac2 -> 3695d6fef


CB-6512: platform add <path> was using wrong www/cordova.js

cordova prepare nukes the www dir under platform on each prepare, so it was
using www/cordova.js from the cached platfrom files to restore it. For this to
work, prepare was starting with a lazy_load(platform) to make sure it has the
platform files cached.

For the case of platform add <path> this was downloading a stock version of
platform files instead of using the ones in <path>.

Some time ago see CB-5063 cordova started keeping a copy of cordova.js under
/platfroms/<platfrom>/platfrom_www/ but the cached files were still needed for
older projects that didn't yet have platform_www.

This commit removes the lazy_load before prepare and counts on platform_www to
exist. It also adds platform_www during `platform add`.


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/3695d6fe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/3695d6fe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/3695d6fe

Branch: refs/heads/master
Commit: 3695d6fef8998929189a36681bbe1f99c13f7887
Parents: a4c780a
Author: Mark Koudritsky <ka...@gmail.com>
Authored: Fri Jul 11 15:52:29 2014 -0400
Committer: Mark Koudritsky <ka...@gmail.com>
Committed: Fri Jul 11 15:52:29 2014 -0400

----------------------------------------------------------------------
 cordova-lib/spec-cordova/prepare.spec.js | 13 +---
 cordova-lib/src/cordova/platform.js      | 21 ++++--
 cordova-lib/src/cordova/prepare.js       | 98 ++++++++++++---------------
 3 files changed, 63 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3695d6fe/cordova-lib/spec-cordova/prepare.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/prepare.spec.js b/cordova-lib/spec-cordova/prepare.spec.js
index 4842d44..475b90e 100644
--- a/cordova-lib/spec-cordova/prepare.spec.js
+++ b/cordova-lib/spec-cordova/prepare.spec.js
@@ -136,15 +136,6 @@ describe('prepare command', function() {
                 expect(err).toBeUndefined();
             }).fin(done);
         });
-        it('should invoke lazy_load for each platform to make sure platform libraries are loaded', function(done) {
-            prepare().then(function() {
-                supported_platforms.forEach(function(p) {
-                    expect(load).toHaveBeenCalledWith(project_dir, p);
-                });
-            }, function(err) {
-                expect(err).toBeUndefined();
-            }).fin(done);
-        });
         describe('plugman integration', function() {
             it('should invoke plugman.prepare after update_project', function(done) {
                 prepare().then(function() {
@@ -171,9 +162,9 @@ describe('prepare command', function() {
             });
             it('should fire after hooks through the hooker module, and pass in platforms and paths as data object', function(done) {
                 prepare('android').then(function() {
-                     expect(fire).toHaveBeenCalledWith('after_prepare', {verbose: false, platforms:['android'], options: [], paths:[path.join(project_dir, 'platforms', 'android', 'www')]});
+                    expect(fire).toHaveBeenCalledWith('after_prepare', {verbose: false, platforms:['android'], options: [], paths:[path.join(project_dir, 'platforms', 'android', 'www')]});
                 }, function(err) {
-                    expect(err).toBeUndefined();
+                    expect(err).toBeUndefined('Exception while running `prepare android`:\n' + err);
                 }).fin(done);
             });
         });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3695d6fe/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 788395c..dca8ed4 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -196,11 +196,8 @@ function update(hooks, projectRoot, targets, opts) {
         return superspawn.spawn(script, [platformPath], { stdio: 'inherit' });
     })
     .then(function() {
-         // Copy the new cordova.js from www -> platform_www.
-        var parser = new platforms[plat].parser(platformPath);
-        var platform_www = path.join(platformPath, 'platform_www');
-        shell.mkdir('-p', platform_www);
-        shell.cp('-f', path.join(parser.www_dir(), 'cordova.js'), path.join(platform_www, 'cordova.js'));
+        // Copy the new cordova.js from www -> platform_www.
+        copy_cordova_js(projectRoot, plat);
         // Leave it to the update script to log out "updated to v FOO".
     });
 }
@@ -438,6 +435,9 @@ function call_into_create(target, projectRoot, cfg, libDir, template_dir, opts)
 
     return superspawn.spawn(bin, args, opts || { stdio: 'inherit' })
     .then(function() {
+        copy_cordova_js(projectRoot, target);
+    })
+    .then(function() {
         return require('./cordova').raw.prepare(target);
     })
     .then(function() {
@@ -457,6 +457,17 @@ function call_into_create(target, projectRoot, cfg, libDir, template_dir, opts)
     });
 }
 
+
+// Copty the cordova.js file to platforms/<platform>/platform_www/
+// The www dir is nuked on each prepare so we keep cordova.js in platform_www
+function copy_cordova_js(projectRoot, platform) {
+    var platformPath = path.join(projectRoot, 'platforms', platform);
+    var parser = new platforms[platform].parser(platformPath);
+    var platform_www = path.join(platformPath, 'platform_www');
+    shell.mkdir('-p', platform_www);
+    shell.cp('-f', path.join(parser.www_dir(), 'cordova.js'), path.join(platform_www, 'cordova.js'));
+}
+
 module.exports.add = add;
 module.exports.remove = remove;
 module.exports.update = update;

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3695d6fe/cordova-lib/src/cordova/prepare.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/prepare.js b/cordova-lib/src/cordova/prepare.js
index 0615c97..9ba5610 100644
--- a/cordova-lib/src/cordova/prepare.js
+++ b/cordova-lib/src/cordova/prepare.js
@@ -29,14 +29,16 @@ var cordova_util      = require('./util'),
     shell             = require('shelljs'),
     et                = require('elementtree'),
     hooker            = require('./hooker'),
-    lazy_load         = require('./lazy_load'),
     events            = require('../events'),
     Q                 = require('q'),
     plugman           = require('../plugman/plugman');
 
 // Returns a promise.
-exports = module.exports = function prepare(options) {
+exports = module.exports = prepare;
+function prepare(options) {
     var projectRoot = cordova_util.cdProjectRoot();
+    var xml = cordova_util.projectConfig(projectRoot);
+    var cfg = new ConfigParser(xml);
 
     if (!options) {
         options = {
@@ -48,7 +50,6 @@ exports = module.exports = function prepare(options) {
 
     options = cordova_util.preProcessOptions(options);
 
-    var xml = cordova_util.projectConfig(projectRoot);
     var paths = options.platforms.map(function(p) {
         var platform_path = path.join(projectRoot, 'platforms', p);
         var parser = (new platforms[p].parser(platform_path));
@@ -59,74 +60,65 @@ exports = module.exports = function prepare(options) {
     var hooks = new hooker(projectRoot);
     return hooks.fire('before_prepare', options)
     .then(function() {
-        var cfg = new ConfigParser(xml);
+
 
         // Iterate over each added platform
         return Q.all(options.platforms.map(function(platform) {
             var platformPath = path.join(projectRoot, 'platforms', platform);
-            return lazy_load.based_on_config(projectRoot, platform)
-            .then(function(libDir) {
-                var parser = new platforms[platform].parser(platformPath),
-                    defaults_xml_path = path.join(platformPath, 'cordova', 'defaults.xml');
-                //If defaults.xml is present, overwrite platform config.xml with it
-                //Otherwise save whatever is there as defaults so it can be restored
-                //or copy project config into platform if none exists
-                if (fs.existsSync(defaults_xml_path)) {
-                    shell.cp('-f', defaults_xml_path, parser.config_xml());
-                    events.emit('verbose', 'Generating config.xml from defaults for platform "' + platform + '"');
-                } else {
-                    if(fs.existsSync(parser.config_xml())){
-                        shell.cp('-f', parser.config_xml(), defaults_xml_path);
-                    }else{
-                        shell.cp('-f',xml,parser.config_xml());
-                    }
-                }
 
-                var stagingPath = path.join(platformPath, '.staging');
-                if (fs.existsSync(stagingPath)) {
-                    events.emit('log', 'Deleting now-obsolete intermediate directory: ' + stagingPath);
-                    shell.rm('-rf', stagingPath);
+            var parser = new platforms[platform].parser(platformPath),
+                defaults_xml_path = path.join(platformPath, 'cordova', 'defaults.xml');
+            // If defaults.xml is present, overwrite platform config.xml with
+            // it Otherwise save whatever is there as defaults so it can be
+            // restored or copy project config into platform if none exists.
+            if (fs.existsSync(defaults_xml_path)) {
+                shell.cp('-f', defaults_xml_path, parser.config_xml());
+                events.emit('verbose', 'Generating config.xml from defaults for platform "' + platform + '"');
+            } else {
+                if(fs.existsSync(parser.config_xml())){
+                    shell.cp('-f', parser.config_xml(), defaults_xml_path);
+                }else{
+                    shell.cp('-f', xml, parser.config_xml());
                 }
+            }
 
-                var platform_www = path.join(platformPath, 'platform_www');
-                // Create platfom_www if project was created with older version.
-                if (!fs.existsSync(platform_www)) {
-                    shell.mkdir(platform_www);
-                    shell.cp(parser.cordovajs_path(libDir), path.join(platform_www, 'cordova.js'));
-                }
+            var stagingPath = path.join(platformPath, '.staging');
+            if (fs.existsSync(stagingPath)) {
+                events.emit('log', 'Deleting now-obsolete intermediate directory: ' + stagingPath);
+                shell.rm('-rf', stagingPath);
+            }
 
-                // Replace the existing web assets with the app master versions
-                parser.update_www();
+            // Replace the existing web assets with the app master versions
+            parser.update_www();
 
-                // Call plugman --prepare for this platform. sets up js-modules appropriately.
-                var plugins_dir = path.join(projectRoot, 'plugins');
-                events.emit('verbose', 'Calling plugman.prepare for platform "' + platform + '"');
-                plugman.prepare(platformPath, platform, plugins_dir);
+            // Call plugman --prepare for this platform. sets up js-modules appropriately.
+            var plugins_dir = path.join(projectRoot, 'plugins');
+            events.emit('verbose', 'Calling plugman.prepare for platform "' + platform + '"');
+            plugman.prepare(platformPath, platform, plugins_dir);
 
-                // Make sure that config changes for each existing plugin is in place
-                var munger = new plugman.config_changes.PlatformMunger(platform, platformPath, plugins_dir);
-                munger.reapply_global_munge();
-                munger.save_all();
+            // Make sure that config changes for each existing plugin is in place
+            var munger = new plugman.config_changes.PlatformMunger(platform, platformPath, plugins_dir);
+            munger.reapply_global_munge();
+            munger.save_all();
 
-                // Update platform config.xml based on top level config.xml
-                var platform_cfg = new ConfigParser(parser.config_xml());
-                exports._mergeXml(cfg.doc.getroot(), platform_cfg.doc.getroot(), platform, true);
+            // Update platform config.xml based on top level config.xml
+            var platform_cfg = new ConfigParser(parser.config_xml());
+            exports._mergeXml(cfg.doc.getroot(), platform_cfg.doc.getroot(), platform, true);
 
-                // CB-6976 Windows Universal Apps. For smooth transition and to prevent mass api failures
-                // we allow using windows8 tag for new windows platform
-                if (platform == 'windows') {
-                    exports._mergeXml(cfg.doc.getroot(), platform_cfg.doc.getroot(), 'windows8', true);
-                }
+            // CB-6976 Windows Universal Apps. For smooth transition and to prevent mass api failures
+            // we allow using windows8 tag for new windows platform
+            if (platform == 'windows') {
+                exports._mergeXml(cfg.doc.getroot(), platform_cfg.doc.getroot(), 'windows8', true);
+            }
 
-                platform_cfg.write();
+            platform_cfg.write();
 
-                return parser.update_project(cfg);
-            });
+            return parser.update_project(cfg);
         })).then(function() {
             return hooks.fire('after_prepare', options);
         });
     });
-};
+}
 
 var BLACKLIST = ['platform'];
 var SINGLETONS = ['content', 'author'];