You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2014/03/04 01:12:37 UTC
js commit: updating transform/bundler/packager
Repository: cordova-js
Updated Branches:
refs/heads/browserify 26a9f98a3 -> f6931d64b
updating transform/bundler/packager
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/f6931d64
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/f6931d64
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/f6931d64
Branch: refs/heads/browserify
Commit: f6931d64be723f58bf0aa7a7741430189f57f669
Parents: 26a9f98
Author: Anis Kadri <an...@apache.org>
Authored: Mon Mar 3 16:12:23 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Mar 3 16:12:23 2014 -0800
----------------------------------------------------------------------
tasks/lib/bundle-browserify.js | 1 -
tasks/lib/packager-browserify.js | 15 ++++++
tasks/lib/require-tr.js | 97 ++++++++++++++++++++---------------
3 files changed, 72 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/f6931d64/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
index 85da8dd..1d948fa 100644
--- a/tasks/lib/bundle-browserify.js
+++ b/tasks/lib/bundle-browserify.js
@@ -20,7 +20,6 @@ var fs = require('fs');
var path = require('path');
var browserify = require('browserify');
var require_tr = require('./require-tr');
-var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');
var root = path.join(__dirname, '..', '..')
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/f6931d64/tasks/lib/packager-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/packager-browserify.js b/tasks/lib/packager-browserify.js
index ecc8e9d..07d7774 100644
--- a/tasks/lib/packager-browserify.js
+++ b/tasks/lib/packager-browserify.js
@@ -18,8 +18,11 @@
*/
var fs = require('fs');
var path = require('path');
+var util = require('util');
var bundle = require('./bundle-browserify');
var computeCommitId = require('./compute-commit-id');
+var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');
+var require_tr = require('./require-tr');
module.exports = function generate(platform, useWindowsLineEndings, done) {
@@ -45,7 +48,19 @@ module.exports = function generate(platform, useWindowsLineEndings, done) {
outReleaseFile = path.join('pkg', 'cordova.' + platform + '.js');
outReleaseFileStream = fs.createWriteStream(outReleaseFile);
+
+ // some poppycock
+ var licenseText = util.format("/*\n *%s\n */\n", fs.readFileSync(licensePath, 'utf8').replace(/\n/g, "\n *"));
+
+ outReleaseFileStream.write("// Platform: " + platform + "\n", 'utf8');
+ outReleaseFileStream.write("// " + commitId + "\n", 'utf8');
+ outReleaseFileStream.write(licenseText, 'utf8');
+ outReleaseFileStream.write("var CORDOVA_JS_BUILD_LABEL = '" + commitId + "';\n", 'utf8');
+ outReleaseFileStream.write("var define = {moduleMap: []};\n", 'utf8');
+
releaseBundle = libraryRelease.bundle();
+ //console.log(libraryRelease.deps());
+
releaseBundle.pipe(outReleaseFileStream);
releaseBundle.on('end', function() {
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/f6931d64/tasks/lib/require-tr.js
----------------------------------------------------------------------
diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js
index 5629e80..2c347a3 100644
--- a/tasks/lib/require-tr.js
+++ b/tasks/lib/require-tr.js
@@ -30,6 +30,37 @@ var through = require('through');
var UglifyJS = require('uglify-js');
var root = fs.realpathSync(path.join(__dirname, '..', '..'));
+
+var requireTr = {
+
+ transform: function(file) {
+ var data = '';
+
+ function write(buf) {
+ data += buf;
+ }
+
+ function end() {
+ // getting rid of define and require properties of cordova
+ // if(file.match(/cordova.js$/)) {
+ // data = data.replace(/ *(define:define|require:require),\n/, '');
+ // }
+ this.queue(_updateRequires(data));
+ this.queue(null);
+ }
+
+ return through(write, end);
+ },
+ getSymbolList: function() {
+ return this.symbolList;
+ },
+ platform: null,
+ symbolList: []
+}
+
+/*
+ * visits AST and modifies all the require('cordova/*')
+ */
function _updateRequires(code) {
var ast = UglifyJS.parse(code);
@@ -39,28 +70,32 @@ function _updateRequires(code) {
// check all function calls
if(node instanceof UglifyJS.AST_Call) {
// check if function call is a require('module') call
- if(node.expression.name === "require") {
+ if(node.expression.name === "require" && node.args.length === 1) {
+ var module = node.args[0].value;
// make sure require only has one argument and that it starts with cordova (old style require.js)
- 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");
- // android and amazon-fireos
- } 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\/(.+)/,
- path.join(root, "src", "common", "$1"));
+ if(module !== undefined &&
+ module.indexOf("cordova") === 0) {
+
+ // adding symbolList bullcrap
+ if(requireTr.symbolList && requireTr.symbolList.indexOf(module) === -1) {
+ requireTr.symbolList.push(module);
+ }
+
+ // require('cordova') -> cordova.js
+ if(module === "cordova") {
+ node.args[0].value = path.join(root, "src", "cordova_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)\/(.+)/,
+ 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"));
+ // require('cordova/anything') should be under common/
+ } else if(module.match(/cordova\/(.+)/)) {
+ node.args[0].value = module.replace(/cordova\/(.+)/,
+ path.join(root, "src", "common", "$1"));
}
}
}
@@ -77,22 +112,4 @@ function _updateRequires(code) {
}
-module.exports = {
-
- transform: function(file) {
- var data = '';
-
- function write(buf) {
- data += buf;
- }
-
- function end() {
- //fs.appendFileSync('/tmp/foo', _updateRequires(data));
- this.queue(_updateRequires(data));
- this.queue(null);
- }
-
- return through(write, end);
- },
- platform: ""
-}
+module.exports = requireTr;