Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-11642 Updated CDVAvailability.h in coho prepare-release-branch #140

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,7 @@
"tape-runner": "^0.3.0"
},
"scripts": {
"test": "nsp check && node test/test.js | tap-spec"
"test": "node test/test.js | tap-spec"
},
"repository": {
"type": "git",
Expand Down
44 changes: 40 additions & 4 deletions src/platform-release.js
Expand Up @@ -18,6 +18,8 @@ under the License.
*/

var path = require('path');
var fs = require('fs');
var util = require('util');
var optimist = require('optimist');
var shelljs = require('shelljs');
var apputil = require('./apputil');
Expand Down Expand Up @@ -76,6 +78,33 @@ function configureReleaseCommandFlags(opt) {

var hasBuiltJs = '';

//Adds the version to CDVAvailability.h for iOS
function *updateCDVAvailabilityFile(version) {
var iosFile = path.join(process.cwd(), 'CordovaLib', 'Classes', 'Public','CDVAvailability.h');
var iosFileContents = fs.readFileSync(iosFile, 'utf8');
iosFileContents = iosFileContents.split('\n');

var lineNumberToInsertLine = iosFileContents.indexOf('/* coho:next-version,insert-before */');
var lineNumberToReplaceLine = iosFileContents.indexOf(' /* coho:next-version-min-required,replace-after */') + 2;

var versionNumberUnderscores = version.split('.').join('_');
var versionNumberZeroes = version.split('.').join('0');

var lineToAdd = util.format('#define __CORDOVA_%s %s', versionNumberUnderscores, versionNumberZeroes);
var lineToReplace = util.format(' #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_%s', versionNumberUnderscores);

if(iosFileContents[lineNumberToInsertLine - 1] === lineToAdd) {
print('Version already exists in CDVAvailability.h');
lineNumberToReplaceLine = lineNumberToReplaceLine - 1;
} else {
iosFileContents.splice(lineNumberToInsertLine, 0, lineToAdd);
}

iosFileContents[lineNumberToReplaceLine] = lineToReplace;

fs.writeFileSync(iosFile, iosFileContents.join('\n'));
}

function *updateJsSnapshot(repo, version) {
function *ensureJsIsBuilt() {
var cordovaJsRepo = repoutil.getRepoById('js');
Expand Down Expand Up @@ -129,13 +158,14 @@ exports.prepareReleaseBranchCommand = function*() {
);

var repos = flagutil.computeReposFromFlag(argv.r);
var branchName = null;


var branchName = null;

// First - perform precondition checks.
yield repoupdate.updateRepos(repos, [], true);

yield repoutil.forEachRepo(repos, function*(repo) {
var platform = repo.id;

var version = null;

Expand All @@ -153,7 +183,14 @@ exports.prepareReleaseBranchCommand = function*() {
yield gitutil.stashAndPop(repo, function*() {
// git fetch + update master
yield repoupdate.updateRepos([repo], ['master'], false);

if (platform === 'ios') {
//Updates version in CDVAvailability.h file
yield updateCDVAvailabilityFile(version);
//Git commit changes
if(yield gitutil.pendingChangesExist()) {
yield executil.execHelper(executil.ARGS('git commit -am', 'Added ' + version + ' to CDVAvailability.h (via coho).'));
}
}
// Either create or pull down the branch.
if (yield gitutil.remoteBranchExists(repo, branchName)) {
print('Remote branch already exists for repo: ' + repo.repoName);
Expand All @@ -179,7 +216,6 @@ exports.prepareReleaseBranchCommand = function*() {
yield gitutil.gitCheckout(branchName);
});
});

executil.reportGitPushResult(repos, ['master', branchName]);
}

Expand Down