You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by da...@apache.org on 2016/05/18 17:57:59 UTC
cordova-cli git commit: CB-11262 Add a warning about prerelease
lib/cli usage
Repository: cordova-cli
Updated Branches:
refs/heads/master 83d3383dc -> 254844d73
CB-11262 Add a warning about prerelease lib/cli usage
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/254844d7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/254844d7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/254844d7
Branch: refs/heads/master
Commit: 254844d73f56eb9203b7cb579e1e32ee1f9f9a6d
Parents: 83d3383
Author: daserge <v-...@microsoft.com>
Authored: Wed May 18 20:53:25 2016 +0300
Committer: daserge <v-...@microsoft.com>
Committed: Wed May 18 20:53:25 2016 +0300
----------------------------------------------------------------------
spec/cli.spec.js | 21 +++++++++++++--------
src/cli.js | 35 +++++++++++++++++++++--------------
2 files changed, 34 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/254844d7/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index 011734d..937c20b 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -22,10 +22,11 @@ var cli = require("../src/cli"),
cordova_lib = require('cordova-lib'),
events = cordova_lib.events,
cordova = cordova_lib.cordova,
- telemetry = require('../src/telemetry');
-
- //avoid node complaining of too many event listener added
- process.setMaxListeners(0);
+ telemetry = require('../src/telemetry'),
+ logger = require('cordova-common').CordovaLogger.get();
+
+//avoid node complaining of too many event listener added
+process.setMaxListeners(0);
describe("cordova cli", function () {
beforeEach(function () {
@@ -41,8 +42,12 @@ describe("cordova cli", function () {
};
spyOn(events, "on").andReturn(new FakeEvents());
+
+ // Spy and mute output
+ spyOn(logger, 'results');
+ spyOn(logger, 'warn');
spyOn(console, 'log');
-
+
// Prevent accidentally turning telemetry on/off during testing
telemetry.turnOn = function() {};
telemetry.turnOff = function() {};
@@ -58,21 +63,21 @@ describe("cordova cli", function () {
it("will spit out the version with -v", function (done) {
cli(["node", "cordova", "-v"], function() {
- expect(console.log.mostRecentCall.args[0]).toMatch(version);
+ expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done();
});
});
it("will spit out the version with --version", function (done) {
cli(["node", "cordova", "--version"], function () {
- expect(console.log.mostRecentCall.args[0]).toMatch(version);
+ expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done()
});
});
it("will spit out the version with -v anywhere", function (done) {
cli(["node", "cordova", "one", "-v", "three"], function () {
- expect(console.log.mostRecentCall.args[0]).toMatch(version);
+ expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done();
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/254844d7/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 5d437b0..071d956 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -240,18 +240,6 @@ function cli(inputArgs) {
var args = nopt(knownOpts, shortHands, inputArgs);
- if (args.version) {
- var cliVersion = require('../package').version;
- var libVersion = require('cordova-lib/package').version;
- var toPrint = cliVersion;
- if (cliVersion != libVersion || /-dev$/.exec(libVersion)) {
- toPrint += ' (cordova-lib@' + libVersion + ')';
- }
- console.log(toPrint);
- return Q();
- }
-
-
// For CordovaError print only the message without stack trace unless we
// are in a verbose mode.
process.on('uncaughtException', function(err) {
@@ -262,7 +250,7 @@ function cli(inputArgs) {
}
process.exit(1);
});
-
+
logger.subscribe(events);
if (args.silent) {
@@ -273,6 +261,25 @@ function cli(inputArgs) {
logger.setLevel('verbose');
}
+ var cliVersion = require('../package').version;
+ // TODO: Use semver.prerelease when it gets released
+ var usingPrerelease = /-nightly|-dev$/.exec(cliVersion);
+ if (args.version || usingPrerelease) {
+ var libVersion = require('cordova-lib/package').version;
+ var toPrint = cliVersion;
+ if (cliVersion != libVersion || usingPrerelease) {
+ toPrint += ' (cordova-lib@' + libVersion + ')';
+ }
+
+ if (args.version) {
+ logger.results(toPrint);
+ return Q();
+ } else {
+ // Show a warning and continue
+ logger.warn('Warning: using prerelease version ' + toPrint);
+ }
+ }
+
// TODO: Example wanted, is this functionality ever used?
// If there were arguments protected from nopt with a double dash, keep
// them in unparsedArgs. For example:
@@ -320,7 +327,7 @@ function cli(inputArgs) {
nohooks: args.nohooks || [],
searchpath : args.searchpath
};
-
+
if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run' || cmd === 'clean') {
// All options without dashes are assumed to be platform names
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org