Skip to content

Commit 73c1ddc

Browse files
author
Pooya Parsa
committed
feat: rewrite FancyReporter without ora
1 parent 47f9bb0 commit 73c1ddc

File tree

6 files changed

+35
-59
lines changed

6 files changed

+35
-59
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Elegant Console Logger
88
- Fancy output with Fallback for CI environments
99
- A global mockable stdout/stderr wrapper
1010
- Pluggable reporters
11-
- [ORA](https://github.com/sindresorhus/ora) integration
1211
- Consistance CLI experience
1312
- Scoped Loggers
1413

assets/screen1.png

22.6 KB
Loading

examples/basic.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ const consola = require('..')
22

33
consola.start('Starting build')
44

5+
consola.warn('Something is going to happen soon')
6+
57
setTimeout(() => {
6-
consola.success('Built!')
7-
consola.info('Some info')
8-
consola.error(new Error('Foo'))
8+
consola.success('Build succeed in 10 seconds')
9+
consola.info('Some extra info is here')
10+
consola.debug('Hum hum hum')
11+
consola.error(new Error('consola is awesome'))
12+
consola.fatal('This is the end!')
913
}, 1500)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"homepage": "https://github.com/nuxt/consola#readme",
3131
"dependencies": {
3232
"figures": "^2.0.0",
33-
"ora": "^2.0.0",
33+
"lodash": "^4.17.5",
3434
"std-env": "^1.1.0"
3535
},
3636
"devDependencies": {

src/reporters/fancy.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
import chalk from 'chalk'
2-
import ORA from 'ora'
32
import figures from 'figures'
3+
import _ from 'lodash'
44

55
const NS_SEPERATOR = chalk.blue(figures(' › '))
66

7-
const ORA_FN = {
8-
start: 'start',
9-
success: 'succeed',
10-
error: 'fail',
11-
warn: 'warn',
12-
info: 'info'
7+
const ICONS = {
8+
start: figures('●'),
9+
info: figures('ℹ'),
10+
success: figures('✔'),
11+
error: figures('✖'),
12+
fatal: figures('✖'),
13+
warn: figures('⚠'),
14+
debug: figures('…'),
15+
trace: figures('…'),
16+
default: figures('❯'),
17+
ready: figures('♥')
1318
}
1419

20+
const pad = str => _.padEnd(str, 9)
21+
1522
export default class FancyReporter {
1623
constructor (stream, options = {}) {
1724
this.stream = stream || process.stderr
25+
}
1826

19-
this.ora = new ORA(this.stream, Object.assign({
20-
hideCursor: false
21-
}, options.ora))
27+
formatBadge (type, color = 'blue') {
28+
return chalk['bg' + _.startCase(color)].black(` ${type.toUpperCase()} `) + ' '
2229
}
2330

2431
formatTag (type, color = 'blue') {
25-
return chalk.bgKeyword(color).black(` ${type.toUpperCase()} `)
32+
const icon = ICONS[type] || ICONS.default
33+
return chalk[color](pad(`${icon} ${type.toLowerCase()}`)) + ' '
2634
}
2735

2836
clear () {
@@ -33,26 +41,24 @@ export default class FancyReporter {
3341
let message = logObj.message
3442

3543
if (logObj.scope) {
36-
message = logObj.scope.replace(/:/g, '>') + '>' + message
44+
message =
45+
(logObj.scope.replace(/:/g, '>') + '>').split('>').join(NS_SEPERATOR) +
46+
message
3747
}
3848

39-
message = message.replace(/>/g, NS_SEPERATOR)
40-
4149
if (logObj.clear) {
4250
this.clear()
4351
}
4452

45-
const oraFn = ORA_FN[logObj.type]
46-
47-
if (oraFn && logObj.badge !== true) {
48-
this.ora[oraFn](message)
53+
if (logObj.badge) {
54+
this.stream.write('\n\n' + this.formatBadge(logObj.type, logObj.color) + message + '\n\n')
4955
} else {
50-
this.stream.write('\n\n' + this.formatTag(logObj.type, logObj.color) + ' ' + message + '\n\n')
56+
this.stream.write(this.formatTag(logObj.type, logObj.color) + message + '\n')
5157
}
5258

5359
if (logObj.additional) {
5460
const lines = logObj.additional.split('\n').map(s => ' ' + s).join('\n')
55-
this.stream.write(chalk.grey(lines) + '\n\n')
61+
this.stream.write(chalk.grey(lines) + '\n')
5662
}
5763
}
5864
}

yarn.lock

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,6 @@ cli-cursor@^2.0.0, cli-cursor@^2.1.0:
994994
dependencies:
995995
restore-cursor "^2.0.0"
996996

997-
cli-spinners@^1.1.0:
998-
version "1.1.0"
999-
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.1.0.tgz#f1847b168844d917a671eb9d147e3df497c90d06"
1000-
1001997
cli-width@^2.0.0:
1002998
version "2.2.0"
1003999
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
@@ -1420,12 +1416,6 @@ deep-is@~0.1.3:
14201416
version "0.1.3"
14211417
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
14221418

1423-
defaults@^1.0.3:
1424-
version "1.0.3"
1425-
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
1426-
dependencies:
1427-
clone "^1.0.2"
1428-
14291419
defined@^1.0.0:
14301420
version "1.0.0"
14311421
resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"
@@ -2459,16 +2449,10 @@ lodash.uniq@^4.5.0:
24592449
version "4.5.0"
24602450
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
24612451

2462-
lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0:
2452+
lodash@^4.14.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0:
24632453
version "4.17.5"
24642454
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
24652455

2466-
log-symbols@^2.2.0:
2467-
version "2.2.0"
2468-
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
2469-
dependencies:
2470-
chalk "^2.0.1"
2471-
24722456
log-update@^2.3.0:
24732457
version "2.3.0"
24742458
resolved "https://registry.yarnpkg.com/log-update/-/log-update-2.3.0.tgz#88328fd7d1ce7938b29283746f0b1bc126b24708"
@@ -2743,17 +2727,6 @@ optionator@^0.8.2:
27432727
type-check "~0.3.2"
27442728
wordwrap "~1.0.0"
27452729

2746-
ora@^2.0.0:
2747-
version "2.0.0"
2748-
resolved "https://registry.yarnpkg.com/ora/-/ora-2.0.0.tgz#8ec3a37fa7bffb54a3a0c188a1f6798e7e1827cd"
2749-
dependencies:
2750-
chalk "^2.3.1"
2751-
cli-cursor "^2.1.0"
2752-
cli-spinners "^1.1.0"
2753-
log-symbols "^2.2.0"
2754-
strip-ansi "^4.0.0"
2755-
wcwidth "^1.0.1"
2756-
27572730
os-homedir@^1.0.1:
27582731
version "1.0.2"
27592732
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
@@ -4021,12 +3994,6 @@ vue-eslint-parser@^2.0.3:
40213994
esquery "^1.0.0"
40223995
lodash "^4.17.4"
40233996

4024-
wcwidth@^1.0.1:
4025-
version "1.0.1"
4026-
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
4027-
dependencies:
4028-
defaults "^1.0.3"
4029-
40303997
whet.extend@~0.9.9:
40313998
version "0.9.9"
40323999
resolved "https://registry.yarnpkg.com/whet.extend/-/whet.extend-0.9.9.tgz#f877d5bf648c97e5aa542fadc16d6a259b9c11a1"

0 commit comments

Comments
 (0)