You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/06/21 19:18:30 UTC
[3/3] js commit: Move computing of commit ID into packager.js (cherry
picked from commit 232f389252c94d3f7b5404ccb8c4b96fcf5467fa)
Move computing of commit ID into packager.js
(cherry picked from commit 232f389252c94d3f7b5404ccb8c4b96fcf5467fa)
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/5f553f3b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/5f553f3b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/5f553f3b
Branch: refs/heads/3.0.0
Commit: 5f553f3b2e8c72a2c312e704ab869326cb5d4f1a
Parents: 01378a6
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jun 21 13:15:00 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jun 21 13:18:23 2013 -0400
----------------------------------------------------------------------
Gruntfile.js | 44 +-----------------------
build/packager.js | 91 ++++++++++++++++++++++++++++++++++++--------------
2 files changed, 67 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/5f553f3b/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index f7c3b3d..7665623 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -17,7 +17,6 @@
* under the License.
*/
module.exports = function(grunt) {
- var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');
@@ -83,43 +82,6 @@ module.exports = function(grunt) {
scan(root);
}
- var cachedGitVersion = null;
- function computeGitVersion(callback) {
- if (cachedGitVersion) {
- callback(cachedGitVersion);
- return;
- }
- var gitPath = 'git';
- var args = 'describe --tags --long';
- 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(stdout);
- }
- });
- } else if (err) {
- error(err);
- } else {
- done(stdout);
- }
- });
-
- function error(err) {
- throw new Error(err);
- }
-
- function done(stdout) {
- var version = stdout.trim().replace(/^2.5.0-.*?-/, 'dev-');
- cachedGitVersion = version;
- callback(version);
- };
- }
-
function processWhiteSpace(processor, callback) {
var rexp_minified = new RegExp("\\.min\\.js$");
var rexp_src = new RegExp('\\.js$');
@@ -152,11 +114,7 @@ module.exports = function(grunt) {
var done = this.async();
var platformName = this.target;
var useWindowsLineEndings = this.data.useWindowsLineEndings;
- computeGitVersion(function(version) {
- grunt.log.writeln('Build label: ' + version);
- packager.generate(platformName, version, useWindowsLineEndings);
- done();
- });
+ packager.generate(platformName, useWindowsLineEndings, done);
});
grunt.registerTask('test', 'Runs test in node', function() {
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/5f553f3b/build/packager.js
----------------------------------------------------------------------
diff --git a/build/packager.js b/build/packager.js
index f81b6a4..d859636 100644
--- a/build/packager.js
+++ b/build/packager.js
@@ -17,43 +17,84 @@
* under the License.
*/
+var childProcess = require('child_process');
var fs = require('fs')
var util = require('util')
var path = require('path')
var packager = module.exports
-//------------------------------------------------------------------------------
-packager.generate = function(platform, commitId, useWindowsLineEndings) {
- var outFile;
- var time = new Date().valueOf();
-
- var libraryRelease = packager.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);
-
- time = new Date().valueOf() - time;
- if (!fs.existsSync('pkg')) {
- fs.mkdirSync('pkg');
+var cachedGitVersion = null;
+packager.computeCommitId = function(callback) {
+ if (cachedGitVersion) {
+ callback(cachedGitVersion);
+ return;
}
- if(!fs.existsSync('pkg/debug')) {
- fs.mkdirSync('pkg/debug');
+ var gitPath = 'git';
+ var args = 'describe --tags --long';
+ 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(stdout);
+ }
+ });
+ } else if (err) {
+ error(err);
+ } else {
+ done(stdout);
+ }
+ });
+
+ function error(err) {
+ throw new Error(err);
}
- outFile = path.join('pkg', 'cordova.' + platform + '.js');
- fs.writeFileSync(outFile, libraryRelease, 'utf8');
-
- outFile = path.join('pkg', 'debug', 'cordova.' + platform + '-debug.js');
- fs.writeFileSync(outFile, libraryDebug, 'utf8');
-
- console.log('generated platform: ' + platform + ' in ' + time + 'ms');
+ function done(stdout) {
+ var version = stdout.trim().replace(/^2.5.0-.*?-/, 'dev-');
+ cachedGitVersion = version;
+ callback(version);
+ };
+}
+
+//------------------------------------------------------------------------------
+packager.generate = function(platform, useWindowsLineEndings, callback) {
+ packager.computeCommitId(function(commitId) {
+ var outFile;
+ var time = new Date().valueOf();
+
+ var libraryRelease = packager.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);
+
+ time = new Date().valueOf() - time;
+ if (!fs.existsSync('pkg')) {
+ fs.mkdirSync('pkg');
+ }
+ if(!fs.existsSync('pkg/debug')) {
+ fs.mkdirSync('pkg/debug');
+ }
+
+ outFile = path.join('pkg', 'cordova.' + platform + '.js');
+ fs.writeFileSync(outFile, libraryRelease, 'utf8');
+
+ outFile = path.join('pkg', 'debug', 'cordova.' + platform + '-debug.js');
+ fs.writeFileSync(outFile, libraryDebug, 'utf8');
+
+ console.log('generated cordova.' + platform + '.js @ ' + commitId + ' in ' + time + 'ms');
+ callback();
+ });
}
//------------------------------------------------------------------------------
-packager.bundle = function(platform, debug, commitId ) {
+packager.bundle = function(platform, debug, commitId) {
var modules = collectFiles('lib/common')
var scripts = collectFiles('lib/scripts')