You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/11/01 02:26:25 UTC
[4/6] git commit: CB-7904 Added nightly command to build nightly
releases
CB-7904 Added nightly command to build nightly releases
Project: http://git-wip-us.apache.org/repos/asf/cordova-coho/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-coho/commit/304e0548
Tree: http://git-wip-us.apache.org/repos/asf/cordova-coho/tree/304e0548
Diff: http://git-wip-us.apache.org/repos/asf/cordova-coho/diff/304e0548
Branch: refs/heads/master
Commit: 304e054803be7e468dfbb1ec0a369d12a01fc615
Parents: d49c9d1
Author: Steve Gill <st...@gmail.com>
Authored: Wed Oct 29 22:02:20 2014 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Fri Oct 31 18:25:00 2014 -0700
----------------------------------------------------------------------
package.json | 2 +-
src/executil.js | 18 +++++--
src/gitutil.js | 4 +-
src/main.js | 4 ++
src/nightly.js | 124 ++++++++++++++++++++++++++++++++++++------------
src/npm-publish.js | 77 ++++++++++++++++++++++++++++++
src/repoutil.js | 11 ++++-
src/versionutil.js | 24 ++++++++++
8 files changed, 227 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index cdb4efe..babb812 100644
--- a/package.json
+++ b/package.json
@@ -10,11 +10,11 @@
"chalk": "~0.4",
"co": "~3.0",
"gnode": "^0.1.0",
+ "nlf": "1.1.0",
"optimist": "0.4",
"q": "~0.9",
"request": "2.22.0",
"shelljs": "0.1.4",
- "nlf": "1.1.0",
"treeify": "1.0.1"
},
"repository": {
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/executil.js
----------------------------------------------------------------------
diff --git a/src/executil.js b/src/executil.js
index 1a83630..301f007 100644
--- a/src/executil.js
+++ b/src/executil.js
@@ -23,19 +23,20 @@ var print = apputil.print;
var gitCommitCount = 0;
-exports.ARGS = function(s, var_args) {
+function ARGS(s, var_args) {
var ret = s.trim().split(/\s+/);
for (var i = 1; i < arguments.length; ++i) {
ret.push(arguments[i]);
}
return ret;
}
+exports.ARGS = ARGS;
// silent = false ==> print command and output
// silent == true or 1 ==> don't print command, don't print output
// silent == 2 ==> don't print command, print output
// silent == 3 ==> print command, don't print output
-exports.execHelper = function(cmdAndArgs, silent, allowError) {
+function execHelper(cmdAndArgs, silent, allowError) {
// there are times where we want silent but not allowError.
if (null == allowError) {
// default to allow failure if being silent.
@@ -58,8 +59,9 @@ exports.execHelper = function(cmdAndArgs, silent, allowError) {
process.exit(2);
});
}
+exports.execHelper = execHelper;
-exports.reportGitPushResult = function(repos, branches) {
+function reportGitPushResult(repos, branches) {
print('');
if (gitCommitCount) {
var flagsStr = repos.map(function(r) { return '-r ' + r.id; }).join(' ') + ' ' + branches.map(function(b) { return '-b ' + b; }).join(' ');
@@ -75,3 +77,13 @@ exports.reportGitPushResult = function(repos, branches) {
}
}
+exports.reportGitPushResult = reportGitPushResult;
+
+function *execOrPretend(cmd, pretend) {
+ if (pretend) {
+ print('PRETENDING TO RUN: ' + cmd.join(' '));
+ } else {
+ return yield execHelper(cmd);
+ }
+}
+exports.execOrPretend = execOrPretend;
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/gitutil.js
----------------------------------------------------------------------
diff --git a/src/gitutil.js b/src/gitutil.js
index 91e4b86..907292f 100644
--- a/src/gitutil.js
+++ b/src/gitutil.js
@@ -90,4 +90,6 @@ exports.hashForRef = function(ref) {
return executil.execHelper(executil.ARGS('git rev-parse', ref), true, true);
};
-
+exports.resetFromOrigin = function() {
+ return executil.execHelper(executil.ARGS('git reset --hard origin/master'), false, true);
+}
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index 27edd74..6b4c037 100644
--- a/src/main.js
+++ b/src/main.js
@@ -129,6 +129,10 @@ module.exports = function() {
name: 'nightly',
desc: 'Builds and publishes nightly builds of cordova-cli using the latest commits for each platform.',
entryPoint: lazyRequire('./nightly')
+ }, {
+ name:'npm-publish-tag',
+ desc: 'Publishes current version of repo to specified tag',
+ entryPoint: lazyRequire('./npm-publish', 'publishTag')
}
];
var commandMap = {};
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/nightly.js
----------------------------------------------------------------------
diff --git a/src/nightly.js b/src/nightly.js
index c63d50a..3de5f10 100644
--- a/src/nightly.js
+++ b/src/nightly.js
@@ -17,48 +17,109 @@ specific language governing permissions and limitations
under the License.
*/
-var optimist = require('optimist');
-var apputil = require('./apputil');
var executil = require('./executil');
+var optimist = require('optimist');
var flagutil = require('./flagutil');
-var gitutil = require('./gitutil');
var repoutil = require('./repoutil');
var repoupdate = require('./repo-update');
var retrieveSha = require('./retrieve-sha');
-var print = apputil.print;
+var npmpublish = require('./npm-publish');
+var versionutil = require('./versionutil');
+var gitutil = require('./gitutil');
var fs = require('fs');
var path = require('path');
-module.exports = function*() {
- var repos = flagutil.computeReposFromFlag('nightly');
- console.log(repos);
- //Update Repos
- yield repoupdate.updateRepos(repos, []);
+module.exports = function*(argv) {
+ var repos = flagutil.computeReposFromFlag('nightly');
+ var cli = repoutil.getRepoById('cli');
+ var cordovaLib = repoutil.getRepoById('lib');
+ var opt = flagutil.registerHelpFlag(optimist);
- var SHAJSON = yield retrieveSha(repos);
+ argv = opt
+ .usage('Publish CLI & LIB to NPM under nightly tag. \n' +
+ 'Cordova platform add uses latest commits to the platforms. \n' +
+ 'Usage: $0 nightly'
+ )
+ .options('pretend', {
+ desc: 'Don\'t actually publish to npm, just print what would be run.',
+ type:'boolean'
+ })
+ .argv;
+
+ if(argv.h) {
+ optimist.showHelp();
+ process.exit(1);
+ }
- //console.log(SHAJSON['android']);
+ //Update Repos
+ yield repoupdate.updateRepos(repos);
+
+ //Remove any local changes for cli & lib
+ yield repoutil.forEachRepo([cordovaLib, cli], function*() {
+ gitutil.resetFromOrigin();
+ });
+
+ //get SHAS from platforms
+ var SHAJSON = yield retrieveSha(repos);
+
//save SHAJSON in cordova-cli repo
+ yield repoutil.forEachRepo([cli], function*() {
+ //need to get the path to cordova-cli using executil
+ var cordovaclidir = yield executil.execHelper(executil.ARGS('pwd'), true, true);
+ fs.writeFile((path.join(cordovaclidir, 'shas.json')), JSON.stringify(SHAJSON, null, 4), 'utf8', function(err) {
+ if (err) return console.log (err);
+ });
- //Update platforms at cordova-lib/src/cordova/platforms.js
- //console.log(repos);
- var cordovaLib = repoutil.getRepoById('lib');
- //Need to run forEachRepo
+ });
+
+ //Update platform references at cordova-lib/src/cordova/platformsConfig.json
+ var cordovalibdir;
yield repoutil.forEachRepo([cordovaLib], function*() {
//need to get the path to cordova-lib using executil
- var cordovalibdir = yield executil.execHelper(executil.ARGS('pwd'), true, true);
- yield updatePlatformsFile(path.join(cordovalibdir, 'cordova-lib/src/cordova/platforms.js'), SHAJSON);
+ cordovalibdir = yield executil.execHelper(executil.ARGS('pwd'), true, true);
});
+ yield updatePlatformsFile(path.join(cordovalibdir, 'src/cordova/platformsConfig.json'), SHAJSON);
+
+
+ var currentDate = new Date();
+ var nightlyVersion = '-nightly.' + currentDate.getFullYear() + '.' +
+ currentDate.getMonth() + '.' + 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 = yield executil.execHelper(executil.ARGS('pwd'), true, true);
+ var packageJSON = require(dir+'/package.json');
+ packageJSON.version = versionutil.removeDev(packageJSON.version) + nightlyVersion;
+
+ if(repo.id === 'lib'){
+ cordovaLibVersion = packageJSON.version;
+ } else {
+ packageJSON.dependencies['cordova-lib'] = cordovaLibVersion;
+ }
+
+ fs.writeFile(dir+'/package.json', JSON.stringify(packageJSON, null, 4), 'utf8', function(err) {
+ if (err) return console.log (err);
+ });
+ });
+
+ //run CLI + cordova-lib tests
+ //TODO: Link cli to use local lib (done on my machine, need to automate this for others)
+ yield runTests(cli, cordovaLib);
+
+ //publish to npm under nightly tag
+ argv.tag = 'nightly';
+ argv.r = ['lib', 'cli'];
+ yield npmpublish.publishTag(argv);
}
//updates platforms.js with the SHA
-function *updatePlatformsFile(file, shajson){
- platformsJS = require(file);
- var repos = flagutil.computeReposFromFlag('active-platform');
- //console.log(platformsJS);
+function *updatePlatformsFile(file, shajson) {
+ var platformsJS = require(file);
+
+ var repos = flagutil.computeReposFromFlag('active-platform');
+
yield repoutil.forEachRepo(repos, function*(repo) {
- console.log(repo);
if(repo.id === 'windowsphone'){
platformsJS['wp8'].version = shajson[repo.id];
} else if(repo.id === 'windows') {
@@ -71,16 +132,17 @@ function *updatePlatformsFile(file, shajson){
}
});
- fs.readFile(file, 'utf8', function (err, data) {
- if (err) {
- console.log(err);
- }
- var result = data.replace(/(({(.\n)*(.|\n)*)version:\s[\d\w'.]*(\n)(.)*(\n)})/g, JSON.stringify(platformsJS, null, 4));
-
- fs.writeFile(file, result, 'utf8', function(err) {
+ fs.writeFile(file, JSON.stringify(platformsJS, null, 4), 'utf8', function(err) {
if (err) return console.log (err);
});
-
- });
}
+function *runTests(cli, lib) {
+ yield repoutil.forEachRepo([cli, lib], function *(repo) {
+ if (repo.id === 'lib'){
+ yield executil.execHelper(executil.ARGS('npm test'), false, false);
+ } else {
+ yield executil.execHelper(executil.ARGS('npm test'), false, false);
+ }
+ });
+}
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/npm-publish.js
----------------------------------------------------------------------
diff --git a/src/npm-publish.js b/src/npm-publish.js
new file mode 100644
index 0000000..d266290
--- /dev/null
+++ b/src/npm-publish.js
@@ -0,0 +1,77 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+var optimist = require('optimist');
+var apputil = require('./apputil');
+var flagutil = require('./flagutil');
+var repoutil = require('./repoutil');
+var executil = require('./executil');
+var print = apputil.print;
+
+exports.publishTag = function*(argv) {
+ var opt = flagutil.registerHelpFlag(optimist);
+
+ //argv was passed through another function, set defaults to appease demand.
+ if(argv) {
+ opt = opt
+ .options('tag', {
+ default:argv.tag
+ })
+ .options('r', {
+ default:argv.r
+ })
+ }
+
+ argv = opt
+ .usage('Publishes current version of a repo to a specified npm tag. \n' +
+ 'Usage: $0 npm-publish --tag rc -r cli -r lib')
+ .options('tag', {
+ desc: 'Which npm tag to publish to',
+ demand: true
+ })
+ .options('r', {
+ alias: 'repos',
+ desc: 'Which repo(s) to publish',
+ demand:true
+ })
+ .options('pretend', {
+ desc: 'Don\'t actually run commands, just print what would be run.',
+ type:'boolean'
+ })
+ .argv;
+
+ if(argv.h) {
+ optimist.showHelp();
+ process.exit(1);
+ }
+
+ var repos = flagutil.computeReposFromFlag(argv.r);
+
+ //npm publish --tag argv.tag
+ yield repoutil.forEachRepo(repos, function*(repo) {
+ yield executil.execOrPretend(executil.ARGS('npm publish --tag ' + argv.tag), argv.pretend);
+ //yield executil.execOrPretend(executil.ARGS('ls'), argv.pretend);
+ });
+}
+
+//TODO: Does npm tag cordova-js*.tgz latest
+exports.setLatest = function *(argv) {
+
+
+}
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/repoutil.js
----------------------------------------------------------------------
diff --git a/src/repoutil.js b/src/repoutil.js
index ae92cec..b08cb5a 100644
--- a/src/repoutil.js
+++ b/src/repoutil.js
@@ -450,14 +450,23 @@ exports.forEachRepo = function*(repos, func) {
var newPath = isInForEachRepoFunction ? path.join('..', repo.repoName) : repo.repoName;
isInForEachRepoFunction = true;
+
+ if(repo.id === 'lib'){
+ newPath = newPath + '/cordova-lib'
+ }
shelljs.cd(newPath);
+
if (shelljs.error()) {
apputil.fatal('Repo directory does not exist: ' + repo.repoName + '. First run coho repo-clone.');
}
yield func(repo);
+
+ if(repo.id === 'lib'){
+ origPath = origPath + '/..';
+ }
shelljs.cd(origPath);
- isInForEachRepoFunction = origPath != '..';
+ isInForEachRepoFunction = !((origPath === '..')||(origPath === '../..'));
}
}
http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/304e0548/src/versionutil.js
----------------------------------------------------------------------
diff --git a/src/versionutil.js b/src/versionutil.js
new file mode 100644
index 0000000..810a458
--- /dev/null
+++ b/src/versionutil.js
@@ -0,0 +1,24 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+function removeDev(version) {
+ var newVersion = version.replace('-dev', '');
+ return newVersion;
+}
+exports.removeDev = removeDev;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org