cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [22/28] git commit: adding prepare namespace
Date Thu, 24 Apr 2014 21:14:20 GMT
adding prepare namespace


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

Branch: refs/heads/master
Commit: 8426f9afe0ec8ca4679bef1f01740f85357f3dcd
Parents: 89c2dad
Author: Anis Kadri <anis@apache.org>
Authored: Tue Apr 8 18:37:27 2014 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Fri Apr 11 12:45:45 2014 -0700

----------------------------------------------------------------------
 src/prepare.js                | 14 ++++----------
 src/util/prepare-namespace.js | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8426f9af/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index ae7f500..9940dc1 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -23,6 +23,7 @@ var platform_modules   = require('./platforms'),
     path               = require('path'),
     config_changes     = require('./util/config-changes'),
     xml_helpers        = require('./util/xml-helpers'),
+    prepareNamespace   = require('./util/prepare-namespace'),
     wp7                = require('./platforms/wp7'),
     wp8                = require('./platforms/wp8'),
     windows8           = require('./platforms/windows8'),
@@ -215,14 +216,10 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
                         obj.clobbers = [];
                     }
                     obj.clobbers.push(child.attrib.target);
-                    /* FIXME: browserify guettho clobber */
+                    //console.log(prepareNamespace(child.attrib.target, 'c'));
                     fs.appendFileSync(bScriptPath,
-                      util.format(
-                        "require('cordova/builder').assignOrWrapInDeprecateGetter(window,
'%s', module.exports);", 
-                        child.attrib.target
-                      ),
+                      prepareNamespace(child.attrib.target, 'c'),
                       'utf-8');
-                    /* end browserify guettho clobber */
                 } else if (child.tag.toLowerCase() == 'merges') {
                     if (!obj.merges) {
                         obj.merges = [];
@@ -230,10 +227,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir,
www_
                     obj.merges.push(child.attrib.target);
                     /* FIXME: browserify guettho clobber */
                     fs.appendFileSync(bScriptPath,
-                      util.format(
-                        "require('cordova/builder').recursiveMerge(window, '%s', module.exports);",

-                        child.attrib.target
-                      ),
+                      prepareNamespace(child.attrib.target, 'm'),
                       'utf-8');
                     /* end browserify guettho clobber */
                 } else if (child.tag.toLowerCase() == 'runs') {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/8426f9af/src/util/prepare-namespace.js
----------------------------------------------------------------------
diff --git a/src/util/prepare-namespace.js b/src/util/prepare-namespace.js
new file mode 100644
index 0000000..3c19d13
--- /dev/null
+++ b/src/util/prepare-namespace.js
@@ -0,0 +1,31 @@
+// FIXME this is extremely guettho
+module.exports = function(target, method) {
+  var lastDot = target.lastIndexOf('.');
+  var namespace = target.substr(0, lastDot);
+  var lastName = target.substr(lastDot + 1);
+  var props = target.split(".");
+  var code = "";
+  for(var i = 1, len = props.length ; i <= len ; i++) {
+    var sub = props.slice(0, i).join(".");
+    code += util.format("window.%s = window.%s || {};\n", sub, sub);
+  }
+  
+  props.unshift('window');  
+  var object = props.slice(0, props.length - 1).join('.');
+//  code = "\n";
+  if(method === "c") {
+    return util.format(
+      "%s\n;require('cordova/builder').assignOrWrapInDeprecateGetter(%s, '%s', module.exports);",

+      code,
+      object,
+      lastName
+    );
+  } else if(method === "m") {
+    return util.format(
+      "%s\n;require('cordova/builder').recursiveMerge(%s, '%s', module.exports);", 
+      code,
+      object,
+      lastName
+    );
+  }
+}


Mime
View raw message