Skip to content

Commit

Permalink
CB-7219 added platformVersion, removed cordova.version
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Sep 24, 2014
1 parent 6c7a76f commit 4a4c544
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dojo": false,

// Custom predefined globals.
"predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp", "PalmSystem", "PalmServiceBridge", "Acceleration", "webworks", "CORDOVA_JS_BUILD_LABEL"],
"predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp", "PalmSystem", "PalmServiceBridge", "Acceleration", "webworks", "CORDOVA_JS_BUILD_LABEL", "PLATFORM_VERSION_BUILD_LABEL"],


// Development
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ All of the build tasks can be run via the `grunt` node module. Install it global

Then from the repository root run:

grunt
grunt --platformVersion=3.6.0

To do just one platform, run:

grunt compile:android --platformVersion=3.6.0

To create the browserify version, run:

grunt compile-browserify --platformVersion=3.6.0

For integration, see the 'Integration' section below.

Expand Down Expand Up @@ -82,7 +90,7 @@ The `boot` method does all the work. First, it grabs the common platform defini

Tests run in node or the browser. To run the tests in node:

grunt test
grunt test --platformVersion=3.6.0

To run them in the browser:

Expand Down
3 changes: 2 additions & 1 deletion src/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ function createEvent(type, data) {
var cordova = {
define:define,
require:require,
version:CORDOVA_JS_BUILD_LABEL,
//version:CORDOVA_JS_BUILD_LABEL,
platformVersion:PLATFORM_VERSION_BUILD_LABEL,
platformId:platform.id,
/**
* Methods to add/remove your own addEventListener hijacking on document + window.
Expand Down
3 changes: 2 additions & 1 deletion src/cordova_b.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function createEvent(type, data) {


var cordova = {
version:CORDOVA_JS_BUILD_LABEL,
platformVersion:PLATFORM_VERSION_BUILD_LABEL,
//version:CORDOVA_JS_BUILD_LABEL,
require: function(module) {
if(module === "cordova/exec") {
return cordova.exec;
Expand Down
18 changes: 16 additions & 2 deletions tasks/compile-browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,24 @@ 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);

//grabs --platformVersion flag
var flags = grunt.option.flags();
var platformVersion;
flags.forEach(function(flag) {
if (flag.indexOf('platformVersion') > -1) {
var equalIndex = flag.indexOf('=');
platformVersion = flag.slice(equalIndex + 1);
}
});
if(!platformVersion){
console.log('please add a platform version flag and value');
console.log('ex: grunt compile-browserify --platformVersion=3.6.0');
throw new Error("platformVersion is required!");
}
generate(platformName, useWindowsLineEndings, platformVersion, done);
});
}
19 changes: 17 additions & 2 deletions tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,26 @@ var generate = require('./lib/packager');

module.exports = function(grunt) {
grunt.registerMultiTask('compile', 'Packages cordova.js', function() {

var done = this.async();
var platformName = this.target;
var useWindowsLineEndings = this.data.useWindowsLineEndings;
var platformVersion;

//grabs --platformVersion flag
var flags = grunt.option.flags();
var platformVersion;
flags.forEach(function(flag) {
if (flag.indexOf('platformVersion') > -1) {
var equalIndex = flag.indexOf('=');
platformVersion = flag.slice(equalIndex + 1);
}
});
if(!platformVersion){
console.log('please add a platform version flag and value');
console.log('ex: grunt compile-browserify --platformVersion=3.6.0');
throw new Error("platformVersion is required!");
}

generate(platformName, useWindowsLineEndings, done);
generate(platformName, useWindowsLineEndings, platformVersion, done);
});
}
5 changes: 3 additions & 2 deletions tasks/lib/bundle-browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ var require_tr = require('./require-tr');
var root = path.join(__dirname, '..', '..')


module.exports = function bundle(platform, debug, commitId) {
module.exports = function bundle(platform, debug, commitId, platformVersion) {
require_tr.platform = platform;
// FIXME: need to find a way to void ignore missing
var b = browserify({debug: debug});
// XXX plugin_list is not present at this stage
b.ignore(path.join(root, 'src', 'common', 'plugin_list'));

console.log('commitID: '+ commitId);
console.log('platformVersion: ' + platformVersion);
b.transform(require_tr.transform);

b.add(path.join(root, 'src', platform, 'exec.js'));
Expand Down
8 changes: 5 additions & 3 deletions tasks/lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ var writeModule = require('./write-module');
var writeScript = require('./write-script');
var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');

module.exports = function bundle(platform, debug, commitId) {
module.exports = function bundle(platform, debug, commitId, platformVersion) {
var modules = collectFiles(path.join('src', 'common'));
var scripts = collectFiles(path.join('src', 'scripts'));
modules[''] = path.join('src', 'cordova.js');
copyProps(modules, collectFiles(path.join('src', platform)));

console.log('commitID: '+ commitId);
console.log('platformVersion: ' + platformVersion);
if (platform === 'test') {
// Add any platform-specific modules that have tests to the test bundle.
var testFilesPath = path.join('src', 'android', 'android');
Expand All @@ -46,7 +47,8 @@ module.exports = function bundle(platform, debug, commitId) {
// write header
output.push('/*', fs.readFileSync(licensePath, 'utf8'), '*/');
output.push(';(function() {');
output.push("var CORDOVA_JS_BUILD_LABEL = '" + commitId + "';");
//output.push("var CORDOVA_JS_BUILD_LABEL = '" + commitId + "';");
output.push("var PLATFORM_VERSION_BUILD_LABEL = '" + platformVersion + "';");

// write initial scripts
if (!scripts['require']) {
Expand Down
16 changes: 7 additions & 9 deletions tasks/lib/compute-commit-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,29 @@ module.exports = function computeCommitId(callback, cachedGitVersion) {

var versionFileId = fs.readFileSync('VERSION', { encoding: 'utf8' }).trim();

if (/-dev$/.test(versionFileId) && fs.existsSync('.git')) {
if (fs.existsSync('.git')) {
var gitPath = 'git';
var args = 'rev-list HEAD --max-count=1 --abbrev-commit';
var args = 'rev-list HEAD --max-count=1';
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) {
console.warn('Error during git describe: ' + err);
done(versionFileId + '-??');
done('???');
} else {
done(versionFileId + '-' + stdout);
done(stdout);
}
});
} else if (err) {
console.warn('Error during git describe: ' + err);
done(versionFileId + '-??');
done('???');
} else {
done(versionFileId + '-' + stdout);
done(stdout);
}
});
} else {
done(fs.readFileSync('VERSION', { encoding: 'utf8' }));
}
}

function done(stdout) {
var version = stdout.trim();
Expand Down
7 changes: 3 additions & 4 deletions tasks/lib/packager-browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ var bundle = require('./bundle-browserify');
var computeCommitId = require('./compute-commit-id');
var writeLicenseHeader = require('./write-license-header');


module.exports = function generate(platform, useWindowsLineEndings, done) {
module.exports = function generate(platform, useWindowsLineEndings, platformVersion, done) {
computeCommitId(function(commitId) {
var outReleaseFile, outReleaseFileStream,
outDebugFile, outDebugFileStream,
releaseBundle, debugBundle;
var time = new Date().valueOf();

var libraryRelease = bundle(platform, false, commitId);
var libraryRelease = bundle(platform, false, commitId, platformVersion);
// if we are using windows line endings, we will also add the BOM
// if(useWindowsLineEndings) {
// libraryRelease = "\ufeff" + libraryRelease.split(/\r?\n/).join("\r\n");
Expand All @@ -49,7 +48,7 @@ module.exports = function generate(platform, useWindowsLineEndings, done) {
outReleaseFileStream = fs.createWriteStream(outReleaseFile);

// write license header
writeLicenseHeader(outReleaseFileStream, platform, commitId);
writeLicenseHeader(outReleaseFileStream, platform, commitId, platformVersion);

releaseBundle = libraryRelease.bundle();

Expand Down
6 changes: 3 additions & 3 deletions tasks/lib/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ var bundle = require('./bundle');
var computeCommitId = require('./compute-commit-id');


module.exports = function generate(platform, useWindowsLineEndings, callback) {
module.exports = function generate(platform, useWindowsLineEndings, platformVersion, callback) {
computeCommitId(function(commitId) {
var outFile;
var time = new Date().valueOf();

var libraryRelease = bundle(platform, false, commitId);
var libraryRelease = bundle(platform, false, commitId, platformVersion);
// 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);
var libraryDebug = bundle(platform, true, commitId, platformVersion);

time = new Date().valueOf() - time;
if (!fs.existsSync('pkg')) {
Expand Down
5 changes: 3 additions & 2 deletions tasks/lib/write-license-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ var util = require('util');
var fs = require('fs');
var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');

module.exports = function(outStream, platform, commitId) {
module.exports = function(outStream, platform, commitId, platformVersion) {
// some poppycock
var licenseText = util.format("/*\n *%s\n */\n", fs.readFileSync(licensePath, 'utf8').replace(/\n/g, "\n *"));

outStream.write("// Platform: " + platform + "\n", 'utf8');
outStream.write("// " + commitId + "\n", 'utf8');
outStream.write(licenseText, 'utf8');
outStream.write("var CORDOVA_JS_BUILD_LABEL = '" + commitId + "';\n", 'utf8');
//outStream.write("var CORDOVA_JS_BUILD_LABEL = '" + commitId + "';\n", 'utf8');
outStream.write("var PLATFORM_VERSION_BUILD_LABEL = '" + platformVersion + "';\n", 'utf8');
outStream.write("var define = {moduleMap: []};\n", 'utf8');

}

0 comments on commit 4a4c544

Please sign in to comment.