cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [33/45] js commit: replacing platform/exec
Date Thu, 24 Apr 2014 21:11:18 GMT
replacing platform/exec


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

Branch: refs/heads/master
Commit: 2c300fdd19c1bc3ee121c329aa4efb8c249b7bfb
Parents: 202b92f
Author: Anis Kadri <anis@apache.org>
Authored: Mon Feb 24 19:46:57 2014 -0800
Committer: Anis Kadri <anis@apache.org>
Committed: Thu Mar 27 15:20:22 2014 +0100

----------------------------------------------------------------------
 tasks/lib/bundle-browserify.js | 25 ++-----------------------
 tasks/lib/require-tr.js        | 36 +++++++++++++++++++++++-------------
 2 files changed, 25 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/2c300fdd/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
index 0dda5d3..85da8dd 100644
--- a/tasks/lib/bundle-browserify.js
+++ b/tasks/lib/bundle-browserify.js
@@ -25,34 +25,13 @@ var root         = path.join(__dirname, '..', '..')
 
 
 module.exports = function bundle(platform, debug, commitId) {
+    require_tr.platform = platform;
     // FIXME: need to find a way to void ignore missing
     var b = browserify({debug: debug});
     // XXX plugin_list is not present at this stage 
     b.ignore(path.join(root, 'src', 'common', 'plugin_list'));
 
-   // if (platform === 'test') {
-   //     // FIXME why does 'test' resolve a bunch of android stuff?! 
-   //     var testFilesPath = path.join('src', 'android', 'android');
-   //     copyProps(modules, collectFiles(testFilesPath, 'android/'));
-   // }
-
-   // var output = [];
-	
-   // output.push("// Platform: " + platform);
-   // output.push("// "  + commitId);
-
-   // // write header
-   // output.push('/*', fs.readFileSync(licensePath, 'utf8'), '*/');
-   // output.push(';(function() {');
-   // output.push("var CORDOVA_JS_BUILD_LABEL = '"  + commitId + "';");
-
-   // // write initial scripts
-   // if (!scripts['require']) {
-   //     throw new Error("didn't find a script for 'require'")
-   // }
-    
-   // writeScript(output, scripts['require'], debug)
-    b.transform(require_tr);
+    b.transform(require_tr.transform);
 
     b.add(path.join(root, 'src', platform, 'exec.js'));
     

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/2c300fdd/tasks/lib/require-tr.js
----------------------------------------------------------------------
diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js
index ba8bd53..5629e80 100644
--- a/tasks/lib/require-tr.js
+++ b/tasks/lib/require-tr.js
@@ -35,15 +35,16 @@ function _updateRequires(code) {
   var ast = UglifyJS.parse(code);
 
   var walker = new UglifyJS.TreeWalker(function(node) {
+
     // check all function calls
     if(node instanceof UglifyJS.AST_Call) {
       // check if function call is a require('module') call
       if(node.expression.name === "require") {
         // make sure require only has one argument and that it starts with cordova (old style
require.js) 
-        //fs.appendFileSync('/tmp/foo', JSON.stringify(node.args[0]) + "###\n");
         if(node.args.length === 1 && 
            node.args[0].value !== undefined &&
            node.args[0].value.indexOf("cordova") === 0) {
+          //fs.appendFileSync('/tmp/foo', JSON.stringify(node.args[0].value) + "\n###\n");
           // cordova.js
           if(node.args[0].value === "cordova") {
             node.args[0].value = path.join(root, "src", "cordova");
@@ -51,6 +52,11 @@ function _updateRequires(code) {
           } else if(node.args[0].value.match(/cordova\/(android|amazon-fireos)\/(.+)/)) {
             node.args[0].value = node.args[0].value.replace(/cordova\/(android|amazon-fireos)\/(.+)/,
                                  path.join(root, "src", "$1", "android", "$2"));
+          // replace common exec/platform with the platform's exec/platform
+          } else if(node.args[0].value.match(/cordova\/(platform|exec)$/)) {
+            //fs.appendFileSync('/tmp/foo', node.args[0].value + "\n" +module.exports.platform
+ "\n");
+            node.args[0].value = node.args[0].value.replace(/cordova\/(platform|exec)/,
+                                 path.join(root, "src", module.exports.platform, "$1"));
           // everything else
           } else if(node.args[0].value.match(/cordova\/(.+)/)) {
             node.args[0].value = node.args[0].value.replace(/cordova\/(.+)/,
@@ -71,18 +77,22 @@ function _updateRequires(code) {
 }
 
 
-module.exports = function(file) {
-  var data = '';
+module.exports = {
+
+  transform: function(file) {
+    var data = '';
 
-  function write(buf) {
-    data += buf;
-  }
+    function write(buf) {
+      data += buf;
+    }
 
-  function end() {
-    //fs.appendFileSync('/tmp/foo', _updateRequires(data));
-    this.queue(_updateRequires(data));
-    this.queue(null);
-  }
- 
-  return through(write, end);
+    function end() {
+      //fs.appendFileSync('/tmp/foo', _updateRequires(data));
+      this.queue(_updateRequires(data));
+      this.queue(null);
+    }
+   
+    return through(write, end);
+  },
+  platform: ""
 }


Mime
View raw message