@@ -24,6 +24,11 @@ kleur.enabled = !('AVA_PATH' in process.env);
24
24
// Aliases to colors used.
25
25
// @ts -ignore
26
26
const { red, grey, yellow, green, bold, dim } = kleur ;
27
+ const ICONS = {
28
+ tick : [ '✔' , '√' ] ,
29
+ cross : [ '✖' , '×' ] ,
30
+ tada : [ '🎉' , '🎉' ] ,
31
+ } ;
27
32
28
33
/**
29
34
* Format output as an error message.
@@ -49,6 +54,18 @@ function prettyBytes(size: number): string {
49
54
return bytes ( size , { unit : 'kb' , fixedDecimals : true , unitSeparator : ' ' } ) ;
50
55
}
51
56
57
+ /**
58
+ * Retrieve an icon appropriate for your OS.
59
+ * @param name
60
+ */
61
+ function getIcon ( name : 'tick' | 'cross' | 'tada' ) {
62
+ if ( process . platform === 'win32' ) {
63
+ return ICONS [ name ] [ 1 ] ;
64
+ }
65
+
66
+ return ICONS [ name ] [ 0 ] ;
67
+ }
68
+
52
69
/**
53
70
*
54
71
* @param size
@@ -108,24 +125,26 @@ export function LogReport({ silent }: Context, report: Map<ItemConfig['path'], C
108
125
}
109
126
110
127
const paths = Array . from ( report . keys ( ) ) ;
128
+ const maxDisplayablePath = 30 ;
111
129
const pathMaxLength = Math . max . apply (
112
130
null ,
113
- paths . map ( path => path . length + 2 ) ,
131
+ paths . map ( path => Math . min ( path . length , maxDisplayablePath ) + 2 ) ,
114
132
) ;
115
133
const formatMaxLengths = OrderedCompressionValues . map ( compression => maxLengthForCompression ( report , paths , compression ) ) ;
116
134
const compressionHeaders = OrderedCompressionValues . map ( ( compression , index ) => compressedExtension ( compression , formatMaxLengths [ index ] ) ) ;
117
135
let success : number = 0 ;
118
136
let failure : number = 0 ;
119
137
120
- console . log ( bold ( '\nFilesizes ' ) ) ;
121
- console . log ( '' . padEnd ( pathMaxLength ) + ' ' + compressionHeaders . join ( '' ) ) ;
138
+ console . log ( bold ( '\n Filesizes ' ) ) ;
139
+ console . log ( '' . padEnd ( pathMaxLength + 4 ) + ' ' + compressionHeaders . join ( '' ) ) ;
122
140
for ( const path of paths ) {
123
141
const compressionMap = report . get ( path ) ;
124
142
if ( ! compressionMap ) {
125
143
continue ;
126
144
}
127
145
128
- let message = path . padEnd ( pathMaxLength ) + ' ' ;
146
+ let includesFailure = false ;
147
+ let message = ' ' + path . substring ( path . length - maxDisplayablePath ) . padEnd ( pathMaxLength ) + ' ' ;
129
148
let compressionIndex = 0 ;
130
149
for ( const compression of OrderedCompressionValues ) {
131
150
const padding = compressionHeaders [ compressionIndex ] . length ;
@@ -136,16 +155,23 @@ export function LogReport({ silent }: Context, report: Map<ItemConfig['path'], C
136
155
success ++ ;
137
156
} else if ( successful !== null ) {
138
157
failure ++ ;
158
+ includesFailure = true ;
139
159
}
140
160
message += compressionMessage ;
141
161
compressionIndex ++ ;
142
162
}
163
+ if ( includesFailure ) {
164
+ message = ' ' + red ( getIcon ( 'cross' ) ) + message ;
165
+ } else {
166
+ message = ' ' + dim ( ) . green ( getIcon ( 'tick' ) ) + message ;
167
+ }
143
168
console . log ( message ) ;
144
169
}
145
170
if ( success > 0 || failure > 0 ) {
146
- console . log ( '\n ' + green ( success + ` ${ success === 1 ? 'check' : 'checks' } passed` ) + ( failure === 0 ? ' 🎉' : '' ) ) ;
147
- const failureColor = failure < 1 ? grey : red ;
148
- console . log ( ' ' + failureColor ( failure + ` ${ failure === 1 ? 'check' : 'checks' } failed` ) ) ;
171
+ console . log ( '\n ' + green ( success + ` ${ success === 1 ? 'check' : 'checks' } passed` ) + ( failure === 0 ? ` ${ getIcon ( 'tada' ) } ` : '' ) ) ;
172
+ if ( failure > 0 ) {
173
+ console . log ( ' ' + red ( failure + ` ${ failure === 1 ? 'check' : 'checks' } failed` ) ) ;
174
+ }
149
175
}
150
176
console . log ( ) ;
151
177
}
0 commit comments