@@ -216,7 +216,14 @@ export async function printRecentCommits(operation: Operation): Promise<void> {
216
216
return
217
217
}
218
218
219
- const parsed = lines . map ( ( line ) => {
219
+ interface ParsedCommit {
220
+ hash : string
221
+ tag : string
222
+ message : string
223
+ color : ( c : string ) => string
224
+ }
225
+
226
+ const parsed = lines . map ( ( line ) : ParsedCommit => {
220
227
const [ hash , ...parts ] = line . split ( ' ' )
221
228
const message = parts . join ( ' ' )
222
229
const match = message . match ( / ^ ( \w + ) ( \( [ ^ ) ] + \) ) ? ( ! ) ? : ( .* ) $ / )
@@ -225,24 +232,41 @@ export async function printRecentCommits(operation: Operation): Promise<void> {
225
232
if ( match [ 3 ] === '!' ) {
226
233
color = c . red
227
234
}
228
- return [
229
- c . dim ( hash ) ,
230
- ' ' ,
231
- c . bold ( color ( [ match [ 1 ] , match [ 2 ] , match [ 3 ] ] . filter ( Boolean ) . join ( '' ) . padStart ( 7 , ' ' ) ) ) ,
232
- c . dim ( ':' ) ,
233
- ' ' ,
234
- color === c . gray ? color ( match [ 4 ] . trim ( ) ) : match [ 4 ] . trim ( ) ,
235
- ] . join ( '' )
235
+ const tag = [ match [ 1 ] , match [ 2 ] , match [ 3 ] ] . filter ( Boolean ) . join ( '' )
236
+ return {
237
+ hash,
238
+ tag,
239
+ message : match [ 4 ] . trim ( ) ,
240
+ color,
241
+ }
236
242
}
237
- return `${ c . gray ( hash ) } ${ message } `
243
+ return {
244
+ hash,
245
+ tag : '' ,
246
+ message,
247
+ color : c => c ,
248
+ }
249
+ } )
250
+ const tagLength = parsed . map ( ( { tag } ) => tag . length ) . reduce ( ( a , b ) => Math . max ( a , b ) , 0 )
251
+ const prettified = parsed . map ( ( { hash, tag, message, color } ) => {
252
+ const paddedTag = tag . padStart ( tagLength + 2 , ' ' )
253
+ return [
254
+ c . dim ( hash ) ,
255
+ ' ' ,
256
+ color === c . gray ? color ( paddedTag ) : c . bold ( color ( paddedTag ) ) ,
257
+ c . dim ( ':' ) ,
258
+ ' ' ,
259
+ color === c . gray ? color ( message ) : message ,
260
+ ] . join ( '' )
238
261
} )
262
+
239
263
console . log ( )
240
264
console . log (
241
265
c . bold (
242
266
`${ c . green ( lines . length ) } Commits since ${ c . gray ( sha . slice ( 0 , 7 ) ) } :` ,
243
267
) ,
244
268
)
245
269
console . log ( )
246
- console . log ( parsed . join ( '\n' ) )
270
+ console . log ( prettified . reverse ( ) . join ( '\n' ) )
247
271
console . log ( )
248
272
}
0 commit comments