cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-cli git commit: CB-10748 Use cordova-common.CordovaLogger in CLI
Date Fri, 04 Mar 2016 10:38:49 GMT
Repository: cordova-cli
Updated Branches:
  refs/heads/master d129f9dbc -> 9256d6339


CB-10748 Use cordova-common.CordovaLogger in CLI

Fixes the help tests (3rd line is expected to contain the command usage and not the blank
line)


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/9256d633
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/9256d633
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/9256d633

Branch: refs/heads/master
Commit: 9256d633994a40d87ae4f6738292166f2d9fa33e
Parents: d129f9d
Author: daserge <v-seshak@microsoft.com>
Authored: Tue Mar 1 15:32:22 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Fri Mar 4 13:32:52 2016 +0300

----------------------------------------------------------------------
 doc/cordova.txt  |   1 +
 package.json     |   1 +
 spec/cli.spec.js |   9 +++-
 src/cli.js       |  14 ++----
 src/logger.js    | 116 --------------------------------------------------
 5 files changed, 14 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9256d633/doc/cordova.txt
----------------------------------------------------------------------
diff --git a/doc/cordova.txt b/doc/cordova.txt
index 2a80f44..164e81d 100644
--- a/doc/cordova.txt
+++ b/doc/cordova.txt
@@ -1,4 +1,5 @@
 Synopsis
+
     cordova-cli command [options]
 
 Global Commands

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9256d633/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 601d739..3aa4738 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
   "dependencies": {
     "ansi": "^0.3.0",
     "cordova-lib": "6.0.0",
+    "cordova-common": "^1.1.0",
     "q": "1.0.1",
     "nopt": "3.0.1",
     "underscore": "1.7.0",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9256d633/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index f1e1e92..7881614 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -29,7 +29,14 @@ describe("cordova cli", function () {
         // tests in a directory run in a single process (and in parallel),
         // logging events registered as a result of the "--verbose" flag in
         // CLI testing below would cause lots of logging messages printed out by other specs.
-        spyOn(events, "on");
+
+        // This is required so that fake events chaining works (events.on('log').on('verbose')...)
+        var FakeEvents = function FakeEvents() {};
+        FakeEvents.prototype.on = function fakeOn () {
+            return new FakeEvents();
+        };
+
+        spyOn(events, "on").andReturn(new FakeEvents());
         spyOn(console, 'log');
     });
 

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9256d633/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index f561ad5..5015dcd 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -29,13 +29,13 @@ var path = require('path'),
     nopt,
     _,
     updateNotifier,
-    pkg = require('../package.json'),
-    logger = require('./logger');
+    pkg = require('../package.json');
 
 var cordova_lib = require('cordova-lib'),
     CordovaError = cordova_lib.CordovaError,
     cordova = cordova_lib.cordova,
-    events = cordova_lib.events;
+    events = cordova_lib.events,
+    logger = require('cordova-common').CordovaLogger.get();
 
 
 /*
@@ -136,13 +136,7 @@ function cli(inputArgs) {
         process.exit(1);
     });
 
-    events.on('verbose', logger.verbose);
-    events.on('log', logger.normal);
-    events.on('info', logger.info);
-    events.on('warn', logger.warn);
-
-    // Set up event handlers for logging and results emitted as events.
-    events.on('results', logger.results);
+    logger.subscribe(events);
 
     if (args.silent) {
         logger.setLevel('error');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9256d633/src/logger.js
----------------------------------------------------------------------
diff --git a/src/logger.js b/src/logger.js
deleted file mode 100644
index 93c3d55..0000000
--- a/src/logger.js
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- 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 util = require('util'),
-    ansi = require('ansi'),
-    Stream = require('stream'),
-    cordova_lib = require('cordova-lib'),
-    CordovaError = cordova_lib.CordovaError;
-
-var EOL = require('os').EOL;
-
-var logger = {
-    levels: {},
-    colors: {},
-    stdout: process.stdout,
-    stderr: process.stderr
-};
-
-logger.stdoutCursor = ansi(logger.stdout);
-logger.stderrCursor = ansi(logger.stderr);
-
-function formatError(error, isVerbose) {
-    var message = '';
-
-    if(error instanceof CordovaError) {
-        message = error.toString(isVerbose);
-    } else if(error instanceof Error) {
-        if(isVerbose) {
-            message = error.stack;
-        } else {
-            message = error.message;
-        }
-    } else {
-        // Plain text error message
-        message = error;
-    }
-
-    if(message.toUpperCase().indexOf('ERROR:') !== 0) {
-        // Needed for backward compatibility with external tools
-        message = 'Error: ' + message;
-    }
-
-    return message;
-}
-
-logger.log = function (logLevel, message) {
-    if (this.levels[logLevel] >= this.levels[this.logLevel]) {
-        var isVerbose = this.logLevel === 'verbose';
-        var cursor, output;
-
-        if(message instanceof Error || logLevel === 'error') {
-            message = formatError(message, isVerbose);
-            cursor = this.stderrCursor;
-            output = this.stderr;
-        } else {
-            cursor = this.stdoutCursor;
-            output = this.stdout;
-        }
-
-        message = message + EOL;
-
-        if (!cursor) {
-            output.write(message);
-        }
-        if (output !== cursor.stream) {
-            cursor = ansi(output, { enabled: colorEnabled });
-        }
-        var color = this.colors[logLevel];
-        !!color && cursor.bold().fg[color]();
-        cursor.write(message);
-        cursor.reset();
-    }
-};
-
-logger.addLevel = function (level, severity, color) {
-    this.levels[level] = severity;
-    color && (this.colors[level] = color);
-
-    if (!this[level]) {
-        this[level] = this.log.bind(this, level);
-        return this[level];
-    }
-};
-
-logger.setLevel = function (logLevel) {
-    if (this.levels[logLevel]) {
-        this.logLevel = logLevel;
-    }
-};
-
-logger.addLevel('verbose', 1000, 'grey');
-logger.addLevel('normal' , 2000);
-logger.addLevel('warn'   , 2000, 'yellow');
-logger.addLevel('info'   , 3000, 'blue');
-logger.addLevel('error'  , 5000, 'red');
-logger.addLevel('results' , 10000);
-
-logger.setLevel('normal');
-
-module.exports = logger;


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


Mime
View raw message