@@ -43,26 +43,31 @@ task('rename-entity', 'Batch replace text in local filenames and contents')
43
43
) ,
44
44
) ;
45
45
46
- let count = 0 ;
46
+ let nameChangedCount = 0 ;
47
+ let contentsChangedCount = 0 ;
47
48
48
49
for ( const oldName of files ) {
49
50
const newName = oldName . replaceAll ( args . oldText , args . newText ) ;
50
51
51
52
const oldContents = fileContents [ oldName ] ;
52
53
const newContents = oldContents . replaceAll ( args . oldText , args . newText ) ;
53
54
54
- if ( oldName !== newName || oldContents !== newContents ) {
55
+ const nameChanged = newName !== oldName ;
56
+ const contentsChanged = newContents !== oldContents ;
57
+
58
+ if ( nameChanged || contentsChanged ) {
55
59
if ( ! args . skipDiff ) {
56
60
console . log ( `diff --git a/${ oldName } b/${ newName } ` ) ;
57
61
58
62
if ( oldName !== newName ) {
63
+ nameChangedCount ++ ;
59
64
console . log ( `rename from ${ oldName } ` ) ;
60
65
console . log ( `rename to ${ newName } ` ) ;
61
66
}
62
67
63
- const diff = gitDiff ( oldContents , newContents , { color : true } ) ;
64
-
65
- if ( diff ) {
68
+ if ( contentsChanged ) {
69
+ contentsChangedCount ++ ;
70
+ const diff = gitDiff ( oldContents , newContents , { color : true } ) ;
66
71
console . log ( '---' , oldName ) ;
67
72
console . log ( '+++' , newName ) ;
68
73
console . log ( diff ) ;
@@ -78,15 +83,19 @@ task('rename-entity', 'Batch replace text in local filenames and contents')
78
83
) ;
79
84
}
80
85
81
- count ++ ;
86
+ nameChangedCount ++ ;
82
87
}
83
88
}
84
89
85
90
if ( args . write ) {
86
- console . log ( `Updated ${ count } files.` ) ;
87
-
88
91
for ( const directory of directories ) {
89
92
await deleteEmpty ( path . resolve ( hre . config . paths . root , directory ) ) ;
90
93
}
91
94
}
95
+
96
+ console . log ( `${ nameChangedCount } files renamed` ) ;
97
+ console . log ( `${ contentsChangedCount } files modified` ) ;
98
+ if ( ! args . write ) {
99
+ console . log ( 'No changes written to disk (use --write flag)' ) ;
100
+ }
92
101
} ) ;
0 commit comments