cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [4/4] git commit: performance improvement and fixed too many files open problem
Date Tue, 06 May 2014 01:21:44 GMT
performance improvement and fixed too many files open problem


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

Branch: refs/heads/browserify
Commit: 17ae9332beaf6f1a92b63ba266ea51c12d5fb07b
Parents: 72ea55e
Author: Anis Kadri <anis@apache.org>
Authored: Mon May 5 18:21:29 2014 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Mon May 5 18:21:29 2014 -0700

----------------------------------------------------------------------
 npm-shrinkwrap.json       |   2 +-
 src/install.js            |  11 ++--
 src/prepare-browserify.js | 111 ++++++++++++++++++++++-------------------
 3 files changed, 67 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/17ae9332/npm-shrinkwrap.json
----------------------------------------------------------------------
diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json
index 6fc6a48..17e7368 100644
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -7,7 +7,7 @@
       "from": "bplist-parser@0.0.5"
     },
     "cordova-js": {
-      "version": "3.5.3",
+      "version": "3.6.0",
       "from": "cordova-js@"
     },
     "dep-graph": {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/17ae9332/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index cce145d..bf249c7 100644
--- a/src/install.js
+++ b/src/install.js
@@ -300,7 +300,7 @@ var runInstall = module.exports.runInstall = function runInstall(actions,
platfo
                 copyPlugin(plugin_dir, plugins_dir, options.link);
             }
 
-            return handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir,
install_plugin_dir, filtered_variables, options.www_dir, options.is_top_level);
+            return handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir,
install_plugin_dir, filtered_variables, options);
         }
     ).fail(
         function (error) {
@@ -491,13 +491,12 @@ function installDependency(dep, install, options) {
     };
 }
 
-function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir,
plugin_dir, filtered_variables, www_dir, is_top_level) {
-
+function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir,
plugin_dir, filtered_variables, options) {
     // @tests - important this event is checked spec/install.spec.js
     events.emit('verbose', 'Install start for "' + plugin_id + '" on ' + platform + '.');
 
     var handler = platform_modules[platform];
-    www_dir = www_dir || handler.www_dir(project_dir);
+    www_dir = options.www_dir || handler.www_dir(project_dir);
 
     var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
     var assets = plugin_et.findall('asset');
@@ -553,9 +552,9 @@ function handleInstall(actions, plugin_id, plugin_et, platform, project_dir,
plu
     return actions.process(platform, project_dir)
     .then(function(err) {
         // queue up the plugin so prepare knows what to do.
-        config_changes.add_installed_plugin_to_prepare_queue(plugins_dir, plugin_id, platform,
filtered_variables, is_top_level);
+        config_changes.add_installed_plugin_to_prepare_queue(plugins_dir, plugin_id, platform,
filtered_variables, options.is_top_level);
         // call prepare after a successful install
-        plugman.prepare(project_dir, platform, plugins_dir, www_dir);
+        plugman.prepare(project_dir, platform, plugins_dir, www_dir, options.is_top_level);
 
         events.emit('verbose', 'Install complete for ' + plugin_id + ' on ' + platform +
'.');
         // WIN!

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/17ae9332/src/prepare-browserify.js
----------------------------------------------------------------------
diff --git a/src/prepare-browserify.js b/src/prepare-browserify.js
index 4fc764e..fd94210 100644
--- a/src/prepare-browserify.js
+++ b/src/prepare-browserify.js
@@ -38,22 +38,7 @@ var platform_modules   = require('./platforms'),
     requireTr          = require('cordova-js/tasks/lib/require-tr'),
     writeLicenseHeader = require('cordova-js/tasks/lib/write-license-header');
 
-// Called on --prepare.
-// Sets up each plugin's Javascript code to be loaded properly.
-// Expects a path to the project (platforms/android in CLI, . in plugman-only),
-// a path to where the plugins are downloaded, the www dir, and the platform ('android',
'ios', etc.).
-module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_dir) {
-    // Process:
-    // - Do config munging by calling into config-changes module
-    // - List all plugins in plugins_dir
-    // - Load and parse their plugin.xml files.
-    // - Skip those without support for this platform. (No <platform> tags means JS-only!)
-    // - Build a list of all their js-modules, including platform-specific js-modules.
-    // - For each js-module (general first, then platform) build up an object storing the
path and any clobbers, merges and runs for it.
-    events.emit('verbose', 'Preparing ' + platform + ' browserify project');
-    var platform_json = config_changes.get_platform_json(plugins_dir, platform);
-    var wwwDir = www_dir || platform_modules[platform].www_dir(project_dir);
-
+function uninstallQueuedPlugins(platform_json) {
     // Check if there are any plugins queued for uninstallation, and if so, remove any of
their plugin web assets loaded in
     // via <js-module> elements
     var plugins_to_uninstall = platform_json.prepare_queue.uninstalled;
@@ -70,10 +55,58 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
             });
         }
     }
+}
+
+function generateFinalBundle(platform, libraryRelease, outReleaseFile) {
+
+    var outReleaseFileStream = fs.createWriteStream(outReleaseFile);
+    var commitId = 'N/A';
+    var time = new Date().valueOf();
+
+    writeLicenseHeader(outReleaseFileStream, platform, commitId);
+    
+    releaseBundle = libraryRelease.bundle();
+
+    releaseBundle.pipe(outReleaseFileStream);
+
+    outReleaseFileStream.on('finish', function() {
+      var newtime = new Date().valueOf() - time;
+      plugman.emit('verbose', 'generated cordova.' + platform + '.js @ ' + commitId + ' in
' + newtime + 'ms');
+      // TODO clean up all the *.browserify files
+    });
+
+    outReleaseFileStream.on('error', function(err) {
+      var newtime = new Date().valueOf() - time;
+      console.log('error while generating cordova_b.js');
+      plugman.emit('verbose', 'error while generating cordova.js');
+    });
+
+}
+
+// Called on --prepare.
+// Sets up each plugin's Javascript code to be loaded properly.
+// Expects a path to the project (platforms/android in CLI, . in plugman-only),
+// a path to where the plugins are downloaded, the www dir, and the platform ('android',
'ios', etc.).
+module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_dir, is_top_level)
{
+    // Process:
+    // - Do config munging by calling into config-changes module
+    // - List all plugins in plugins_dir
+    // - Load and parse their plugin.xml files.
+    // - Skip those without support for this platform. (No <platform> tags means JS-only!)
+    // - Build a list of all their js-modules, including platform-specific js-modules.
+    // - For each js-module (general first, then platform) build up an object storing the
path and any clobbers, merges and runs for it.
+    events.emit('verbose', 'Preparing ' + platform + ' browserify project');
+    var platform_json = config_changes.get_platform_json(plugins_dir, platform);
+    var wwwDir = www_dir || platform_modules[platform].www_dir(project_dir);
+    var scripts = [];
+
+    uninstallQueuedPlugins(platform_json);
 
     events.emit('verbose', 'Processing configuration changes for plugins.');
     config_changes.process(plugins_dir, project_dir, platform);
 
+    if(!is_top_level) return;
+
     requireTr.platform = platform;
     var libraryRelease = bundle(platform, false, 'N/A');
 
@@ -111,7 +144,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
         assets.forEach(function(asset) {
             common.asset.install(asset, pluginDir, wwwDir);
         });
-
         jsModules.forEach(function(module) {
             // Copy the plugin's files into the www directory.
             // NB: We can't always use path.* functions here, because they will use platform
slashes.
@@ -127,58 +159,37 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
             if (module.attrib.name) {
                 moduleName += module.attrib.name;
             } else {
-             // var result = module.attrib.src.match(/([^\/]+)\.js/);
-             // moduleName += result[1];
-              moduleName = path.basename(module.attrib.src, '.js');
+                moduleName = path.basename(module.attrib.src, '.js');
             }
 
             var fsPath = path.join.apply(path, pathParts);
             var scriptPath = path.join(pluginDir, fsPath);
 
-            var bScriptPath = util.format("%s.%s", scriptPath, 'browserify');
-            requireTr.addModule({symbol: new RegExp(moduleName), path: bScriptPath});
+            requireTr.addModule({symbol: new RegExp(moduleName), path: scriptPath});
 
-            // Loop over the children of the js-module tag, collecting clobbers, merges and
runs.
             module.getchildren().forEach(function(child) {
                 if (child.tag.toLowerCase() == 'clobbers') {
-                    fs.appendFileSync(bScriptPath,
+                    fs.appendFileSync(scriptPath,
                       prepareNamespace(child.attrib.target, 'c'),
                       'utf-8');
                 } else if (child.tag.toLowerCase() == 'merges') {
-                    fs.appendFileSync(bScriptPath,
+                    fs.appendFileSync(scriptPath,
                       prepareNamespace(child.attrib.target, 'm'),
                       'utf-8');
-                    /* end browserify guettho clobber */
                 }
             });
-
-            /* begin browserify */
-            libraryRelease.transform(requireTr.transform);
-            libraryRelease.add(bScriptPath);
-            /* end browserify */
+            scripts.push(scriptPath);
         });
     });
-
-    var outReleaseFile = path.join(wwwDir, 'cordova.js');
-    var outReleaseFileStream = fs.createWriteStream(outReleaseFile);
-    var commitId = 'N/A';
-    var time = new Date().valueOf();
-
-    writeLicenseHeader(outReleaseFileStream, platform, commitId);
     
-    releaseBundle = libraryRelease.bundle();
-
-    releaseBundle.pipe(outReleaseFileStream);
+    libraryRelease.transform(requireTr.transform);
 
-    outReleaseFileStream.on('finish', function() {
-      var newtime = new Date().valueOf() - time;
-      plugman.emit('verbose', 'generated cordova.' + platform + '.js @ ' + commitId + ' in
' + newtime + 'ms');
-      // TODO clean up all the *.browserify files
+    scripts.forEach(function(script) {
+        libraryRelease.add(script);
     });
+        
+    var outReleaseFile = path.join(wwwDir, 'cordova.js');
+    
+    generateFinalBundle(platform, libraryRelease, outReleaseFile);
 
-    outReleaseFileStream.on('error', function(err) {
-      var newtime = new Date().valueOf() - time;
-      console.log('error while generating cordova_b.js');
-      plugman.emit('verbose', 'error while generating cordova.js');
-    });
 };


Mime
View raw message