cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [2/2] cordova-lib git commit: CB-9549 Removes excess JS files from browserified app
Date Tue, 25 Aug 2015 07:47:16 GMT
CB-9549 Removes excess JS files from browserified app


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

Branch: refs/heads/master
Commit: fe517618c44c1c856b728dfb584c83efb9515235
Parents: ffe3cee
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Mon Aug 24 14:20:42 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Mon Aug 24 14:26:53 2015 +0300

----------------------------------------------------------------------
 cordova-lib/src/cordova/prepare.js            | 20 ++++++++++-----
 cordova-lib/src/plugman/prepare-browserify.js | 30 +++++++++++++---------
 2 files changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fe517618/cordova-lib/src/cordova/prepare.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/prepare.js b/cordova-lib/src/cordova/prepare.js
index 797200b..9e27833 100644
--- a/cordova-lib/src/cordova/prepare.js
+++ b/cordova-lib/src/cordova/prepare.js
@@ -106,27 +106,35 @@ function prepare(options) {
             if (options.browserify) {
                 plugman.prepare = require('../plugman/prepare-browserify');
             }
-            
-            return plugman.prepare(platformPath, platform, plugins_dir, null, true, pluginInfoProvider).then(function
() {              
+
+            return plugman.prepare(platformPath, platform, plugins_dir, null, true, pluginInfoProvider)
+            .then(function () {
+                // Remove cordova-js-src from application www directory
+                // otherwise it will be included into resultant app bundle
+                var cordovaJsSrcPath = path.join(platformPath, 'www/cordova-js-src');
+                if(fs.existsSync(cordovaJsSrcPath)) {
+                    shell.rm('-rf', cordovaJsSrcPath);
+                }
+            }).then(function () {
                 // Make sure that config changes for each existing plugin is in place
                 var platformJson = PlatformJson.load(plugins_dir, platform);
                 var munger = new PlatformMunger(platform, platformPath, plugins_dir, platformJson,
pluginInfoProvider);
                 munger.reapply_global_munge();
                 munger.save_all();
-    
+
                 // Update platform config.xml based on top level config.xml
                 var cfg = new ConfigParser(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);
                 }
-    
+
                 platform_cfg.write();
-    
+
                 return parser.update_project(cfg);
             });
         })).then(function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fe517618/cordova-lib/src/plugman/prepare-browserify.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/prepare-browserify.js b/cordova-lib/src/plugman/prepare-browserify.js
index 39d44ac..2dfb26a 100644
--- a/cordova-lib/src/plugman/prepare-browserify.js
+++ b/cordova-lib/src/plugman/prepare-browserify.js
@@ -33,7 +33,8 @@ var platform_modules   = require('../platforms/platforms'),
     bundle             = require('cordova-js/tasks/lib/bundle-browserify'),
     writeLicenseHeader = require('cordova-js/tasks/lib/write-license-header'),
     Q                  = require('q'),
-    computeCommitId    = require('cordova-js/tasks/lib/compute-commit-id');
+    computeCommitId    = require('cordova-js/tasks/lib/compute-commit-id'),
+    Readable           = require('stream').Readable;
 
 var PlatformJson = require('./util/PlatformJson');
 var PluginInfoProvider = require('../PluginInfoProvider');
@@ -146,7 +147,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
 
         var pluginMetadata = {};
         var modulesMetadata = [];
-        var cordova_plugins = '';
 
         var plugins = Object.keys(platformJson.root.installed_plugins).concat(Object.keys(platformJson.root.dependent_plugins));
         events.emit('verbose', 'Iterating over installed plugins:', plugins);
@@ -183,24 +183,30 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
             });
         });
 
-        cordova_plugins += 'module.exports.metadata = \n' +
-            JSON.stringify(pluginMetadata, null, 4) + ';\n' +
-            'module.exports = \n' +
-            JSON.stringify(modulesMetadata, null, 4) + ';\n';
-
         events.emit('verbose', 'Writing out cordova_plugins.js...');
-        fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), cordova_plugins, 'utf8');
-        libraryRelease.add(path.join(wwwDir, 'cordova_plugins.js'), {expose: 'cordova/plugin_list'});
 
-        fs.writeFileSync(path.join(wwwDir, 'init.js'), 'require(\'cordova/init\');\n', 'utf8');
-        libraryRelease.add(path.resolve(wwwDir, 'init.js'));
+        // Create a stream and write plugin metadata into it
+        // instead of generating intermediate file on FS
+        var cordova_plugins = new Readable();
+        cordova_plugins.push(
+            'module.exports.metadata = ' + JSON.stringify(pluginMetadata, null, 4) + ';\n'
+
+            'module.exports = ' + JSON.stringify(modulesMetadata, null, 4) + ';\n', 'utf8');
+        cordova_plugins.push(null);
+
+        var bootstrap = new Readable();
+        bootstrap.push('require(\'cordova/init\');\n', 'utf8');
+        bootstrap.push(null);
 
         var moduleAliases = modulesMetadata
         .reduce(function (accum, meta) {
             accum['./' + meta.name] = meta.id;
             return accum;
         }, {});
-        libraryRelease.transform(aliasify, {aliases: moduleAliases, verbose: true});
+
+        libraryRelease
+            .add(cordova_plugins, {file: path.join(wwwDir, 'cordova_plugins.js'), expose:
'cordova/plugin_list'})
+            .add(bootstrap)
+            .transform(aliasify, {aliases: moduleAliases});
 
         var outReleaseFile = path.join(wwwDir, 'cordova.js');
         return generateFinalBundle(platform, libraryRelease, outReleaseFile, commitId, platformVersion);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message