cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-coho git commit: CB-11279 Support arbitrary repositories for 'coho nightly'
Date Thu, 19 May 2016 08:27:29 GMT
Repository: cordova-coho
Updated Branches:
  refs/heads/master 2fb8df07d -> 94bf9d8bf


CB-11279 Support arbitrary repositories for 'coho nightly'

- Use `updateRepoVersion` from versionutil to update repo's version properly
- Reduce amount of changes written to repos
  - Append new line to every package.json written
  - Use 2 spaces indent in 'package.json' as npm does
- Fix unpublish running multiple times for every repo

This closes #122


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

Branch: refs/heads/master
Commit: 94bf9d8bf8e76a7856bbf45a8b19c47a1e20d9d2
Parents: 2fb8df0
Author: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Authored: Tue May 17 13:11:36 2016 +0300
Committer: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Committed: Thu May 19 11:25:32 2016 +0300

----------------------------------------------------------------------
 src/main.js             |   6 +-
 src/nightly.js          | 140 +++++++++++++++++++++++++++++--------------
 src/npm-publish.js      |  27 +++------
 src/platform-release.js |  58 +-----------------
 src/repoutil.js         |  11 +++-
 src/versionutil.js      |  89 ++++++++++++++++++++++++---
 6 files changed, 201 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index ec7a9c3..a599ef0 100644
--- a/src/main.js
+++ b/src/main.js
@@ -120,8 +120,8 @@ module.exports = function() {
             entryPoint: lazyRequire('./update-release-notes')
         },  {
             name: 'npm-unpublish-nightly',
-            desc: 'Unpublishes last nightly versions for cli and lib',
-            entryPoint: lazyRequire('./npm-publish', 'unpublish')
+            desc: 'Unpublishes last nightly versions for all specified repositories',
+            entryPoint: lazyRequire('./npm-publish', 'unpublishNightly')
         }];
     var otherCommands = [{
             name: 'list-pulls',
@@ -137,7 +137,7 @@ module.exports = function() {
             desc: 'Launches github PR UI for the specified topic branch',
             entryPoint: lazyRequire('./create-pr'),
             noChdir : true
-        }, 
+        },
         {
             name: 'last-week',
             desc: 'Prints out git logs of things that happened last week.',

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/nightly.js
----------------------------------------------------------------------
diff --git a/src/nightly.js b/src/nightly.js
index bcec1d4..28dbdd0 100644
--- a/src/nightly.js
+++ b/src/nightly.js
@@ -33,10 +33,11 @@ var npmlink = require('./npm-link');
 var repoclone = require('./repo-clone');
 
 module.exports = function*(argv) {
-    var repos = flagutil.computeReposFromFlag('tools');
-    var cli = repoutil.getRepoById('cli');
-    var cordovaLib = repoutil.getRepoById('lib');
+    /** Specifies the default repos to build nightlies for */
+    var DEFAULT_NIGHTLY_REPOS = ['cli', 'lib'];
+
     var opt = flagutil.registerHelpFlag(optimist);
+    opt = flagutil.registerRepoFlag(opt);
 
     argv = opt
         .usage('Publish CLI & LIB to NPM under nightly tag. \n' +
@@ -52,6 +53,7 @@ module.exports = function*(argv) {
             type:'boolean',
             alias : 'ignoreTestFailures'
         })
+        .default({ r: DEFAULT_NIGHTLY_REPOS})
         .argv;
 
     if(argv.h) {
@@ -60,36 +62,26 @@ module.exports = function*(argv) {
     }
 
     // Clone and update Repos
-    yield repoclone.cloneRepos(repos, /*silent=*/true);
-    yield repoupdate.updateRepos(repos);
+    yield prepareRepos(argv.r);
 
-    //remove local changes and sync up with remote master
-    yield repoutil.forEachRepo(repos, function*() {
-        yield gitutil.gitClean();
-        yield gitutil.resetFromOrigin();
-    });
+    var reposToBuild = flagutil.computeReposFromFlag(argv.r, { includeModules: true });
+    // Get updated nightly versions for all repos
+    /** @type {Object} A map of repo.id and a short SHA for every repo to build */
+    var VERSIONS = yield retrieveVersions(reposToBuild);
 
-    // Get SHAS from repos
-    var SHAJSON = yield retrieveSha(repos);
+    // Update version in package.json and other respective files for every repo
+    // and update dependencies to use nightly versions of packages to be released
+    yield repoutil.forEachRepo(reposToBuild, function*(repo) {
+        apputil.print('Updating ' + repo.id + ' version to ' + VERSIONS[repo.id]);
+        yield versionutil.updateRepoVersion(repo, VERSIONS[repo.id], { commitChanges: false
});
 
-    var currentDate = new Date();
-    var nightlyVersion = '-nightly.' + currentDate.getFullYear() + '.' +
-        (currentDate.getMonth() + 1) + '.' + currentDate.getDate();
-    var cordovaLibVersion;
-    //update package.json version for cli + lib, update lib reference for cli
-    yield repoutil.forEachRepo([cordovaLib, cli], function*(repo) {
-        var dir = process.cwd();
-        var packageJSON = require(dir+'/package.json');
-        packageJSON.version = versionutil.removeDev(packageJSON.version) + nightlyVersion
+
-            '+' + SHAJSON[repo.id];
-
-        if(repo.id === 'lib'){
-            cordovaLibVersion = packageJSON.version;
-        } else {
-            packageJSON.dependencies['cordova-lib'] = cordovaLibVersion;
-        }
+        var packageJSONPath = path.join(process.cwd(), 'package.json');
+        var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
 
-        fs.writeFileSync(dir+'/package.json', JSON.stringify(packageJSON, null, 4), 'utf8',
function(err) {
+        // If there is a dependencies listed, iterate through and update cordova-* dependencies
+        packageJSON.dependencies = mapDependenciesVersions(packageJSON.dependencies, VERSIONS);
+
+        fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2) + '\n', 'utf8',
function(err) {
             if (err) return console.log (err);
         });
     });
@@ -98,36 +90,64 @@ module.exports = function*(argv) {
     yield npmlink();
 
     // npm install cli
+    var cli = repoutil.getRepoById('cli');
     yield repoutil.forEachRepo([cli], function*(repo) {
         yield executil.execHelper(executil.ARGS('npm install'), /*silent=*/true, false);
     });
 
     //run CLI + cordova-lib tests
-    yield runTests(cli, cordovaLib, argv.ignoreTestFailures);
+    yield runTests(reposToBuild, argv.ignoreTestFailures);
 
     var options = {};
     options.tag = 'nightly';
     options.pretend = argv.pretend;
+    options.r = reposToBuild.map(function (repo) { return repo.id; });
 
     //unpublish old nightly
-    yield repoutil.forEachRepo([cordovaLib, cli], function*(repo) {
-        var packageName = repo.packageName || repo.repoName;
-        var oldNightlyVersion = yield executil.execHelper(executil.ARGS('npm view ' + packageName
+ ' dist-tags.nightly'));
-        apputil.print('Latest ' + packageName + '@nightly version is ' + oldNightlyVersion);
-
-        options.r = [repo.id];
-        options.version = oldNightlyVersion;
-
-        yield npmpublish.unpublish(options);
-    });
-
-    options.r = ['lib', 'cli'];
+    yield npmpublish.unpublishNightly(options);
     //publish to npm under nightly tag
     yield npmpublish.publishTag(options);
+};
+
+function* prepareRepos(repoNames) {
+    // Clone and update required repos
+    apputil.print('Cloning and updating required repositories...');
+    var reposToClone = flagutil.computeReposFromFlag(['tools'].concat(repoNames));
+    yield repoclone.cloneRepos(reposToClone, /*silent=*/true);
+    yield repoupdate.updateRepos(reposToClone, /*silent=*/true);
+
+    // Remove local changes and sync up with remote master
+    apputil.print('Resetting repositories to "master" branches...');
+    var reposToUpdate = flagutil.computeReposFromFlag(repoNames);
+    yield repoutil.forEachRepo(reposToUpdate, function*() {
+        yield gitutil.gitClean();
+        yield gitutil.resetFromOrigin();
+    });
 }
 
-function *runTests(cli, lib, ignoreTestFailures) {
-    yield repoutil.forEachRepo([cli, lib], function *(repo) {
+/**
+ * Updates provided dependencies object with versions, supplied in packageVersions object
+ * @param {Object<String, String>} packageDependencies A map of current package's dependencies
to versions
+ * @param {Object<String, String>} packageVersions Map of package's id's to nightly
versions
+ * @returns {Object<String, String>} A mapped object
+ */
+function mapDependenciesVersions(packageDependencies, packageVersions) {
+    return Object.keys(packageDependencies)
+    .reduce(function (result, dependency) {
+        var dep = repoutil.getRepoById(dependency);
+        // If this is a cordova-* dependency, and we're going to build nightly for it
+        if (dependency.match(/cordova\-.*/) && dep && packageVersions[dep.id])
{
+            // Update its version in package's dependencies to nightly version
+            apputil.print('Updating ' + dependency + ' dependency version to ' + packageVersions[dep.id]);
+            result[dependency] = packageVersions[dep.id];
+        }
+
+        return result;
+    }, packageDependencies);
+}
+
+function *runTests(repos, ignoreTestFailures) {
+    yield repoutil.forEachRepo(repos, function *(repo) {
         try {
             yield executil.execHelper(executil.ARGS('npm test'), false, ignoreTestFailures);
         } catch (e) {
@@ -136,3 +156,35 @@ function *runTests(cli, lib, ignoreTestFailures) {
         }
     });
 }
+
+/**
+ * Generates suffix for appending to nightly package version
+ *   based on current date and SHA string.
+ * @param SHA {String} String to use to generate nightly version
+ * @returns {String} A newly generated nightly suffix
+ */
+function getNightlySuffix (SHA) {
+    var currentDate = new Date();
+    var nightlySuffix = '-nightly.' + currentDate.getFullYear() + '.' +
+        (currentDate.getMonth() + 1) + '.' + currentDate.getDate() +
+        '+' + SHA;
+
+    return nightlySuffix;
+}
+
+/**
+ * Generates map of repo.id -> nightly version based on current
+ *   date and SHA of current revision of repository
+ * @param {Object[]} repos An array of cordova repos
+ * @returns {Object} Mapped object
+ */
+function* retrieveVersions(repos) {
+    var SHAJSON = yield retrieveSha(repos);
+
+    return Object.keys(SHAJSON).reduce(function (result, repoId) {
+        var repoPath = repoutil.getRepoDir(repoutil.getRepoById(repoId));
+        var oldVersion = require(path.join(repoPath, 'package.json')).version;
+        result[repoId] = versionutil.removeDev(oldVersion) + getNightlySuffix(SHAJSON[repoId]);
+        return result;
+    }, {});
+}

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/npm-publish.js
----------------------------------------------------------------------
diff --git a/src/npm-publish.js b/src/npm-publish.js
index 5433d41..9fe34cf 100644
--- a/src/npm-publish.js
+++ b/src/npm-publish.js
@@ -74,14 +74,8 @@ function *publishTag(options) {
 
 module.exports.publishTag = publishTag;
 
-//TODO: Does npm tag cordova-js*.tgz latest
-exports.setLatest = function*(argv) {
-
-
-}
-
 //Gets last nightly tag and unpublishes it
-function *unpublish(options) {
+function *unpublishNightly(options) {
     var opt = flagutil.registerHelpFlag(optimist);
 
     if(options) {
@@ -92,12 +86,9 @@ function *unpublish(options) {
             .options('r', {
                 default:options.r
             })
-            .options('version', {
-                default:options.version
-            })
     }
 
-    argv = opt
+    var argv = opt
         .usage("Unpublishes the nightly version for the cli & lib from npm \n" +
                 "Usage: $0 npm-unpublish-nightly")
         .options("pretend", {
@@ -105,11 +96,7 @@ function *unpublish(options) {
             type: "boolean"
         })
         .options('r', {
-            desc: "Which repo(s) to publish",
-            demand: true
-        })
-        .options('version', {
-            desc: "Which version to unpublish",
+            desc: "Which repo(s) to unpublish",
             demand: true
         })
         .argv;
@@ -123,8 +110,12 @@ function *unpublish(options) {
 
     yield repoutil.forEachRepo(repos, function*(repo) {
         var packageId = repo.packageName || repo.repoName;
-        yield executil.execOrPretend(executil.ARGS('npm unpublish '+ packageId + '@' + argv.version),
argv.pretend);
+        var oldNightlyVersion = yield executil.execHelper(executil.ARGS('npm view ' + packageId
+ ' dist-tags.nightly'));
+
+        if (oldNightlyVersion && oldNightlyVersion !== 'undefined') {
+            yield executil.execOrPretend(executil.ARGS('npm unpublish '+ packageId + '@'
+ oldNightlyVersion), argv.pretend);
+        }
     });
 }
 
-module.exports.unpublish = unpublish;
+module.exports.unpublishNightly = unpublishNightly;

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/platform-release.js
----------------------------------------------------------------------
diff --git a/src/platform-release.js b/src/platform-release.js
index dd0df7f..a9ebce1 100644
--- a/src/platform-release.js
+++ b/src/platform-release.js
@@ -17,7 +17,6 @@ specific language governing permissions and limitations
 under the License.
 */
 
-var fs = require('fs');
 var path = require('path');
 var optimist = require('optimist');
 var shelljs = require('shelljs');
@@ -27,6 +26,7 @@ var flagutil = require('./flagutil');
 var gitutil = require('./gitutil');
 var repoutil = require('./repoutil');
 var repoupdate = require('./repo-update');
+var versionutil = require('./versionutil');
 var print = apputil.print;
 
 function createPlatformDevVersion(version) {
@@ -114,58 +114,6 @@ function *updateJsSnapshot(repo, version) {
     }
 }
 
-function *updateRepoVersion(repo, version) {
-    // Update the VERSION files.
-    var versionFilePaths = repo.versionFilePaths || ['VERSION'];
-    if (fs.existsSync(versionFilePaths[0])) {
-        versionFilePaths.forEach(function(versionFilePath) {
-            fs.writeFileSync(versionFilePath, version + '\n');
-        });
-        shelljs.config.fatal = true;
-        if (repo.id == 'android' || repo.id == 'amazon-fireos') {
-            shelljs.sed('-i', /CORDOVA_VERSION.*=.*;/, 'CORDOVA_VERSION = "' + version +
'";', path.join('framework', 'src', 'org', 'apache', 'cordova', 'CordovaWebView.java'));
-            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'cordova', 'version'));
-        } else if (repo.id == 'ios' || repo.id == 'osx') {
-            shelljs.sed('-i', /VERSION.*=.*/, 'VERSION="' + version + '";', path.join('bin',
'templates', 'scripts', 'cordova', 'version'));
-        } else if (repo.id == 'blackberry') {
-            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'project','cordova', 'lib', 'version.js'));
-        } else if (repo.id == 'firefoxos' || repo.id == 'browser' || repo.id == 'ubuntu')
{
-            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'project','cordova', 'version'));
-        } else if (repo.id == 'windows') {
-            if(fs.existsSync(path.join('template', 'cordova', 'version'))) {
-                console.log('version exists');
-                shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('template',
'cordova', 'version'));
-            }
-        }
-        shelljs.config.fatal = false;
-        if (!(yield gitutil.pendingChangesExist())) {
-            print('VERSION file was already up-to-date.');
-        }
-    } else {
-        console.warn('No VERSION file exists in repo ' + repo.repoName);
-    }
-
-    // Update the package.json VERSION.
-    var packageFilePaths = repo.packageFilePaths || ['package.json'];
-    if (fs.existsSync(packageFilePaths[0])) {
-        fs.readFile(packageFilePaths[0], {encoding: 'utf-8'},function (err, data) {
-            if (err) throw err;
-            var packageJSON = JSON.parse(data);
-            packageJSON.version = version;
-            fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, "   
"));
-        });
-        if (!(yield gitutil.pendingChangesExist())) {
-            print('package.json file was already up-to-date.');
-        }
-    } else {
-        console.warn('No package.json file exists in repo ' + repo.repoName);
-    }
-
-    if (yield gitutil.pendingChangesExist()) {
-        yield executil.execHelper(executil.ARGS('git commit -am', 'Set VERSION to ' + version
+ ' (via coho)'));
-    }
-}
-
 exports.prepareReleaseBranchCommand = function*() {
     var argv = configureReleaseCommandFlags(optimist
         .usage('Prepares release branches but does not create tags. This includes:\n' +
@@ -206,12 +154,12 @@ exports.prepareReleaseBranchCommand = function*() {
             }
             yield updateJsSnapshot(repo, version);
             print(repo.repoName + ': ' + 'Setting VERSION to "' + version + '" on branch
+ "' + branchName + '".');
-            yield updateRepoVersion(repo, version);
+            yield versionutil.updateRepoVersion(repo, version);
 
             yield gitutil.gitCheckout('master');
             var devVersion = createPlatformDevVersion(version);
             print(repo.repoName + ': ' + 'Setting VERSION to "' + devVersion + '" on branch
+ "master".');
-            yield updateRepoVersion(repo, devVersion);
+            yield versionutil.updateRepoVersion(repo, devVersion);
             yield updateJsSnapshot(repo, devVersion);
             yield gitutil.gitCheckout(branchName);
         });

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/repoutil.js
----------------------------------------------------------------------
diff --git a/src/repoutil.js b/src/repoutil.js
index 59ab1fe..e4bf09f 100644
--- a/src/repoutil.js
+++ b/src/repoutil.js
@@ -439,11 +439,20 @@ repoGroups.__defineGetter__('auto', function() {
 
 exports.repoGroups = repoGroups;
 
+function isInRepoGroup(repoToCheck, groupName) {
+    var repos = repoGroups[groupName];
+    if (!repos) return false;
+    return repos.some(function (repo) {
+        return repo.id === repoToCheck.id;
+    });
+}
+exports.isInRepoGroup = isInRepoGroup;
+
 function getRepoById(id, opt_repos) {
     // Strip cordova- prefix if it exists.
     var repos = opt_repos || allRepos;
     for (var i = 0; i < repos.length; ++i) {
-        if (repos[i].id == id || repos[i].repoName == id) {
+        if (repos[i].id == id || repos[i].packageName == id || repos[i].repoName == id) {
             return repos[i];
         }
     }

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/94bf9d8b/src/versionutil.js
----------------------------------------------------------------------
diff --git a/src/versionutil.js b/src/versionutil.js
index 1dbe06b..2458b13 100644
--- a/src/versionutil.js
+++ b/src/versionutil.js
@@ -16,9 +16,15 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-var repoutil = require('./repoutil');
-var flagutil = require('./flagutil');
+
+var fs = require('fs');
 var path = require('path');
+var shelljs = require('shelljs');
+var apputil = require('./apputil');
+var executil = require('./executil');
+var flagutil = require('./flagutil');
+var gitutil = require('./gitutil');
+var repoutil = require('./repoutil');
 
 function removeDev(version) {
     var newVersion = version.replace('-dev', '');
@@ -27,12 +33,12 @@ function removeDev(version) {
 exports.removeDev = removeDev;
 
 //updates platformsConfig.json
-//Needs to be passed a object which includes repo.id as key 
+//Needs to be passed a object which includes repo.id as key
 //and the new version as value
 //ex {android:4.0.0}
 function *updatePlatformsConfig(newValues) {
-    
-    var platformsConfig = path.join(repoutil.getRepoDir('cordova-lib'), 
+
+    var platformsConfig = path.join(repoutil.getRepoDir('cordova-lib'),
         'src/cordova/platformsConfig.json');
     console.log(platformsConfig);
     var platformsJS = require(platformsConfig);
@@ -42,16 +48,81 @@ function *updatePlatformsConfig(newValues) {
     yield repoutil.forEachRepo(repos, function*(repo) {
         if(repo.id === 'windows') {
             platformsJS[repo.id].version = newValues[repo.id];
-            platformsJS['windows8'].version = newValues[repo.id]; 
+            platformsJS['windows8'].version = newValues[repo.id];
         } else if(repo.id === 'blackberry') {
-            platformsJS['blackberry10'].version = newValues[repo.id]; 
+            platformsJS['blackberry10'].version = newValues[repo.id];
         } else {
-            platformsJS[repo.id].version = newValues[repo.id]; 
+            platformsJS[repo.id].version = newValues[repo.id];
         }
     });
 
-    fs.writeFileSync(platformsConfig, JSON.stringify(platformsJS, null, 4), 'utf8', function(err)
{
+    fs.writeFileSync(platformsConfig, JSON.stringify(platformsJS, null, 4) + '\n', 'utf8',
function(err) {
         if (err) return console.log (err);
     });
 }
 exports.updatePlatformsConfig = updatePlatformsConfig;
+
+/**
+ * Updates VERSION file, version executable script and package.json using specified
+ *   version. Also commits change made to the repo if opposite is not specified.
+ *
+ * @param {Object}  repo    Repo to update version for
+ * @param {String}  version A semver-compatible version to write to repo's files
+ * @param {Object}  [opts]  An options object
+ * @param {Boolean} [opts.commitChanges=true] Specifies whether to commit changes
+ *   to the repo after update is done.
+ */
+exports.updateRepoVersion = function *updateRepoVersion(repo, version, opts) {
+    // Update the VERSION files.
+    var versionFilePaths = repo.versionFilePaths || ['VERSION'];
+    var isPlatformRepo = !!repoutil.isInRepoGroup(repo, 'platform');
+    if (isPlatformRepo && fs.existsSync(versionFilePaths[0])) {
+        versionFilePaths.forEach(function(versionFilePath) {
+            fs.writeFileSync(versionFilePath, version + '\n');
+        });
+        shelljs.config.fatal = true;
+        if (repo.id == 'android' || repo.id == 'amazon-fireos') {
+            shelljs.sed('-i', /CORDOVA_VERSION.*=.*;/, 'CORDOVA_VERSION = "' + version +
'";', path.join('framework', 'src', 'org', 'apache', 'cordova', 'CordovaWebView.java'));
+            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'cordova', 'version'));
+        } else if (repo.id == 'ios' || repo.id == 'osx') {
+            shelljs.sed('-i', /VERSION.*=.*/, 'VERSION="' + version + '";', path.join('bin',
'templates', 'scripts', 'cordova', 'version'));
+        } else if (repo.id == 'blackberry') {
+            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'project','cordova', 'lib', 'version.js'));
+        } else if (repo.id == 'firefoxos' || repo.id == 'browser' || repo.id == 'ubuntu')
{
+            shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('bin',
'templates', 'project','cordova', 'version'));
+        } else if (repo.id == 'windows') {
+            if(fs.existsSync(path.join('template', 'cordova', 'version'))) {
+                console.log('version exists');
+                shelljs.sed('-i', /VERSION.*=.*;/, 'VERSION = "' + version + '";', path.join('template',
'cordova', 'version'));
+            }
+        }
+        shelljs.config.fatal = false;
+        if (!(yield gitutil.pendingChangesExist())) {
+            apputil.print('VERSION file was already up-to-date.');
+        }
+    } else {
+        if (isPlatformRepo) console.warn('No VERSION file exists in repo ' + repo.repoName);
+    }
+
+    // Update the package.json VERSION.
+    var packageFilePaths = repo.packageFilePaths || ['package.json'];
+    if (fs.existsSync(packageFilePaths[0])) {
+        fs.readFile(packageFilePaths[0], {encoding: 'utf-8'}, function (err, data) {
+            if (err) throw err;
+            var packageJSON = JSON.parse(data);
+            packageJSON.version = version;
+            // use 2 spaces indent similar to npm
+            fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, 2) +
'\n');
+        });
+        if (!(yield gitutil.pendingChangesExist())) {
+            apputil.print('package.json file was already up-to-date.');
+        }
+    } else {
+        console.warn('No package.json file exists in repo ' + repo.repoName);
+    }
+
+    var commitChanges = !!(opts ? opts.commitChanges : true);
+    if (commitChanges && (yield gitutil.pendingChangesExist())) {
+        yield executil.execHelper(executil.ARGS('git commit -am', 'Set VERSION to ' + version
+ ' (via coho)'));
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message