cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [3/8] js commit: CB-8441 updated workflow to use cordova-js-src when available
Date Mon, 18 May 2015 23:21:01 GMT
CB-8441 updated workflow to use cordova-js-src when available


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

Branch: refs/heads/master
Commit: 100e4359a1b77b421d024323cbaaa68d74dd70cd
Parents: 994d6bb
Author: Steve Gill <stevengill97@gmail.com>
Authored: Fri May 15 17:12:55 2015 -0700
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Mon May 18 02:05:21 2015 -0700

----------------------------------------------------------------------
 tasks/lib/bundle-browserify.js    | 15 ++++++--
 tasks/lib/require-tr.js           | 69 +++++++++++++++++++++-------------
 tasks/lib/write-license-header.js |  2 +-
 3 files changed, 55 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/100e4359/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
index 668d1e9..a6b8687 100644
--- a/tasks/lib/bundle-browserify.js
+++ b/tasks/lib/bundle-browserify.js
@@ -30,11 +30,18 @@ module.exports = function bundle(platform, debug, commitId, platformVersion)
{
     // XXX plugin_list is not present at this stage 
     b.ignore(path.join(root, 'src', 'common', 'plugin_list'));
 
-    b.transform(require_tr.transform);
+    b.transform(require_tr.transform, {'platform': platform});
 
-    b.add(path.join(root, 'src', platform, 'exec.js'));
-    
-    b.add(path.join(root, 'src', platform, 'platform.js'));
+    var cordovajssrc = path.join(process.cwd(), 'platforms', platform, 'platform_www', 'cordova-js-src');
+    //checks to see if browserify is run in a cli project and
+    //if the platform has a cordova-js-src to build cordova.js with
+    if(fs.existsSync(cordovajssrc)){ 
+        b.add(path.join(cordovajssrc, 'exec.js'));
+        b.add(path.join(cordovajssrc, 'platform.js'));
+    } else {
+        b.add(path.join(root, 'src', 'legacy-exec', platform, 'exec.js'));
+        b.add(path.join(root, 'src', 'legacy-exec', platform, 'platform.js'));
+    }
 
     b.add(path.join(root, 'src', 'scripts', 'bootstrap.js'));
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/100e4359/tasks/lib/require-tr.js
----------------------------------------------------------------------
diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js
index a433b30..d8e1ff1 100644
--- a/tasks/lib/require-tr.js
+++ b/tasks/lib/require-tr.js
@@ -37,10 +37,11 @@ var requireTr = {
 
   init: function(platform) {
     this.platform = platform;
-    this.modules = [];
+    this.modules[platform] = [];
   },
 
-  transform: function(file) {
+  transform: function(file, platObj) {
+    this.platform = platObj.platform;
     var data = '';
 
     function write(buf) {
@@ -48,17 +49,18 @@ var requireTr = {
     }
 
     function end() {
-        // SOME BS pre-transforms
+      var platform = platObj.platform;
+      // SOME BS pre-transforms
       if(data.match(/clobbers\('cordova\/plugin\/android\/app/)) {
         // Checking for '\' from the windows path
         root = root.replace(/\\/g, '/');
 
         if(file.match(/android\/platform.js$/) || file.match(/android\\platform.js$/)) {
           data = data.replace(/modulemapper\.clobbers.*\n/,
-                              util.format('navigator.app = require("%s/src/android/plugin/android/app")',
root));
+                              util.format('navigator.app = require("%s/src/legacy-exec/android/plugin/android/app")',
root));
         } else if (file.match(/amazon-fireos\/platform.js$/) || file.match(/amazon-fireos\\platform.js$/))
{
           data = data.replace(/modulemapper\.clobbers.*\n/,
-                              util.format('navigator.app = require("%s/src/amazon-fireos/plugin/android/app")',
root));
+                              util.format('navigator.app = require("%s/src/legacy-exec/amazon-fireos/plugin/android/app")',
root));
         }
       }
 
@@ -75,40 +77,42 @@ var requireTr = {
                             'getOriginalSymbol(window');
       }
      
-      this.queue(_updateRequires(data));
+      this.queue(_updateRequires(data, platform));
       this.queue(null);
     }
    
     return through(write, end);
   },
-  hasModule: function(module) {
-    for(var i = 0, j = this.modules.length ; i < j ; i++) {
-      if(this.modules[i].symbol === module) {
+  hasModule: function(module, platform) {
+    if(this.modules[platform] === undefined) {
+      this.modules[platform] = [];
+    }
+    var platformModules = this.modules[platform];
+
+    for(var i = 0, j = platformModules.length ; i < j ; i++) {
+      if(platformModules[i].symbol === module) {
         return true;
       }
     }
     return false;
   },
-  getModules: function() {
-    return this.modules;
+  getModules: function(platform) {
+    return this.modules[platform];
   },
-  getPlatform: function() {
-    return this.platform;
-  },
-  addModule: function(module) {
+  addModule: function(module, platform) {
     if(!module || !module.symbol || !module.path) {
       throw new Error("Can't add module without a symbol and a path");
     }
-    this.modules.push(module);
+    this.modules[platform].push(module);
   },
-  modules:[],
+  modules:{},
   platform: null
 }
 
 /*
  * visits AST and modifies all the require('cordova/*') and require('org.apache.cordova.*')
  */
-function _updateRequires(code) {
+function _updateRequires(code, platform) {
   var ast = UglifyJS.parse(code);
 
   var before = new UglifyJS.TreeTransformer(function(node, descend) {
@@ -131,6 +135,8 @@ function _updateRequires(code) {
            module.indexOf("cordova") === 0) {
 
           var scriptpath;
+          var cordovajssrc = path.join(process.cwd(), "platforms", platform, "platform_www",
"cordova-js-src")
+
 
           // require('cordova') -> cordova.js
           if(module === "cordova") {
@@ -141,24 +147,35 @@ function _updateRequires(code) {
                                     path.join(root, "src", "common", "init_b"));
           // android and amazon-fireos have some special require's
           } else if(module.match(/cordova\/(android|amazon-fireos)\/(.+)/)) {
-            scriptPath = node.args[0].value = module.replace(/cordova\/(android|amazon-fireos)\/(.+)/,
-                                    path.join(root, "src", "$1", "android", "$2"));
+                if(fs.existsSync(cordovajssrc)) {
+                    //cordova cli project with cordova-js-src in platform
+                    scriptPath = node.args[0].value = module.replace(/cordova\/(android|amazon-fireos)\/(.+)/,
path.join(cordovajssrc, "android", "$2"));
+                } else {
+                    //non cli or no cordova-js-src directory
+                    scriptPath = node.args[0].value = module.replace(/cordova\/(android|amazon-fireos)\/(.+)/,
path.join(root, "src", "legacy-exec", "$1", "android", "$2"));
+                }
           // require('cordova/exec') and require('cordova/platform') -> platform's exec/platform
-          } else if(module.match(/cordova\/(platform|exec)$/)) {
-            scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/,
-                                                path.join(root, "src", requireTr.getPlatform(),
"$1"));
+          } else if(module.match(/cordova\/(platform|exec)$/)) {                
+                if(fs.existsSync(cordovajssrc)) {
+                    //cordova cli project with cordova-js-src in platform
+                    scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/,
path.join(cordovajssrc, "$1"));
+                } else {
+                    //non cli or no cordova-js-src directory
+                    scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/,
path.join(root, "src", "legacy-exec", platform, "$1"));
+                }
+            
           // require('cordova/anything') should be under common/
           } else if(module.match(/cordova\/(.+)/)) {
             scriptPath = node.args[0].value = module.replace(/cordova\/(.+)/,
                                     path.join(root, "src", "common", "$1"));
           }
-          if(requireTr.hasModule(module) === false) {
-            requireTr.addModule({symbol: module, path: scriptPath});
+          if(requireTr.hasModule(module, platform) === false) {
+            requireTr.addModule({symbol: module, path: scriptPath}, platform);
           }
         }
         else if(module !== undefined && ( module.indexOf("org.apache.cordova") !==
-1 ||
                                           module.indexOf("./") === 0 || module.indexOf("../")
=== 0 ) ) {
-          var modules = requireTr.getModules();
+          var modules = requireTr.getModules(platform);
 
           if(module.indexOf("../") === 0){
             module = module.replace('../', '');

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/100e4359/tasks/lib/write-license-header.js
----------------------------------------------------------------------
diff --git a/tasks/lib/write-license-header.js b/tasks/lib/write-license-header.js
index e736011..f9a394b 100644
--- a/tasks/lib/write-license-header.js
+++ b/tasks/lib/write-license-header.js
@@ -34,6 +34,6 @@ module.exports = function(outStream, platform, commitId, platformVersion,
symbol
   outStream.write(licenseText, 'utf8');
   outStream.write("var PLATFORM_VERSION_BUILD_LABEL = '"  + platformVersion + "';\n", 'utf8');
   outStream.write("var define = {moduleMap: []};\n", 'utf8');
-  // outStream.write(util.format("var symbolList = %s", JSON.stringify(symbolList)), 'utf8');
+  //outStream.write(util.format("var symbolList = %s", JSON.stringify(symbolList)), 'utf8');
 
 }


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


Mime
View raw message