diff --git a/src/index.js b/src/index.js index 9fa3d3f..5437519 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ import chalk from 'chalk'; import _ from 'lodash'; import logUpdate from 'log-update'; import Profile from './profile'; -import { BULLET, parseRequst, formatRequest, renderBar, printStats } from './utils'; +import { BULLET, parseRequst, formatRequest, renderBar, printStats, colorize } from './utils'; const sharedState = {}; @@ -83,7 +83,7 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin { return; } - const lColor = chalk.keyword(state.color); + const lColor = colorize(state.color); const lIcon = lColor(BULLET); const lName = lColor(_.startCase(name)); const lBar = renderBar(state.progress, state.color); diff --git a/src/utils.js b/src/utils.js index 6e1fcbc..7c019c3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -16,10 +16,18 @@ const NEXT = chalk.blue(figures(' › ')); export const BULLET = figures('●'); +export const colorize = (color) => { + if (color[0] === '#') { + return chalk.hex(color); + } + + return chalk.color(color); +}; + export const renderBar = (progress, color) => { const w = progress * (BAR_LENGTH / 100); const bg = chalk.white(BLOCK_CHAR); - const fg = chalk.keyword(color)(BLOCK_CHAR2); + const fg = colorize(color)(BLOCK_CHAR2); return BAR_BEFORE + _.range(BAR_LENGTH).map(i => (i < w ? fg : bg)).join('') + diff --git a/test/basic.test.js b/test/basic.test.js index 8a83308..8b53981 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -19,6 +19,7 @@ describe('webpackbar', () => { const compiler = webpack(basicConfig.from({ name: 'test1', profile: true, + color: '#202020', logUpdate, }));