Skip to content

Commit 158dc86

Browse files
authored
Merge pull request #30634 from github/repo-sync
Repo sync
2 parents 748032f + 858d723 commit 158dc86

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/workflows/delete-orphan-translation-files.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,45 @@ main(program.args[0], {
4646
})
4747

4848
function main(root: string, options: Options) {
49-
let deleted = 0
50-
let countInSync = 0
51-
let countOrphan = 0
49+
const deleted: number[] = []
50+
const inSync: number[] = []
51+
const orphan: number[] = []
5252
for (const filePath of getContentAndDataFiles(root)) {
5353
const relPath = path.relative(root, filePath)
54+
const size = fs.statSync(filePath).size
5455
if (!fs.existsSync(path.join(ROOT, relPath))) {
55-
countOrphan++
56-
if (deleted < options.max) {
56+
orphan.push(size)
57+
if (deleted.length < options.max) {
5758
if (options.dryRun) {
5859
console.log('DELETE', filePath)
5960
} else {
6061
fs.rmSync(filePath)
6162
console.log('DELETED', filePath)
6263
}
63-
deleted++
64+
deleted.push(size)
6465

65-
if (deleted >= options.max) {
66+
if (deleted.length >= options.max) {
6667
console.log(`Max. number (${options.max}) of files deleted`)
6768
}
6869
}
6970
} else {
70-
countInSync++
71+
inSync.push(size)
7172
}
7273
}
73-
console.log(`In conclusion, deleted ${deleted.toLocaleString()} files.`)
74+
const sumDeleted = deleted.reduce((a, b) => a + b, 0)
7475
console.log(
75-
`There are ${countInSync.toLocaleString()} files in sync and ${countOrphan.toLocaleString()} orphan files in ${root}`,
76+
`In conclusion, deleted ${deleted.length.toLocaleString()} files (${formatFileSize(
77+
sumDeleted,
78+
)}).`,
79+
)
80+
const sumInSync = inSync.reduce((a, b) => a + b, 0)
81+
const sumOrphan = orphan.reduce((a, b) => a + b, 0)
82+
console.log(
83+
`There are ${inSync.length.toLocaleString()} files (${formatFileSize(
84+
sumInSync,
85+
)}) in sync and ${orphan.length.toLocaleString()} orphan files (${formatFileSize(
86+
sumOrphan,
87+
)}) in ${root}`,
7688
)
7789
}
7890

@@ -82,3 +94,13 @@ function getContentAndDataFiles(root: string) {
8294
...walkFiles(path.join(root, 'data'), ['.md', '.yml']),
8395
]
8496
}
97+
98+
function formatFileSize(bytes: number) {
99+
if (bytes < 1024) {
100+
return `${bytes} B`
101+
}
102+
if (bytes < 1024 * 1024) {
103+
return `${(bytes / 1024).toFixed(1)} kB`
104+
}
105+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`
106+
}

0 commit comments

Comments
 (0)