Repository: cordova-js Updated Branches: refs/heads/master ab3fc0f59 -> 10ffabbd6
CB-8158 populating symbolList Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/bfd57dfc Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/bfd57dfc Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/bfd57dfc Branch: refs/heads/master Commit: bfd57dfcb3919fe46c27688a1e123367fe37009d Parents: ab3fc0f Author: Anis Kadri <a...@apache.org> Authored: Wed Dec 17 20:01:58 2014 -0800 Committer: Anis Kadri <a...@apache.org> Committed: Wed Dec 17 20:01:58 2014 -0800 ---------------------------------------------------------------------- package.json | 2 +- src/cordova_b.js | 12 ++++----- tasks/lib/require-tr.js | 45 ++++++++++++++++++++++------------ tasks/lib/write-license-header.js | 4 +-- 4 files changed, 36 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bfd57dfc/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 40a36fb..ab61fed 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "dependencies": { "uglify-js": "2.4.15", - "browserify": "3.46.0", + "browserify": "7.x.x", "through": "2.3.4" } } http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bfd57dfc/src/cordova_b.js ---------------------------------------------------------------------- diff --git a/src/cordova_b.js b/src/cordova_b.js index 35a4863..87c6852 100644 --- a/src/cordova_b.js +++ b/src/cordova_b.js @@ -95,13 +95,11 @@ var cordova = { platformVersion:PLATFORM_VERSION_BUILD_LABEL, version:PLATFORM_VERSION_BUILD_LABEL, require: function(module) { - // if(module === "cordova/exec") { - // return cordova.exec; - // } - // if(module === "org.apache.cordova.media.Media") { - // return window.Media; - // } - return require(symbolList[module].path); + for(var i = 0 ; i < symbolList.length ; i++) { + if(module === symbolList[module].symbolList) { + return require(symbolList[module].path); + } + } }, platformId:platform.id, /** http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bfd57dfc/tasks/lib/require-tr.js ---------------------------------------------------------------------- diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js index c71ab98..da874a5 100644 --- a/tasks/lib/require-tr.js +++ b/tasks/lib/require-tr.js @@ -30,11 +30,16 @@ var path = require('path'); var util = require('util'); var through = require('through'); var UglifyJS = require('uglify-js'); +var os = require('os'); var root = fs.realpathSync(path.join(__dirname, '..', '..')); - var requireTr = { + init: function(platform) { + this.platform = platform; + this.modules = []; + }, + transform: function(file) { var data = ''; @@ -76,18 +81,26 @@ var requireTr = { return through(write, end); }, + hasModule: function(module) { + for(var i = 0, j = this.modules.length ; i < j ; i++) { + if(this.modules[i].symbol === module) { + return true; + } + } + return false; + }, getModules: function() { return this.modules; }, + getPlatform: function() { + return this.platform; + }, addModule: function(module) { if(!module || !module.symbol || !module.path) { throw new Error("Can't add module without a symbol and a path"); } this.modules.push(module); - }, - platform: null, - modules: [] - + } } /* @@ -114,32 +127,32 @@ function _updateRequires(code) { // make sure require only has one argument and that it starts with cordova (old style require.js) if(module !== undefined && module.indexOf("cordova") === 0) { - - // adding symbolList bullcrap - if(requireTr.symbolList && requireTr.symbolList.indexOf(module) === -1) { - requireTr.symbolList.push(module); - } + + var scriptpath; // require('cordova') -> cordova.js if(module === "cordova") { - node.args[0].value = path.join(root, "src", "cordova_b"); + scriptPath = node.args[0].value = path.join(root, "src", "cordova_b"); // require('cordova/init') -> common/init } else if(module.match(/cordova\/init/)) { - node.args[0].value = module.replace(/cordova\/init/, + scriptPath = node.args[0].value = module.replace(/cordova\/init/, path.join(root, "src", "common", "init_b")); // android and amazon-fireos have some special require's } else if(module.match(/cordova\/(android|amazon-fireos)\/(.+)/)) { - node.args[0].value = module.replace(/cordova\/(android|amazon-fireos)\/(.+)/, + scriptPath = node.args[0].value = module.replace(/cordova\/(android|amazon-fireos)\/(.+)/, path.join(root, "src", "$1", "android", "$2")); // require('cordova/exec') and require('cordova/platform') -> platform's exec/platform } else if(module.match(/cordova\/(platform|exec)$/)) { - node.args[0].value = module.replace(/cordova\/(platform|exec)/, - path.join(root, "src", requireTr.platform, "$1")); + scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/, + path.join(root, "src", requireTr.getPlatform(), "$1")); // require('cordova/anything') should be under common/ } else if(module.match(/cordova\/(.+)/)) { - node.args[0].value = module.replace(/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}); + } } else if(module !== undefined && ( module.indexOf("org.apache.cordova") !== -1 || module.indexOf("./") === 0 || module.indexOf("../") === 0 ) ) { http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bfd57dfc/tasks/lib/write-license-header.js ---------------------------------------------------------------------- diff --git a/tasks/lib/write-license-header.js b/tasks/lib/write-license-header.js index 9c5ffe2..f88969d 100644 --- a/tasks/lib/write-license-header.js +++ b/tasks/lib/write-license-header.js @@ -33,7 +33,5 @@ module.exports = function(outStream, platform, commitId, platformVersion, symbol outStream.write("// browserify" + "\n", 'utf8'); 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;\n\n", JSON.stringify(symbolList)), 'utf8'); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org