Skip to content

Commit

Permalink
feat: support hex colors. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Mar 27, 2018
1 parent 32330a4 commit 1c7cc0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('') +
Expand Down
1 change: 1 addition & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('webpackbar', () => {
const compiler = webpack(basicConfig.from({
name: 'test1',
profile: true,
color: '#202020',
logUpdate,
}));

Expand Down

1 comment on commit 1c7cc0b

@huchenme
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.