diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/consola | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/consola')
| -rw-r--r-- | node_modules/consola/CHANGELOG.md | 160 | ||||
| -rw-r--r-- | node_modules/consola/README.md | 184 | ||||
| -rw-r--r-- | node_modules/consola/dist/consola.cjs.js | 428 | ||||
| -rw-r--r-- | node_modules/consola/dist/consola.js | 394 | ||||
| -rw-r--r-- | node_modules/consola/package.json | 58 | ||||
| -rw-r--r-- | node_modules/consola/src/cjs.js | 1 | ||||
| -rw-r--r-- | node_modules/consola/src/consola.js | 91 | ||||
| -rw-r--r-- | node_modules/consola/src/index.js | 26 | ||||
| -rw-r--r-- | node_modules/consola/src/reporters/basic.js | 25 | ||||
| -rw-r--r-- | node_modules/consola/src/reporters/fancy.js | 63 | ||||
| -rw-r--r-- | node_modules/consola/src/reporters/index.js | 11 | ||||
| -rw-r--r-- | node_modules/consola/src/reporters/json.js | 9 | ||||
| -rw-r--r-- | node_modules/consola/src/reporters/winston.js | 26 | ||||
| -rw-r--r-- | node_modules/consola/src/types.js | 42 |
14 files changed, 1518 insertions, 0 deletions
diff --git a/node_modules/consola/CHANGELOG.md b/node_modules/consola/CHANGELOG.md new file mode 100644 index 00000000..eadcaad7 --- /dev/null +++ b/node_modules/consola/CHANGELOG.md @@ -0,0 +1,160 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +<a name="1.4.5"></a> +## [1.4.5](https://github.com/nuxt/consola/compare/v1.4.3...v1.4.5) (2018-11-04) + + +### Bug Fixes + +* **v1:** upward compatibility support to >= v2 ([5c64b0b](https://github.com/nuxt/consola/commit/5c64b0b)) +* add global.consola ([558cae5](https://github.com/nuxt/consola/commit/558cae5)) + + + +<a name="1.4.4"></a> +## [1.4.4](https://github.com/nuxt/consola/compare/v1.4.3...v1.4.4) (2018-10-13) + + +### Bug Fixes + +* add global.consola ([558cae5](https://github.com/nuxt/consola/commit/558cae5)) + + + +<a name="1.4.3"></a> +## [1.4.3](https://github.com/nuxt/consola/compare/v1.4.2...v1.4.3) (2018-08-18) + + +### Bug Fixes + +* use more compatible string to clear the console ([82ce410](https://github.com/nuxt/consola/commit/82ce410)) + + + +<a name="1.4.2"></a> +## [1.4.2](https://github.com/nuxt/consola/compare/v1.4.1...v1.4.2) (2018-08-12) + + +### Bug Fixes + +* cannot set level as 0 in options ([4c1ecce](https://github.com/nuxt/consola/commit/4c1ecce)) + + + +<a name="1.4.1"></a> +## [1.4.1](https://github.com/nuxt/consola/compare/v1.4.0...v1.4.1) (2018-05-27) + + +### Bug Fixes + +* **fancy:** logObj.type ([418be28](https://github.com/nuxt/consola/commit/418be28)) + + + +<a name="1.4.0"></a> +# [1.4.0](https://github.com/nuxt/consola/compare/v1.3.0...v1.4.0) (2018-05-27) + + +### Features + +* support custom additional style ([#18](https://github.com/nuxt/consola/issues/18)) ([7a750bf](https://github.com/nuxt/consola/commit/7a750bf)) +* **fancy:** support icon field ([0123bed](https://github.com/nuxt/consola/commit/0123bed)) + + + +<a name="1.3.0"></a> +# [1.3.0](https://github.com/nuxt/consola/compare/v1.2.0...v1.3.0) (2018-04-15) + + +### Bug Fixes + +* **reporters/fancy:** extra space for additional ([efeab44](https://github.com/nuxt/consola/commit/efeab44)) +* prevent duplicate consola instances when different versions used by packages ([0bce262](https://github.com/nuxt/consola/commit/0bce262)) + + +### Features + +* support extra log arguments ([8b6d3d2](https://github.com/nuxt/consola/commit/8b6d3d2)) + + + +<a name="1.2.0"></a> +# [1.2.0](https://github.com/nuxt/consola/compare/v1.1.4...v1.2.0) (2018-04-02) + + +### Features + +* **basic:** support additional field ([b50cad8](https://github.com/nuxt/consola/commit/b50cad8)) +* improve packaging ([158e8ef](https://github.com/nuxt/consola/commit/158e8ef)) + + +### Performance Improvements + +* require needed lodash methods only ([91065e4](https://github.com/nuxt/consola/commit/91065e4)) + + + +<a name="1.1.4"></a> +## [1.1.4](https://github.com/nuxt/consola/compare/v1.1.3...v1.1.4) (2018-03-31) + + +### Bug Fixes + +* **package:** add chalk to dependencies ([3f738e9](https://github.com/nuxt/consola/commit/3f738e9)) + + + +<a name="1.1.3"></a> +## [1.1.3](https://github.com/nuxt/consola/compare/v1.1.2...v1.1.3) (2018-03-31) + + +### Bug Fixes + +* only include dist and src in package ([8b477ec](https://github.com/nuxt/consola/commit/8b477ec)) + + + +<a name="1.1.2"></a> +## [1.1.2](https://github.com/nuxt/consola/compare/v1.1.1...v1.1.2) (2018-03-31) + + +### Bug Fixes + +* handle null and undefined calls ([1f98bb1](https://github.com/nuxt/consola/commit/1f98bb1)) + + + +<a name="1.1.1"></a> +## [1.1.1](https://github.com/nuxt/consola/compare/v1.1.0...v1.1.1) (2018-03-31) + + +### Bug Fixes + +* add prepublish script ([8dd8700](https://github.com/nuxt/consola/commit/8dd8700)) + + + +<a name="1.1.0"></a> +# [1.1.0](https://github.com/nuxt/consola/compare/v1.0.0...v1.1.0) (2018-03-31) + + +### Features + +* rewrite FancyReporter without ora ([73c1ddc](https://github.com/nuxt/consola/commit/73c1ddc)) + + + +<a name="1.0.0"></a> +# [1.0.0](https://github.com/nuxt/consola/compare/v0.1.0...v1.0.0) (2018-03-31) + + + +<a name="0.1.0"></a> +# 0.1.0 (2018-03-31) + + +### Features + +* add log type for console compability ([96a8162](https://github.com/nuxt/consola/commit/96a8162)) diff --git a/node_modules/consola/README.md b/node_modules/consola/README.md new file mode 100644 index 00000000..2d24fb1f --- /dev/null +++ b/node_modules/consola/README.md @@ -0,0 +1,184 @@ +# Consola + +Elegant Console Logger + +## Why Consola? + +- Easy to use +- Fancy output with Fallback for Continuous Integration (CI) environments +- Global mockable stdout/stderr wrapper +- Pluggable reporters +- Consistent Command Line Interface (CLI) experience +- Scoped Loggers + +## Installation + +Using yarn: + +```bash +yarn add consola +``` + +Using npm: + +```bash +npm i consola +``` + +## Getting started + +```js +const consola = require('consola') + +// See types section for all available types +consola.start('Starting build') +consola.success('Built!') +consola.info('Reporter: Some info') +consola.error(new Error('Foo')) +``` + +<div align="center"> +<br> +<img src="./assets/screen1.png" width="600px"> +<p>Fancy Reporter</p> +<br> +</div> + +<pre> +[2:17:17 PM] Starting build +[2:17:17 PM] [TEST] Log from test scope +[2:17:18 PM] Built! +[2:17:18 PM] Some info +[2:17:18 PM] Error: Foo +</pre> +<div align="center"> +<p>Minimal Reporter (CI)</p> +<br> +</div> + +## Scoped Loggers + +Group logs using a scope: + +```js +const logger = consola.withScope('test') + +logger.info('Log from test scope') // [Test] Log from test scope +``` + +## Reporters + +Choose between one of the built-in reporters or bring own reporter. + +By default `FancyReporter` is registered for modern terminals or `BasicReporter` will be used if running in limited environments such as CIs. + +Available reporters: + +- [BasicReporter](./src/reporters/basic.js) +- [FancyReporter](./src/reporters/fancy.js) +- [JSONReporter](./src/reporters/json.js) +- [WinstonReporter](./src/reporters/winston.js) + +Please see [Examples](./examples) for usage info. + +### Creating your own reporter + +A reporter (Class or Object) exposes `log(logObj)` method. +To write a reporter, check implementations to get an idea. + +## Types + +Types can be treated as _extended logging levels_ in Consola's world. + +A list of all available default types is [here](./src/types.js). + +## Creating a new instance + +Consola has a global instance and is recommended to use everywhere. +In case more control is needed, create a new instance. + +```js +const { Consola, BasicReporter } = require('consola') + + +const consola = new Consola({ + level: 30, + reporters: [], + types: [] +}) + +consola.add(BasicReporter) +``` + +## API + +- `consola.<type>([logObj|message|error])` + +Log to all reporters. If a plain string or error is given, then the message will be automatically translated to a logObject. + +- `add(reporter)` + +Register a custom reporter instance. + +- `remove(reporter)` + +Remove a registered reporter. + +- `clear()` + +Remove all current reporters (Useful for writing tests). + +- `withDefaults(defaults)` + +Create a wrapper interface with all types available and `defaults` applied to all logs. + +- `withScope(scope)` + +Shortcut to `withDefaults({ scope })`. + +- `level` + +The level to display logs. Any logs at or above this level will be displayed. +List of available levels [here](./src/types.js) + +## logObject + +logObject is a free-to-extend object which will be passed to reporters. + +Here are standard possible fields: + +Common fields: + +- `message` +- `date` +- `scope` + +Extended fields: + +- `clear` +- `badge` +- `additional` +- `additionalStyle` (By default: `grey`) +- `icon` (Default depends on log type) + +## Integrations + +### With jest + +```js +consola.clear().add({ + log: jest.fn() +}) +``` + +### With jsdom + +```js +{ + virtualConsole: new jsdom.VirtualConsole().sendTo(consola) +} +``` + +## License + +MIT diff --git a/node_modules/consola/dist/consola.cjs.js b/node_modules/consola/dist/consola.cjs.js new file mode 100644 index 00000000..5a99f4a9 --- /dev/null +++ b/node_modules/consola/dist/consola.cjs.js @@ -0,0 +1,428 @@ +'use strict'; + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var chalk = _interopDefault(require('chalk')); +var figures = _interopDefault(require('figures')); +var startCase = _interopDefault(require('lodash/startCase')); +var env = _interopDefault(require('std-env')); + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +function _toArray(arr) { + return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); +} + +function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; +} + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); +} + +var types = { + fatal: { + level: 0, + color: 'red' + }, + error: { + level: 0, + color: 'red' + }, + warn: { + level: 1, + color: 'yellow' + }, + log: { + level: 2, + color: 'white' + }, + info: { + level: 2, + color: 'blue' + }, + start: { + level: 3, + color: 'blue' + }, + success: { + level: 3, + color: 'green' + }, + ready: { + level: 3, + color: 'green' + }, + debug: { + level: 4, + color: 'grey' + }, + trace: { + level: 5, + color: 'white' + } +}; + +var Consola = +/*#__PURE__*/ +function () { + function Consola() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Consola); + + this.reporters = options.reporters || []; + this.types = Object.assign({}, types, options.types); + this.level = options.level != null ? options.level : 3; + Object.assign(this, this.withDefaults()); + } + + _createClass(Consola, [{ + key: "withDefaults", + value: function withDefaults(defaults) { + var logger = {}; + + for (var type in this.types) { + logger[type] = this._createLogFn(Object.assign({ + type: type + }, this.types[type], defaults)); + } + + return logger; + } + }, { + key: "_createLogFn", + value: function _createLogFn(defaults) { + var _this = this; + + return function (opts) { + if (!opts) { + return _this; + } + + var logObj = Object.assign({ + date: new Date() + }, defaults); + + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var argsStr = Array.from(args).map(String).join(' '); + + if (typeof opts === 'string') { + // String + logObj.message = opts; + logObj.additional = argsStr; + } else if (opts.stack) { + // Error + var _opts$stack$split = opts.stack.split('\n'), + _opts$stack$split2 = _toArray(_opts$stack$split), + message = _opts$stack$split2[0], + stack = _opts$stack$split2.slice(1); + + logObj.message = message; + logObj.additional = (argsStr.length ? argsStr + '\n' : '') + stack.map(function (s) { + return s.trim(); + }).join('\n'); + } else { + // Object + Object.assign(logObj, opts); + } + + _this._log(logObj); + + return _this; + }; + } + }, { + key: "_log", + value: function _log(logObj) { + if (logObj.level > this.level) { + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.reporters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var reporter = _step.value; + reporter.log(logObj); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return this; + } + }, { + key: "add", + value: function add(reporter) { + this.reporters.push(reporter); + return this; + } + }, { + key: "clear", + value: function clear() { + this.reporters.splice(0); + return this; + } + }, { + key: "remove", + value: function remove(reporter) { + var i = this.reporters.indexOf(reporter); + + if (i >= 0) { + return this.reporters.splice(i, 1); + } + + return this; + } + }, { + key: "withScope", + value: function withScope(scope) { + return this.withDefaults({ + scope: scope + }); + } + }]); + + return Consola; +}(); // Upward compatibility support to >= v2 +Consola.prototype.addReporter = Consola.prototype.add; +Consola.prototype.removeReporter = Consola.prototype.remove; +Consola.prototype.removeReporter = Consola.prototype.clear; +Consola.prototype.withTag = Consola.prototype.withScope; + +var BasicReporter = +/*#__PURE__*/ +function () { + function BasicReporter(stream) { + _classCallCheck(this, BasicReporter); + + this.stream = stream || process.stdout; + } + + _createClass(BasicReporter, [{ + key: "formatTag", + value: function formatTag(tag) { + return "[".concat(tag.toUpperCase(), "]"); + } + }, { + key: "log", + value: function log(logObj) { + var l = [this.formatTag(logObj.date.toLocaleTimeString())]; + + if (logObj.scope) { + l.push(this.formatTag(logObj.scope)); + } + + l.push(logObj.message); + this.stream.write(l.join(' ') + '\n'); + + if (logObj.additional) { + this.stream.write(logObj.additional + '\n'); + } + } + }]); + + return BasicReporter; +}(); + +var NS_SEPARATOR = chalk.blue(figures(' › ')); +var ICONS = { + start: figures('●'), + info: figures('ℹ'), + success: figures('✔'), + error: figures('✖'), + fatal: figures('✖'), + warn: figures('⚠'), + debug: figures('…'), + trace: figures('…'), + default: figures('❯'), + ready: figures('♥') +}; + +var FancyReporter = +/*#__PURE__*/ +function () { + function FancyReporter(stream) { + + _classCallCheck(this, FancyReporter); + + this.stream = stream || process.stderr; + } + + _createClass(FancyReporter, [{ + key: "formatBadge", + value: function formatBadge(type) { + var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'blue'; + return chalk['bg' + startCase(color)].black(" ".concat(type.toUpperCase(), " ")) + ' '; + } + }, { + key: "formatTag", + value: function formatTag(type) { + var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'blue'; + var icon = arguments.length > 2 ? arguments[2] : undefined; + return chalk[color]("".concat(icon, " ").concat(type.toLowerCase())) + ' '; + } + }, { + key: "clear", + value: function clear() { + this.stream.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'); + } + }, { + key: "log", + value: function log(logObj) { + var message = logObj.message; + + if (logObj.scope) { + message = (logObj.scope.replace(/:/g, '>') + '>').split('>').join(NS_SEPARATOR) + message; + } + + if (logObj.clear) { + this.clear(); + } + + var icon = logObj.icon || ICONS[logObj.type] || ICONS.default; + + if (logObj.badge) { + this.stream.write('\n\n' + this.formatBadge(logObj.type, logObj.color, icon) + message + '\n\n'); + } else { + this.stream.write(this.formatTag(logObj.type, logObj.color, icon) + message + '\n'); + } + + if (logObj.additional) { + var lines = logObj.additional.split('\n').map(function (s) { + return ' ' + s; + }).join('\n'); + this.stream.write(chalk[logObj.additionalStyle || 'grey'](lines) + '\n'); + } + } + }]); + + return FancyReporter; +}(); + +var JSONReporter = +/*#__PURE__*/ +function () { + function JSONReporter(stream) { + _classCallCheck(this, JSONReporter); + + this.stream = stream || process.stdout; + } + + _createClass(JSONReporter, [{ + key: "log", + value: function log(logObj) { + this.stream.write(JSON.stringify(logObj) + '\n'); + } + }]); + + return JSONReporter; +}(); + +// This reporter is compatible with Winston 3 +// https://github.com/winstonjs/winston +var WinstonReporter = +/*#__PURE__*/ +function () { + function WinstonReporter(logger) { + _classCallCheck(this, WinstonReporter); + + this.logger = logger; + } + + _createClass(WinstonReporter, [{ + key: "log", + value: function log(logObj) { + this.logger.log({ + level: levels[logObj.level] || 'info', + label: logObj.tag, + message: logObj.message, + timestamp: logObj.date.getTime() / 1000 + }); + } + }]); + + return WinstonReporter; +}(); +var levels = { + 0: 'error', + 1: 'warn', + 2: 'info', + 3: 'verbose', + 4: 'debug', + 5: 'silly' +}; + +var Reporters = { + BasicReporter: BasicReporter, + FancyReporter: FancyReporter, + JSONReporter: JSONReporter, + WinstonReporter: WinstonReporter +}; + +// duplicated instances when used with different packages/versions + +var consola = global && global.consola; + +if (!consola) { + consola = new Consola({ + level: env.debug ? 4 : 3 + }); + + if (env.minimalCLI) { + consola.add(new Reporters.BasicReporter()); + } else { + consola.add(new Reporters.FancyReporter()); + } + + Object.assign(consola, { + Consola: Consola + }, Reporters); + global.consola = consola; +} + +var consola$1 = consola; + +module.exports = consola$1; diff --git a/node_modules/consola/dist/consola.js b/node_modules/consola/dist/consola.js new file mode 100644 index 00000000..95b4ccb1 --- /dev/null +++ b/node_modules/consola/dist/consola.js @@ -0,0 +1,394 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.consola = factory()); +}(this, (function () { 'use strict'; + + var Types = { + // Level 0 + fatal: { + level: 0 + }, + error: { + level: 0 + }, + // Level 1 + warn: { + level: 1 + }, + // Level 2 + log: { + level: 2 + }, + // Level 3 + info: { + level: 3 + }, + success: { + level: 3 + }, + // Level 4 + debug: { + level: 4 + }, + // Level 5 + trace: { + level: 5 + }, + // Silent + silent: { + level: Infinity + }, + // Legacy + ready: { + level: 3 + }, + start: { + level: 3 + } + }; + + function isPlainObject(obj) { + return Object.prototype.toString.call(obj) === '[object Object]'; + } + function isLogObj(arg) { + // Should be plain object + // Also contains either message or args field + return isPlainObject(arg) && Boolean(arg.message || arg.args); + } + + let paused = false; + const queue = []; + class Consola { + constructor(options = {}) { + this._reporters = options.reporters || []; + this._types = options.types || Types; + this._level = options.level != null ? options.level : 3; + this._defaults = options.defaults || {}; + this._async = typeof options.async !== 'undefined' ? options.async : null; + this._stdout = options.stdout; + this._stderr = options.stdout; + this._mockFn = options.mockFn; // Create logger functions for current instance + + for (const type in this._types) { + this[type] = this._wrapLogFn(Object.assign({ + type + }, this._types[type], this._defaults)); + } // Use _mockFn if is set + + + if (this._mockFn) { + this.mockTypes(); + } + } + + get level() { + return this._level; + } + + set level(newLevel) { + // Ensure that newLevel does not exceeds type level boundaries + let min = 0; + let max = 0; + + for (const typeName in this._types) { + const type = this._types[typeName]; + + if (type.level > max) { + max = type.level; + } else if (type.level < min) { + min = type.level; + } + } // Set level + + + this._level = Math.min(max, Math.max(min, newLevel)); + } + + get stdout() { + return this._stdout || console._stdout; // eslint-disable-line no-console + } + + get stderr() { + return this._stderr || console._stderr; // eslint-disable-line no-console + } + + create(options) { + return new Consola(Object.assign({ + reporters: this._reporters, + level: this._level, + types: this._types, + defaults: this._defaults, + stdout: this._stdout, + stderr: this._stderr, + mockFn: this._mockFn + }, options)); + } + + addReporter(reporter) { + this._reporters.push(reporter); + + return this; + } + + removeReporter(reporter) { + if (reporter) { + const i = this._reporters.indexOf(reporter); + + if (i >= 0) { + return this._reporters.splice(i, 1); + } + } else { + this._reporters.splice(0); + } + + return this; + } + + setReporters(reporters) { + this._reporters = Array.isArray(reporters) ? reporters : [reporters]; + } + + withDefaults(defaults) { + return this.create({ + defaults: Object.assign({}, this._defaults, defaults) + }); + } + + withTag(tag) { + return this.withDefaults({ + tag: this._defaults.tag ? this._defaults.tag + ':' + tag : tag + }); + } + + wrapAll() { + this.wrapConsole(); + this.wrapStd(); + } + + restoreAll() { + this.restoreConsole(); + this.restoreStd(); + } + + wrapConsole() { + for (const type in this._types) { + // Backup original value + if (!console['__' + type]) { + // eslint-disable-line no-console + console['__' + type] = console[type]; // eslint-disable-line no-console + } // Override + + + console[type] = this[type]; // eslint-disable-line no-console + } + } + + restoreConsole() { + for (const type in this._types) { + // Restore if backup is available + if (console['__' + type]) { + // eslint-disable-line no-console + console[type] = console['__' + type]; // eslint-disable-line no-console + + delete console['__' + type]; // eslint-disable-line no-console + } + } + } + + wrapStd() { + this._wrapStream(this.stdout, 'log'); + + this._wrapStream(this.stderr, 'log'); + } + + _wrapStream(stream, type) { + if (!stream) { + return; + } // Backup original value + + + if (!stream.__write) { + stream.__write = stream.write; + } // Override + + + stream.write = data => { + this[type](String(data).trim()); + }; + } + + restoreStd() { + this._restoreStream(this.stdout); + + this._restoreStream(this.stderr); + } + + _restoreStream(stream) { + if (!stream) { + return; + } + + if (stream.__write) { + stream.write = stream.__write; + delete stream.__write; + } + } + + pauseLogs() { + paused = true; + } + + resumeLogs() { + paused = false; // Process queue + + const _queue = queue.splice(0); + + for (const item of _queue) { + item[0]._logFn(item[1], item[2]); + } + } + + mockTypes(mockFn) { + this._mockFn = mockFn || this._mockFn; + + if (typeof this._mockFn !== 'function') { + return; + } + + for (const type in this._types) { + this[type] = this._mockFn(type, this._types[type]) || this[type]; + } + } + + _wrapLogFn(defaults) { + function logFn() { + if (paused) { + queue.push([this, defaults, arguments]); + return; + } + + return this._logFn(defaults, arguments); + } + + return logFn.bind(this); + } + + _logFn(defaults, args) { + if (defaults.level > this._level) { + return this._async ? Promise.resolve(false) : false; + } // Construct a new log object + + + const logObj = Object.assign({ + date: new Date(), + args: [] + }, defaults); // Consume arguments + + if (args.length === 1 && isLogObj(args[0])) { + Object.assign(logObj, args[0]); + } else { + logObj.args = Array.from(args); + } // Aliases + + + if (logObj.message) { + logObj.args.unshift(logObj.message); + delete logObj.message; + } + + if (logObj.additional) { + if (!Array.isArray(logObj.additional)) { + logObj.additional = logObj.additional.split('\n'); + } + + logObj.args.push('\n' + logObj.additional.join('\n')); + delete logObj.additional; + } // Log + + + if (this._async) { + return this._logAsync(logObj); + } else { + this._log(logObj); + } + } + + _log(logObj) { + for (const reporter of this._reporters) { + reporter.log(logObj, { + async: false, + stdout: this.stdout, + stderr: this.stderr + }); + } + } + + _logAsync(logObj) { + return Promise.all(this._reporters.map(reporter => reporter.log(logObj, { + async: true, + stdout: this.stdout, + stderr: this.stderr + }))); + } + + } // Legacy support + + Consola.prototype.add = Consola.prototype.addReporter; + Consola.prototype.remove = Consola.prototype.removeReporter; + Consola.prototype.clear = Consola.prototype.removeReporter; + Consola.prototype.withScope = Consola.prototype.withTag; + Consola.prototype.mock = Consola.prototype.mockTypes; + Consola.prototype.pause = Consola.prototype.pauseLogs; + Consola.prototype.resume = Consola.prototype.resumeLogs; + + const TYPE_COLOR_MAP = { + 'info': 'cyan' + }; + const LEVEL_COLOR_MAP = { + 0: 'red', + 1: 'yellow', + 2: 'white', + 3: 'green' + }; + + class BrowserReporter { + constructor(options) { + this.options = Object.assign({}, options); + } + + log(logObj) { + // consoleLogFn + let consoleLogFn = console[logObj.type]; // eslint-disable-line no-console + + if (!consoleLogFn) { + consoleLogFn = console[logObj.level < 2 ? 'error' : 'log']; // eslint-disable-line no-console + } // Type + + + const type = logObj.type.toUpperCase(); // Styles + + const color = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level]; + const styleColor = `color: ${color}; background-color: inherit;`; + const styleInherit = `color: inherit; background-color: inherit;`; + const styleAdditional = `color: ${logObj.additionalColor || 'grey'}; background-color: inherit;`; // Date + + const date = new Date(logObj.date).toLocaleTimeString(); // Log to the console + + consoleLogFn(`%c[${type}]%c[${date}]%c`, styleColor, styleAdditional, styleInherit, ...logObj.args); + } + + } + + if (!window.consola) { + // Create new consola instance + window.consola = new Consola({ + reporters: [new BrowserReporter()] + }); + } + + var browser = window.consola; + + return browser; + +}))); diff --git a/node_modules/consola/package.json b/node_modules/consola/package.json new file mode 100644 index 00000000..e8d671fb --- /dev/null +++ b/node_modules/consola/package.json @@ -0,0 +1,58 @@ +{ + "name": "consola", + "version": "1.4.5", + "description": "Elegant Console Logger", + "main": "./dist/consola.cjs.js", + "module": "./src/index.js", + "scripts": { + "build": "bili", + "test": "true", + "prepublish": "yarn build", + "release": "standard-version && yarn build && git push --follow-tags && npm publish" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/nuxt/consola.git" + }, + "files": [ + "dist", + "src", + "index.js" + ], + "keywords": [ + "console", + "logger", + "reporter", + "elegant", + "cli", + "universal", + "unified", + "winston" + ], + "author": "Pooya Parsa <pooya@pi0.ir>", + "license": "MIT", + "bugs": { + "url": "https://github.com/nuxt/consola/issues" + }, + "homepage": "https://github.com/nuxt/consola#readme", + "dependencies": { + "chalk": "^2.3.2", + "figures": "^2.0.0", + "lodash": "^4.17.5", + "std-env": "^1.1.0" + }, + "devDependencies": { + "bili": "^3.0.14", + "eslint": "^4.17.0", + "eslint-config-standard": "11.0.0", + "eslint-plugin-import": "^2.11.0", + "eslint-plugin-jest": "latest", + "eslint-plugin-node": "6.0.1", + "eslint-plugin-promise": "latest", + "eslint-plugin-standard": "latest", + "eslint-plugin-vue": "latest", + "esm": "^3.0.14", + "standard-version": "^4.3.0", + "winston": "^3.0.0-rc3" + } +} diff --git a/node_modules/consola/src/cjs.js b/node_modules/consola/src/cjs.js new file mode 100644 index 00000000..85e02904 --- /dev/null +++ b/node_modules/consola/src/cjs.js @@ -0,0 +1 @@ +module.exports = require('esm')(module, { mode: 'all' })('./index.js').default diff --git a/node_modules/consola/src/consola.js b/node_modules/consola/src/consola.js new file mode 100644 index 00000000..205b4ad5 --- /dev/null +++ b/node_modules/consola/src/consola.js @@ -0,0 +1,91 @@ +import types from './types' + +export default class Consola { + constructor (options = {}) { + this.reporters = options.reporters || [] + this.types = Object.assign({}, types, options.types) + this.level = options.level != null ? options.level : 3 + + Object.assign(this, this.withDefaults()) + } + + withDefaults (defaults) { + const logger = {} + for (const type in this.types) { + logger[type] = this._createLogFn(Object.assign({ type }, this.types[type], defaults)) + } + return logger + } + + _createLogFn (defaults) { + return (opts, ...args) => { + if (!opts) { + return this + } + + const logObj = Object.assign({ + date: new Date() + }, defaults) + + const argsStr = Array.from(args).map(String).join(' ') + + if (typeof opts === 'string') { + // String + logObj.message = opts + logObj.additional = argsStr + } else if (opts.stack) { + // Error + const [message, ...stack] = opts.stack.split('\n') + logObj.message = message + logObj.additional = (argsStr.length ? argsStr + '\n' : '') + stack.map(s => s.trim()).join('\n') + } else { + // Object + Object.assign(logObj, opts) + } + + this._log(logObj) + + return this + } + } + + _log (logObj) { + if (logObj.level > this.level) { + return + } + for (const reporter of this.reporters) { + reporter.log(logObj) + } + return this + } + + add (reporter) { + this.reporters.push(reporter) + return this + } + + clear () { + this.reporters.splice(0) + return this + } + + remove (reporter) { + const i = this.reporters.indexOf(reporter) + if (i >= 0) { + return this.reporters.splice(i, 1) + } + return this + } + + withScope (scope) { + return this.withDefaults({ scope }) + } +} + +// Upward compatibility support to >= v2 +Consola.prototype.addReporter = Consola.prototype.add + +Consola.prototype.removeReporter = Consola.prototype.remove +Consola.prototype.removeReporter = Consola.prototype.clear + +Consola.prototype.withTag = Consola.prototype.withScope diff --git a/node_modules/consola/src/index.js b/node_modules/consola/src/index.js new file mode 100644 index 00000000..d1c0d9d7 --- /dev/null +++ b/node_modules/consola/src/index.js @@ -0,0 +1,26 @@ +import env from 'std-env' +import Consola from './consola' +import Reporters from './reporters' + +// Attach consola to the global to prevent +// duplicated instances when used with different packages/versions + +let consola = global && global.consola + +if (!consola) { + consola = new Consola({ + level: env.debug ? 4 : 3 + }) + + if (env.minimalCLI) { + consola.add(new Reporters.BasicReporter()) + } else { + consola.add(new Reporters.FancyReporter()) + } + + Object.assign(consola, { Consola }, Reporters) + + global.consola = consola +} + +export default consola diff --git a/node_modules/consola/src/reporters/basic.js b/node_modules/consola/src/reporters/basic.js new file mode 100644 index 00000000..e6e9fff4 --- /dev/null +++ b/node_modules/consola/src/reporters/basic.js @@ -0,0 +1,25 @@ +export default class BasicReporter { + constructor (stream) { + this.stream = stream || process.stdout + } + + formatTag (tag) { + return `[${tag.toUpperCase()}]` + } + + log (logObj) { + let l = [this.formatTag(logObj.date.toLocaleTimeString())] + + if (logObj.scope) { + l.push(this.formatTag(logObj.scope)) + } + + l.push(logObj.message) + + this.stream.write(l.join(' ') + '\n') + + if (logObj.additional) { + this.stream.write(logObj.additional + '\n') + } + } +} diff --git a/node_modules/consola/src/reporters/fancy.js b/node_modules/consola/src/reporters/fancy.js new file mode 100644 index 00000000..f26ad85a --- /dev/null +++ b/node_modules/consola/src/reporters/fancy.js @@ -0,0 +1,63 @@ +import chalk from 'chalk' +import figures from 'figures' +import startCase from 'lodash/startCase' + +const NS_SEPARATOR = chalk.blue(figures(' › ')) + +const ICONS = { + start: figures('●'), + info: figures('ℹ'), + success: figures('✔'), + error: figures('✖'), + fatal: figures('✖'), + warn: figures('⚠'), + debug: figures('…'), + trace: figures('…'), + default: figures('❯'), + ready: figures('♥') +} + +export default class FancyReporter { + constructor (stream, options = {}) { + this.stream = stream || process.stderr + } + + formatBadge (type, color = 'blue', icon) { + return chalk['bg' + startCase(color)].black(` ${type.toUpperCase()} `) + ' ' + } + + formatTag (type, color = 'blue', icon) { + return chalk[color](`${icon} ${type.toLowerCase()}`) + ' ' + } + + clear () { + this.stream.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H') + } + + log (logObj) { + let message = logObj.message + + if (logObj.scope) { + message = + (logObj.scope.replace(/:/g, '>') + '>').split('>').join(NS_SEPARATOR) + + message + } + + if (logObj.clear) { + this.clear() + } + + const icon = logObj.icon || ICONS[logObj.type] || ICONS.default + + if (logObj.badge) { + this.stream.write('\n\n' + this.formatBadge(logObj.type, logObj.color, icon) + message + '\n\n') + } else { + this.stream.write(this.formatTag(logObj.type, logObj.color, icon) + message + '\n') + } + + if (logObj.additional) { + const lines = logObj.additional.split('\n').map(s => ' ' + s).join('\n') + this.stream.write(chalk[logObj.additionalStyle || 'grey'](lines) + '\n') + } + } +} diff --git a/node_modules/consola/src/reporters/index.js b/node_modules/consola/src/reporters/index.js new file mode 100644 index 00000000..6866822d --- /dev/null +++ b/node_modules/consola/src/reporters/index.js @@ -0,0 +1,11 @@ +import BasicReporter from './basic' +import FancyReporter from './fancy' +import JSONReporter from './json' +import WinstonReporter from './winston' + +export default { + BasicReporter, + FancyReporter, + JSONReporter, + WinstonReporter +} diff --git a/node_modules/consola/src/reporters/json.js b/node_modules/consola/src/reporters/json.js new file mode 100644 index 00000000..8909f674 --- /dev/null +++ b/node_modules/consola/src/reporters/json.js @@ -0,0 +1,9 @@ +export default class JSONReporter { + constructor (stream) { + this.stream = stream || process.stdout + } + + log (logObj) { + this.stream.write(JSON.stringify(logObj) + '\n') + } +} diff --git a/node_modules/consola/src/reporters/winston.js b/node_modules/consola/src/reporters/winston.js new file mode 100644 index 00000000..88c821fd --- /dev/null +++ b/node_modules/consola/src/reporters/winston.js @@ -0,0 +1,26 @@ +// This reporter is compatible with Winston 3 +// https://github.com/winstonjs/winston + +export default class WinstonReporter { + constructor (logger) { + this.logger = logger + } + + log (logObj) { + this.logger.log({ + level: levels[logObj.level] || 'info', + label: logObj.tag, + message: logObj.message, + timestamp: logObj.date.getTime() / 1000 + }) + } +} + +const levels = { + 0: 'error', + 1: 'warn', + 2: 'info', + 3: 'verbose', + 4: 'debug', + 5: 'silly' +} diff --git a/node_modules/consola/src/types.js b/node_modules/consola/src/types.js new file mode 100644 index 00000000..45821974 --- /dev/null +++ b/node_modules/consola/src/types.js @@ -0,0 +1,42 @@ +export default { + fatal: { + level: 0, + color: 'red' + }, + error: { + level: 0, + color: 'red' + }, + warn: { + level: 1, + color: 'yellow' + }, + log: { + level: 2, + color: 'white' + }, + info: { + level: 2, + color: 'blue' + }, + start: { + level: 3, + color: 'blue' + }, + success: { + level: 3, + color: 'green' + }, + ready: { + level: 3, + color: 'green' + }, + debug: { + level: 4, + color: 'grey' + }, + trace: { + level: 5, + color: 'white' + } +} |
