You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/12/11 22:54:28 UTC
[09/15] js commit: everything seperated into discreet modules but
deps not resolved
everything seperated into discreet modules but deps not resolved
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/e3e40f52
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/e3e40f52
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/e3e40f52
Branch: refs/heads/master
Commit: e3e40f52e357154d9c801efd9e902f8b81be2ead
Parents: d9a3dce
Author: brianleroux <b...@brian.io>
Authored: Wed Dec 11 09:01:41 2013 +1000
Committer: brianleroux <b...@brian.io>
Committed: Wed Dec 11 09:01:41 2013 +1000
----------------------------------------------------------------------
tasks/compile.js | 4 +-
tasks/lib/bundle.js | 58 +++++++++++++
tasks/lib/compute-commit-id.js | 44 ++++++++++
tasks/lib/packager.js | 157 +++++-------------------------------
4 files changed, 125 insertions(+), 138 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e3e40f52/tasks/compile.js
----------------------------------------------------------------------
diff --git a/tasks/compile.js b/tasks/compile.js
index a30fb7a..58db43c 100644
--- a/tasks/compile.js
+++ b/tasks/compile.js
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-var packager = require('./lib/packager');
+var generate = require('./lib/packager');
module.exports = function(grunt) {
grunt.registerMultiTask('compile', 'Packages cordova.js', function() {
@@ -25,6 +25,6 @@ module.exports = function(grunt) {
var platformName = this.target;
var useWindowsLineEndings = this.data.useWindowsLineEndings;
- packager.generate(platformName, useWindowsLineEndings, done);
+ generate(platformName, useWindowsLineEndings, done);
});
}
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e3e40f52/tasks/lib/bundle.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle.js b/tasks/lib/bundle.js
new file mode 100644
index 0000000..cd4e4af
--- /dev/null
+++ b/tasks/lib/bundle.js
@@ -0,0 +1,58 @@
+
+module.exports = function bundle(platform, debug, commitId) {
+ var modules = collectFiles('lib/common')
+ var scripts = collectFiles('lib/scripts')
+
+ modules[''] = 'lib/cordova.js'
+ copyProps(modules, collectFiles(path.join('lib', platform)));
+
+ if (platform === 'test') {
+ copyProps(modules, collectFiles(path.join('lib', 'android', 'android'), 'android/'));
+ }
+
+ var output = [];
+
+ output.push("// Platform: " + platform);
+ output.push("// " + commitId);
+
+ // write header
+ output.push('/*', fs.readFileSync('LICENSE-for-js-file.txt', '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)
+
+ // write modules
+ var moduleIds = Object.keys(modules)
+ moduleIds.sort()
+
+ for (var i=0; i<moduleIds.length; i++) {
+ var moduleId = moduleIds[i]
+
+ writeModule(output, modules[moduleId], moduleId, debug)
+ }
+
+ output.push("window.cordova = require('cordova');")
+
+ // write final scripts
+ if (!scripts['bootstrap']) {
+ throw new Error("didn't find a script for 'bootstrap'")
+ }
+
+ writeScript(output, scripts['bootstrap'], debug)
+
+ var bootstrapPlatform = 'bootstrap-' + platform
+ if (scripts[bootstrapPlatform]) {
+ writeScript(output, scripts[bootstrapPlatform], debug)
+ }
+
+ // write trailer
+ output.push('})();')
+
+ return output.join('\n')
+}
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e3e40f52/tasks/lib/compute-commit-id.js
----------------------------------------------------------------------
diff --git a/tasks/lib/compute-commit-id.js b/tasks/lib/compute-commit-id.js
new file mode 100644
index 0000000..beaf418
--- /dev/null
+++ b/tasks/lib/compute-commit-id.js
@@ -0,0 +1,44 @@
+
+module.exports = function computeCommitId(callback, cachedGitVersion) {
+
+ if (cachedGitVersion) {
+ callback(cachedGitVersion);
+ return;
+ }
+
+ var versionFileId = fs.readFileSync('VERSION', { encoding: 'utf8' }).trim();
+
+ if (/-dev$/.test(versionFileId) && fs.existsSync('.git')) {
+ var gitPath = 'git';
+ var args = 'rev-list HEAD --max-count=1 --abbrev-commit';
+ childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
+ var isWindows = process.platform.slice(0, 3) == 'win';
+ if (err && isWindows) {
+ gitPath = '"' + path.join(process.env['ProgramFiles'], 'Git', 'bin', 'git.exe') + '"';
+ childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
+ if (err) {
+ error(err);
+ } else {
+ done(versionFileId + '-' + stdout);
+ }
+ });
+ } else if (err) {
+ error(err);
+ } else {
+ done(versionFileId + '-' + stdout);
+ }
+ });
+ } else {
+ done(fs.readFileSync('VERSION', { encoding: 'utf8' }));
+ }
+
+ function error(err) {
+ throw new Error(err);
+ }
+
+ function done(stdout) {
+ var version = stdout.trim();
+ cachedGitVersion = version;
+ callback(version);
+ };
+}
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e3e40f52/tasks/lib/packager.js
----------------------------------------------------------------------
diff --git a/tasks/lib/packager.js b/tasks/lib/packager.js
index 7b0da47..6d0f5ef 100644
--- a/tasks/lib/packager.js
+++ b/tasks/lib/packager.js
@@ -16,83 +16,34 @@
* specific language governing permissions and lim
* under the License.
*/
-
-var childProcess = require('child_process');
-var fs = require('fs');
-var util = require('util');
-var path = require('path');
-var stripHeader = require('./strip-header');
-var copyProps = require('./copy-props');
-var getModuleId = require('./get-module-id');
-var writeContents = require('./write-contents');
-var writeModule = require('./write-module');
-var writeScript = require('./write-script');
-var collectFiles = require('./collect-files');
-var collectFile = require('./collect-file');
-
-
-
-
-
-var packager = module.exports
-var cachedGitVersion = null;
-
-packager.computeCommitId = function(callback) {
-
- if (cachedGitVersion) {
- callback(cachedGitVersion);
- return;
- }
-
- var versionFileId = fs.readFileSync('VERSION', { encoding: 'utf8' }).trim();
-
- if (/-dev$/.test(versionFileId) && fs.existsSync('.git')) {
- var gitPath = 'git';
- var args = 'rev-list HEAD --max-count=1 --abbrev-commit';
- childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
- var isWindows = process.platform.slice(0, 3) == 'win';
- if (err && isWindows) {
- gitPath = '"' + path.join(process.env['ProgramFiles'], 'Git', 'bin', 'git.exe') + '"';
- childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
- if (err) {
- error(err);
- } else {
- done(versionFileId + '-' + stdout);
- }
- });
- } else if (err) {
- error(err);
- } else {
- done(versionFileId + '-' + stdout);
- }
- });
- } else {
- done(fs.readFileSync('VERSION', { encoding: 'utf8' }));
- }
-
- function error(err) {
- throw new Error(err);
- }
-
- function done(stdout) {
- var version = stdout.trim();
- cachedGitVersion = version;
- callback(version);
- };
-}
-
-//------------------------------------------------------------------------------
-packager.generate = function(platform, useWindowsLineEndings, callback) {
- packager.computeCommitId(function(commitId) {
+var fs = require('fs');
+var path = require('path');
+var bundle = require('./bundle');
+var computeCommitId = require('./compute-commit-id');
+/*
+var childProcess = require('child_process');
+var util = require('util');
+var stripHeader = require('./strip-header');
+var copyProps = require('./copy-props');
+var getModuleId = require('./get-module-id');
+var writeContents = require('./write-contents');
+var writeModule = require('./write-module');
+var writeScript = require('./write-script');
+var collectFiles = require('./collect-files');
+var collectFile = require('./collect-file');
+*/
+
+module.exports = function generate(platform, useWindowsLineEndings, callback) {
+ computeCommitId(function(commitId) {
var outFile;
var time = new Date().valueOf();
- var libraryRelease = packager.bundle(platform, false, commitId);
+ 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 = packager.bundle(platform, true, commitId);
+ var libraryDebug = bundle(platform, true, commitId);
time = new Date().valueOf() - time;
if (!fs.existsSync('pkg')) {
@@ -112,69 +63,3 @@ packager.generate = function(platform, useWindowsLineEndings, callback) {
callback();
});
}
-
-//------------------------------------------------------------------------------
-packager.bundle = function(platform, debug, commitId) {
- var modules = collectFiles('lib/common')
- var scripts = collectFiles('lib/scripts')
-
- modules[''] = 'lib/cordova.js'
- copyProps(modules, collectFiles(path.join('lib', platform)));
-
- if (platform === 'test') {
- copyProps(modules, collectFiles(path.join('lib', 'android', 'android'), 'android/'));
- }
-
- var output = [];
-
- output.push("// Platform: " + platform);
- output.push("// " + commitId);
-
- // write header
- output.push('/*', fs.readFileSync('LICENSE-for-js-file.txt', '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)
-
- // write modules
- var moduleIds = Object.keys(modules)
- moduleIds.sort()
-
- for (var i=0; i<moduleIds.length; i++) {
- var moduleId = moduleIds[i]
-
- writeModule(output, modules[moduleId], moduleId, debug)
- }
-
- output.push("window.cordova = require('cordova');")
-
- // write final scripts
- if (!scripts['bootstrap']) {
- throw new Error("didn't find a script for 'bootstrap'")
- }
-
- writeScript(output, scripts['bootstrap'], debug)
-
- var bootstrapPlatform = 'bootstrap-' + platform
- if (scripts[bootstrapPlatform]) {
- writeScript(output, scripts[bootstrapPlatform], debug)
- }
-
- // write trailer
- output.push('})();')
-
- return output.join('\n')
-}
-
-//------------------------------------------------------------------------------
-
-
-
-
-