aboutsummaryrefslogtreecommitdiff
path: root/node_modules/consola/src
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/consola/src')
-rw-r--r--node_modules/consola/src/cjs.js1
-rw-r--r--node_modules/consola/src/consola.js91
-rw-r--r--node_modules/consola/src/index.js26
-rw-r--r--node_modules/consola/src/reporters/basic.js25
-rw-r--r--node_modules/consola/src/reporters/fancy.js63
-rw-r--r--node_modules/consola/src/reporters/index.js11
-rw-r--r--node_modules/consola/src/reporters/json.js9
-rw-r--r--node_modules/consola/src/reporters/winston.js26
-rw-r--r--node_modules/consola/src/types.js42
9 files changed, 294 insertions, 0 deletions
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'
+ }
+}