Skip to content

Commit c6e301e

Browse files
committed
output number of renames and file changes
1 parent 31e45e8 commit c6e301e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tasks/rename_entity.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,31 @@ task('rename-entity', 'Batch replace text in local filenames and contents')
4343
),
4444
);
4545

46-
let count = 0;
46+
let nameChangedCount = 0;
47+
let contentsChangedCount = 0;
4748

4849
for (const oldName of files) {
4950
const newName = oldName.replaceAll(args.oldText, args.newText);
5051

5152
const oldContents = fileContents[oldName];
5253
const newContents = oldContents.replaceAll(args.oldText, args.newText);
5354

54-
if (oldName !== newName || oldContents !== newContents) {
55+
const nameChanged = newName !== oldName;
56+
const contentsChanged = newContents !== oldContents;
57+
58+
if (nameChanged || contentsChanged) {
5559
if (!args.skipDiff) {
5660
console.log(`diff --git a/${oldName} b/${newName}`);
5761

5862
if (oldName !== newName) {
63+
nameChangedCount++;
5964
console.log(`rename from ${oldName}`);
6065
console.log(`rename to ${newName}`);
6166
}
6267

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 });
6671
console.log('---', oldName);
6772
console.log('+++', newName);
6873
console.log(diff);
@@ -78,15 +83,19 @@ task('rename-entity', 'Batch replace text in local filenames and contents')
7883
);
7984
}
8085

81-
count++;
86+
nameChangedCount++;
8287
}
8388
}
8489

8590
if (args.write) {
86-
console.log(`Updated ${count} files.`);
87-
8891
for (const directory of directories) {
8992
await deleteEmpty(path.resolve(hre.config.paths.root, directory));
9093
}
9194
}
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+
}
92101
});

0 commit comments

Comments
 (0)