From 2cec67851344eb9ccfbb0c77528546e402befb3c Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 5 Oct 2018 15:30:23 +0330 Subject: [PATCH] feat: support all chalk colors also removes dependency from lodash.startCase. Fixes #20. --- package.json | 2 +- src/reporters/fancy.js | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 28ba9436..4378d8b2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "dependencies": { "chalk": "^2.4.1", "figures": "^2.0.0", - "lodash": "^4.17.11", "std-env": "^2.0.2" }, "devDependencies": { @@ -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" } diff --git a/src/reporters/fancy.js b/src/reporters/fancy.js index d80d08dd..a62678dc 100644 --- a/src/reporters/fancy.js +++ b/src/reporters/fancy.js @@ -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(' › ')) @@ -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 () {