Skip to content

Commit

Permalink
feat: support all chalk colors
Browse files Browse the repository at this point in the history
also removes dependency from lodash.startCase. Fixes #20.
  • Loading branch information
pi0 committed Oct 5, 2018
1 parent d2402af commit 2cec678
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"chalk": "^2.4.1",
"figures": "^2.0.0",
"lodash": "^4.17.11",
"std-env": "^2.0.2"
},
"devDependencies": {
Expand All @@ -48,6 +47,7 @@
"eslint-plugin-vue": "^4.7.1",
"esm": "^3.0.84",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"standard-version": "^4.4.0",
"winston": "^3.1.0"
}
Expand Down
19 changes: 16 additions & 3 deletions src/reporters/fancy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import chalk from 'chalk'
import figures from 'figures'
import startCase from 'lodash/startCase'
import { formatStack } from '../utils'

const NS_SEPARATOR = chalk.blue(figures(' › '))
Expand All @@ -18,17 +17,31 @@ const ICONS = {
ready: figures('♥')
}

function chalkColor (name) {
if (name[0] === '#') {
return chalk.hex(name)
}
return chalk[name] || chalk.keyword(name)
}

function chalkBgColor (name) {
if (name[0] === '#') {
return chalk.bgHex(name)
}
return chalk['bg' + name[0] + name.slice(1)] || chalk.bgKeyword(name)
}

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()} `) + ' '
return chalkBgColor(color).black(` ${type.toUpperCase()} `) + ' '
}

formatTag (type, color = 'blue', icon) {
return chalk[color](`${icon} ${type.toLowerCase()}`) + ' '
return chalkColor(color)(`${icon} ${type.toUpperCase()}`) + ' '
}

clear () {
Expand Down

0 comments on commit 2cec678

Please sign in to comment.