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/02/04 07:23:06 UTC

[1/6] js commit: adding required libraries to browserify

Updated Branches:
  refs/heads/browserify [created] c08165e77


adding required libraries to browserify


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

Branch: refs/heads/browserify
Commit: c925386ae1dc255cca5198fa8f75184f20579ff1
Parents: 8f301f8
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:14:10 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:14:10 2014 -0800

----------------------------------------------------------------------
 package.json | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c925386a/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index cc25b9a..b0c6225 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
     },
     {
       "name": "Anis Kadri",
-      "email": ""
+      "email": "anis@apache.org"
     },
     {
       "name": "Dan Silivestru",
@@ -55,7 +55,10 @@
   ],
   "dependencies": {
     "jsdom": "0.8.2",
-    "connect": "1.8.5"
+    "connect": "1.8.5",
+    "uglify-js": "2.4.x",
+    "browserify": "3.2.0",
+    "through": "2.3.4"
   },
   "devDependencies": {
     "grunt": "~0.4.1",


[5/6] js commit: adding browserify compile task

Posted by an...@apache.org.
adding browserify compile task


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

Branch: refs/heads/browserify
Commit: bc7843ef79565c5b9748a6cea11cbccd2895b5ce
Parents: 42621ce
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:21:53 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:21:53 2014 -0800

----------------------------------------------------------------------
 tasks/compile-browserify.js | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bc7843ef/tasks/compile-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/compile-browserify.js b/tasks/compile-browserify.js
new file mode 100644
index 0000000..1d28510
--- /dev/null
+++ b/tasks/compile-browserify.js
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+var generate = require('./lib/packager-browserify');
+
+module.exports = function(grunt) {
+    grunt.registerMultiTask('compile-browserify', 'Packages cordova.js browserify style', function() {
+
+        var done = this.async();
+        var platformName = this.target;
+        var useWindowsLineEndings = this.data.useWindowsLineEndings;
+        generate(platformName, useWindowsLineEndings, done);
+    });
+}


[6/6] js commit: Adding compile-browserify grunt task

Posted by an...@apache.org.
Adding compile-browserify grunt task


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

Branch: refs/heads/browserify
Commit: c08165e77eab64f48d1f1a363072adfecdbe040e
Parents: bc7843e
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:22:14 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:22:14 2014 -0800

----------------------------------------------------------------------
 Gruntfile.js | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c08165e7/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index 683c9de..ed153bd 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -33,6 +33,9 @@ module.exports = function(grunt) {
             "ubuntu": {},
             "browser": {}
         },
+        "compile-browserify": {
+            "ios": {}
+        },
         clean: ['pkg'],
         jshint: {
             options: {


[4/6] js commit: adding browserify bundle

Posted by an...@apache.org.
adding browserify bundle


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

Branch: refs/heads/browserify
Commit: 42621ce868692caa13308120fd9e0ecf92d5c211
Parents: 565c6be
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:21:28 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:21:28 2014 -0800

----------------------------------------------------------------------
 tasks/lib/bundle-browserify.js | 62 +++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/42621ce8/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
new file mode 100644
index 0000000..3d91e42
--- /dev/null
+++ b/tasks/lib/bundle-browserify.js
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF
+ * or more contributor license agreements.  See th
+ * distributed with this work for additional infor
+ * regarding copyright ownership.  The ASF license
+ * to you under the Apache License, Version 2.0 (t
+ * "License"); you may not use this file except in
+ * with the License.  You may obtain a copy of the
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to 
+ * software distributed under the License is distr
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * KIND, either express or implied.  See the Licen
+ * specific language governing permissions and lim
+ * under the License.
+ */
+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, '..', '..')
+
+
+module.exports = function bundle(platform, debug, commitId) {
+    // FIXME: need to find a way to void ignore missing
+    var b = browserify();
+    // 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.add(path.join(root, 'src', platform, 'exec.js'));
+
+    b.add(path.join(root, 'src', 'scripts', 'bootstrap.js'));
+
+    return b;
+}


[3/6] js commit: adding browserify packager

Posted by an...@apache.org.
adding browserify 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/565c6bee
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/565c6bee
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/565c6bee

Branch: refs/heads/browserify
Commit: 565c6bee06441255492fd2030d70acccb5b9ec33
Parents: beeb953
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:21:01 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:21:01 2014 -0800

----------------------------------------------------------------------
 tasks/lib/packager-browserify.js | 59 +++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/565c6bee/tasks/lib/packager-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/packager-browserify.js b/tasks/lib/packager-browserify.js
new file mode 100644
index 0000000..299bf89
--- /dev/null
+++ b/tasks/lib/packager-browserify.js
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF
+ * or more contributor license agreements.  See th
+ * distributed with this work for additional infor
+ * regarding copyright ownership.  The ASF license
+ * to you under the Apache License, Version 2.0 (t
+ * "License"); you may not use this file except in
+ * with the License.  You may obtain a copy of the
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to 
+ * software distributed under the License is distr
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * KIND, either express or implied.  See the Licen
+ * specific language governing permissions and lim
+ * under the License.
+ */
+var fs              = require('fs');
+var path            = require('path');
+var bundle          = require('./bundle-browserify');
+var computeCommitId = require('./compute-commit-id');
+
+
+module.exports = function generate(platform, useWindowsLineEndings, callback) {
+    computeCommitId(function(commitId) {
+        var outFile, outFileStream;
+        var time = new Date().valueOf();
+
+        var libraryRelease = bundle(platform, false, commitId);
+        // if we are using windows line endings, we will also add the BOM
+        if(useWindowsLineEndings) {
+            libraryRelease = "\ufeff" + libraryRelease.split(/\r?\n/).join("\r\n");
+        }
+        //var libraryDebug   = bundle(platform, true, commitId);
+
+        time = new Date().valueOf() - time;
+        if (!fs.existsSync('pkg')) {
+            fs.mkdirSync('pkg');
+        }
+       // if(!fs.existsSync('pkg/debug')) {
+       //     fs.mkdirSync('pkg/debug');
+       // }
+        //libraryRelease.bundle().pipe(process.stdout);
+
+        outFile = path.join('pkg', 'cordova.' + platform + '.js');
+        outFileStream = fs.createWriteStream(outFile);
+        libraryRelease.bundle().pipe(outFileStream);
+
+        libraryRelease.bundle().on('end', function() {
+          console.log('generated cordova.' + platform + '.js @ ' + commitId + ' in ' + time + 'ms');
+          callback();
+        });
+
+       // outFile = path.join('pkg', 'debug', 'cordova.' + platform + '-debug.js');
+       // outFileStream = fs.createWriteStream(outFile);
+       // libraryDebug.bundle().pipe(outFileStream);
+    });
+}


[2/6] js commit: adding browserify require transform

Posted by an...@apache.org.
adding browserify require transform


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

Branch: refs/heads/browserify
Commit: beeb953e1f285f3653578ad68ea39fb00e31dbf0
Parents: c925386
Author: Anis Kadri <an...@apache.org>
Authored: Mon Feb 3 22:15:19 2014 -0800
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Feb 3 22:15:19 2014 -0800

----------------------------------------------------------------------
 tasks/lib/require-tr.js | 81 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/beeb953e/tasks/lib/require-tr.js
----------------------------------------------------------------------
diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js
new file mode 100644
index 0000000..4459fda
--- /dev/null
+++ b/tasks/lib/require-tr.js
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*
+ * This probably should live in plugman/cli world
+ * Transoforms old require calls to new node-style require calls
+ */
+
+var fs = require('fs');
+var path = require('path');
+var through = require('through');
+var UglifyJS = require('uglify-js');
+var root = fs.realpathSync(path.join(__dirname, '..', '..'));
+
+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){
+          if(node.args[0].value === "cordova") {
+            node.args[0].value = path.join(root, "src", "cordova");
+          } else if(node.args[0].value.match(/cordova\/(.+)/)) {
+            node.args[0].value = node.args[0].value.replace(/cordova\/(.+)/, path.join(root, "src", "common", "$1"));
+          }
+        }
+      }
+    }
+  });
+
+  ast.walk(walker);
+
+  var stream = UglifyJS.OutputStream({beautify:true});
+
+  ast.print(stream);
+
+  return stream.toString();
+}
+
+
+module.exports = 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);
+}