Skip to content

Commit 1c7cc0b

Browse files
author
Pooya Parsa
committed
feat: support hex colors. (#2)
1 parent 32330a4 commit 1c7cc0b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chalk from 'chalk';
33
import _ from 'lodash';
44
import logUpdate from 'log-update';
55
import Profile from './profile';
6-
import { BULLET, parseRequst, formatRequest, renderBar, printStats } from './utils';
6+
import { BULLET, parseRequst, formatRequest, renderBar, printStats, colorize } from './utils';
77

88
const sharedState = {};
99

@@ -83,7 +83,7 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
8383
return;
8484
}
8585

86-
const lColor = chalk.keyword(state.color);
86+
const lColor = colorize(state.color);
8787
const lIcon = lColor(BULLET);
8888
const lName = lColor(_.startCase(name));
8989
const lBar = renderBar(state.progress, state.color);

src/utils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ const NEXT = chalk.blue(figures(' › '));
1616

1717
export const BULLET = figures('●');
1818

19+
export const colorize = (color) => {
20+
if (color[0] === '#') {
21+
return chalk.hex(color);
22+
}
23+
24+
return chalk.color(color);
25+
};
26+
1927
export const renderBar = (progress, color) => {
2028
const w = progress * (BAR_LENGTH / 100);
2129
const bg = chalk.white(BLOCK_CHAR);
22-
const fg = chalk.keyword(color)(BLOCK_CHAR2);
30+
const fg = colorize(color)(BLOCK_CHAR2);
2331

2432
return BAR_BEFORE +
2533
_.range(BAR_LENGTH).map(i => (i < w ? fg : bg)).join('') +

test/basic.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('webpackbar', () => {
1919
const compiler = webpack(basicConfig.from({
2020
name: 'test1',
2121
profile: true,
22+
color: '#202020',
2223
logUpdate,
2324
}));
2425

0 commit comments

Comments
 (0)