@@ -7,7 +7,14 @@ import { BULLET, parseRequst, formatRequest, renderBar, printStats, colorize } f
7
7
8
8
const sharedState = { } ;
9
9
10
- const defaults = { name : 'webpack' , color : 'green' , profile : false } ;
10
+ const defaults = {
11
+ name : 'webpack' ,
12
+ color : 'green' ,
13
+ stream : process . stdout ,
14
+ profile : false ,
15
+ clear : false ,
16
+ showCursor : false ,
17
+ } ;
11
18
12
19
export default class WebpackBarPlugin extends webpack . ProgressPlugin {
13
20
constructor ( options ) {
@@ -22,7 +29,9 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
22
29
this . handler = _ . throttle ( this . handler , 25 , { leading : true , trailing : true } ) ;
23
30
}
24
31
25
- this . logUpdate = this . options . logUpdate || logUpdate ;
32
+ this . logUpdate = this . options . logUpdate || logUpdate . create ( this . options . stream , {
33
+ showCursor : this . options . showCursor ,
34
+ } ) ;
26
35
27
36
if ( ! sharedState [ this . options . name ] ) {
28
37
sharedState [ this . options . name ] = {
@@ -45,7 +54,9 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
45
54
}
46
55
47
56
done ( ) {
48
- logUpdate . clear ( ) ;
57
+ if ( this . options . clear ) {
58
+ logUpdate . clear ( ) ;
59
+ }
49
60
50
61
if ( this . options . profile ) {
51
62
const stats = sharedState [ this . options . name ] . profile . getStats ( ) ;
@@ -79,7 +90,8 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
79
90
80
91
if ( state . isRunning ) {
81
92
isRunning = true ;
82
- } else {
93
+ } else if ( this . options . clear ) {
94
+ // Hide finished jobs
83
95
return ;
84
96
}
85
97
@@ -88,16 +100,18 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
88
100
const lName = lColor ( _ . startCase ( name ) ) ;
89
101
const lBar = renderBar ( state . progress , state . color ) ;
90
102
const lMsg = _ . startCase ( state . msg ) ;
91
- const lProgress = `(${ state . progress } %)` ;
92
- const lDetail1 = chalk . grey ( state . details [ 0 ] || '' ) ;
93
- const lDetail2 = chalk . grey ( state . details [ 1 ] || '' ) ;
94
- const lRequest = formatRequest ( state . request ) ;
103
+ const lProgress = `(${ state . progress || 0 } %)` ;
104
+ const lDetail1 = chalk . grey ( ( state . details && state . details [ 0 ] ) || '' ) ;
105
+ const lDetail2 = chalk . grey ( ( state . details && state . details [ 1 ] ) || '' ) ;
106
+ const lRequest = state . request ? formatRequest ( state . request ) : '' ;
95
107
96
108
lines . push ( `${ [ lIcon , lName , lBar , lMsg , lProgress , lDetail1 , lDetail2 ] . join ( ' ' ) } \n ${ lRequest } ` ) ;
97
109
} ) ;
98
110
99
111
if ( ! isRunning ) {
100
- this . logUpdate . clear ( ) ;
112
+ if ( this . options . clear ) {
113
+ this . logUpdate . clear ( ) ;
114
+ }
101
115
} else {
102
116
const title = ` ${ chalk . bgBlue . black ( ' BUILDING ' ) } ` ;
103
117
this . logUpdate ( `\n${ title } \n\n${ lines . join ( '\n\n' ) } ` ) ;
0 commit comments