1
1
import { format } from 'util' ;
2
- import * as colors from 'colors/safe ' ;
2
+ import * as chalk from 'chalk ' ;
3
3
import { Difference , isPropertyDifference , ResourceDifference , ResourceImpact } from './diff-template' ;
4
4
import { DifferenceCollection , TemplateDiff } from './diff/types' ;
5
5
import { deepEqual } from './diff/util' ;
@@ -75,10 +75,10 @@ function formatSecurityChangesWithBanner(formatter: Formatter, templateDiff: Tem
75
75
formatter . printSectionFooter ( ) ;
76
76
}
77
77
78
- const ADDITION = colors . green ( '[+]' ) ;
79
- const CONTEXT = colors . grey ( '[ ]' ) ;
80
- const UPDATE = colors . yellow ( '[~]' ) ;
81
- const REMOVAL = colors . red ( '[-]' ) ;
78
+ const ADDITION = chalk . green ( '[+]' ) ;
79
+ const CONTEXT = chalk . grey ( '[ ]' ) ;
80
+ const UPDATE = chalk . yellow ( '[~]' ) ;
81
+ const REMOVAL = chalk . red ( '[-]' ) ;
82
82
83
83
class Formatter {
84
84
constructor (
@@ -93,11 +93,11 @@ class Formatter {
93
93
}
94
94
95
95
public print ( fmt : string , ...args : any [ ] ) {
96
- this . stream . write ( colors . white ( format ( fmt , ...args ) ) + '\n' ) ;
96
+ this . stream . write ( chalk . white ( format ( fmt , ...args ) ) + '\n' ) ;
97
97
}
98
98
99
99
public warning ( fmt : string , ...args : any [ ] ) {
100
- this . stream . write ( colors . yellow ( format ( fmt , ...args ) ) + '\n' ) ;
100
+ this . stream . write ( chalk . yellow ( format ( fmt , ...args ) ) + '\n' ) ;
101
101
}
102
102
103
103
public formatSection < V , T extends Difference < V > > (
@@ -116,7 +116,7 @@ class Formatter {
116
116
}
117
117
118
118
public printSectionHeader ( title : string ) {
119
- this . print ( colors . underline ( colors . bold ( title ) ) ) ;
119
+ this . print ( chalk . underline ( chalk . bold ( title ) ) ) ;
120
120
}
121
121
122
122
public printSectionFooter ( ) {
@@ -134,8 +134,8 @@ class Formatter {
134
134
135
135
let value ;
136
136
137
- const oldValue = this . formatValue ( diff . oldValue , colors . red ) ;
138
- const newValue = this . formatValue ( diff . newValue , colors . green ) ;
137
+ const oldValue = this . formatValue ( diff . oldValue , chalk . red ) ;
138
+ const newValue = this . formatValue ( diff . newValue , chalk . green ) ;
139
139
if ( diff . isAddition ) {
140
140
value = newValue ;
141
141
} else if ( diff . isUpdate ) {
@@ -144,7 +144,7 @@ class Formatter {
144
144
value = oldValue ;
145
145
}
146
146
147
- this . print ( `${ this . formatPrefix ( diff ) } ${ colors . cyan ( type ) } ${ this . formatLogicalId ( logicalId ) } : ${ value } ` ) ;
147
+ this . print ( `${ this . formatPrefix ( diff ) } ${ chalk . cyan ( type ) } ${ this . formatLogicalId ( logicalId ) } : ${ value } ` ) ;
148
148
}
149
149
150
150
/**
@@ -159,7 +159,7 @@ class Formatter {
159
159
const resourceType = diff . isRemoval ? diff . oldResourceType : diff . newResourceType ;
160
160
161
161
// eslint-disable-next-line max-len
162
- this . print ( `${ this . formatPrefix ( diff ) } ${ this . formatValue ( resourceType , colors . cyan ) } ${ this . formatLogicalId ( logicalId ) } ${ this . formatImpact ( diff . changeImpact ) } ` ) ;
162
+ this . print ( `${ this . formatPrefix ( diff ) } ${ this . formatValue ( resourceType , chalk . cyan ) } ${ this . formatLogicalId ( logicalId ) } ${ this . formatImpact ( diff . changeImpact ) } ` ) ;
163
163
164
164
if ( diff . isUpdate ) {
165
165
const differenceCount = diff . differenceCount ;
@@ -175,7 +175,7 @@ class Formatter {
175
175
if ( diff . isAddition ) { return ADDITION ; }
176
176
if ( diff . isUpdate ) { return UPDATE ; }
177
177
if ( diff . isRemoval ) { return REMOVAL ; }
178
- return colors . white ( '[?]' ) ;
178
+ return chalk . white ( '[?]' ) ;
179
179
}
180
180
181
181
/**
@@ -197,13 +197,13 @@ class Formatter {
197
197
public formatImpact ( impact : ResourceImpact ) {
198
198
switch ( impact ) {
199
199
case ResourceImpact . MAY_REPLACE :
200
- return colors . italic ( colors . yellow ( 'may be replaced' ) ) ;
200
+ return chalk . italic ( chalk . yellow ( 'may be replaced' ) ) ;
201
201
case ResourceImpact . WILL_REPLACE :
202
- return colors . italic ( colors . bold ( colors . red ( 'replace' ) ) ) ;
202
+ return chalk . italic ( chalk . bold ( chalk . red ( 'replace' ) ) ) ;
203
203
case ResourceImpact . WILL_DESTROY :
204
- return colors . italic ( colors . bold ( colors . red ( 'destroy' ) ) ) ;
204
+ return chalk . italic ( chalk . bold ( chalk . red ( 'destroy' ) ) ) ;
205
205
case ResourceImpact . WILL_ORPHAN :
206
- return colors . italic ( colors . yellow ( 'orphan' ) ) ;
206
+ return chalk . italic ( chalk . yellow ( 'orphan' ) ) ;
207
207
case ResourceImpact . WILL_UPDATE :
208
208
case ResourceImpact . WILL_CREATE :
209
209
case ResourceImpact . NO_CHANGE :
@@ -249,13 +249,13 @@ class Formatter {
249
249
this . print ( '%s %s %s' , linePrefix , i === 0 ? '└─' : ' ' , diff [ i ] ) ;
250
250
}
251
251
} else {
252
- this . print ( '%s ├─ %s %s' , linePrefix , REMOVAL , this . formatValue ( oldObject , colors . red ) ) ;
253
- this . print ( '%s └─ %s %s' , linePrefix , ADDITION , this . formatValue ( newObject , colors . green ) ) ;
252
+ this . print ( '%s ├─ %s %s' , linePrefix , REMOVAL , this . formatValue ( oldObject , chalk . red ) ) ;
253
+ this . print ( '%s └─ %s %s' , linePrefix , ADDITION , this . formatValue ( newObject , chalk . green ) ) ;
254
254
}
255
255
} else if ( oldObject !== undefined /* && newObject === undefined */ ) {
256
- this . print ( '%s └─ %s' , linePrefix , this . formatValue ( oldObject , colors . red ) ) ;
256
+ this . print ( '%s └─ %s' , linePrefix , this . formatValue ( oldObject , chalk . red ) ) ;
257
257
} else /* if (oldObject === undefined && newObject !== undefined) */ {
258
- this . print ( '%s └─ %s' , linePrefix , this . formatValue ( newObject , colors . green ) ) ;
258
+ this . print ( '%s └─ %s' , linePrefix , this . formatValue ( newObject , chalk . green ) ) ;
259
259
}
260
260
return ;
261
261
}
@@ -268,12 +268,12 @@ class Formatter {
268
268
const newValue = newObject [ key ] ;
269
269
const treePrefix = key === lastKey ? '└' : '├' ;
270
270
if ( oldValue !== undefined && newValue !== undefined ) {
271
- this . print ( '%s %s─ %s %s:' , linePrefix , treePrefix , this . changeTag ( oldValue , newValue ) , colors . blue ( `.${ key } ` ) ) ;
271
+ this . print ( '%s %s─ %s %s:' , linePrefix , treePrefix , this . changeTag ( oldValue , newValue ) , chalk . blue ( `.${ key } ` ) ) ;
272
272
this . formatObjectDiff ( oldValue , newValue , `${ linePrefix } ${ key === lastKey ? ' ' : '│' } ` ) ;
273
273
} else if ( oldValue !== undefined /* && newValue === undefined */ ) {
274
- this . print ( '%s %s─ %s Removed: %s' , linePrefix , treePrefix , REMOVAL , colors . blue ( `.${ key } ` ) ) ;
274
+ this . print ( '%s %s─ %s Removed: %s' , linePrefix , treePrefix , REMOVAL , chalk . blue ( `.${ key } ` ) ) ;
275
275
} else /* if (oldValue === undefined && newValue !== undefined */ {
276
- this . print ( '%s %s─ %s Added: %s' , linePrefix , treePrefix , ADDITION , colors . blue ( `.${ key } ` ) ) ;
276
+ this . print ( '%s %s─ %s Added: %s' , linePrefix , treePrefix , ADDITION , chalk . blue ( `.${ key } ` ) ) ;
277
277
}
278
278
}
279
279
}
@@ -322,7 +322,7 @@ class Formatter {
322
322
const normalized = this . normalizedLogicalIdPath ( logicalId ) ;
323
323
324
324
if ( normalized ) {
325
- return `${ normalized } ${ colors . gray ( logicalId ) } ` ;
325
+ return `${ normalized } ${ chalk . gray ( logicalId ) } ` ;
326
326
}
327
327
328
328
return logicalId ;
@@ -430,7 +430,7 @@ function _diffStrings(oldStr: string, newStr: string, context: number): string[]
430
430
const patch : Patch = structuredPatch ( null , null , oldStr , newStr , null , null , { context } ) ;
431
431
const result = new Array < string > ( ) ;
432
432
for ( const hunk of patch . hunks ) {
433
- result . push ( colors . magenta ( `@@ -${ hunk . oldStart } ,${ hunk . oldLines } +${ hunk . newStart } ,${ hunk . newLines } @@` ) ) ;
433
+ result . push ( chalk . magenta ( `@@ -${ hunk . oldStart } ,${ hunk . oldLines } +${ hunk . newStart } ,${ hunk . newLines } @@` ) ) ;
434
434
const baseIndent = _findIndent ( hunk . lines ) ;
435
435
for ( const line of hunk . lines ) {
436
436
// Don't care about termination newline.
@@ -442,10 +442,10 @@ function _diffStrings(oldStr: string, newStr: string, context: number): string[]
442
442
result . push ( `${ CONTEXT } ${ text } ` ) ;
443
443
break ;
444
444
case '+' :
445
- result . push ( colors . bold ( `${ ADDITION } ${ colors . green ( text ) } ` ) ) ;
445
+ result . push ( chalk . bold ( `${ ADDITION } ${ chalk . green ( text ) } ` ) ) ;
446
446
break ;
447
447
case '-' :
448
- result . push ( colors . bold ( `${ REMOVAL } ${ colors . red ( text ) } ` ) ) ;
448
+ result . push ( chalk . bold ( `${ REMOVAL } ${ chalk . red ( text ) } ` ) ) ;
449
449
break ;
450
450
default :
451
451
throw new Error ( `Unexpected diff marker: ${ marker } (full line: ${ line } )` ) ;
0 commit comments