From 254844d73f56eb9203b7cb579e1e32ee1f9f9a6d Mon Sep 17 00:00:00 2001 From: daserge Date: Wed, 18 May 2016 20:53:25 +0300 Subject: [PATCH] CB-11262 Add a warning about prerelease lib/cli usage --- spec/cli.spec.js | 21 +++++++++++++-------- src/cli.js | 35 +++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/spec/cli.spec.js b/spec/cli.spec.js index 011734db8..937c20b46 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(); }); }); diff --git a/src/cli.js b/src/cli.js index 5d437b0dc..071d956fa 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