@@ -46,33 +46,45 @@ main(program.args[0], {
46
46
} )
47
47
48
48
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 [ ] = [ ]
52
52
for ( const filePath of getContentAndDataFiles ( root ) ) {
53
53
const relPath = path . relative ( root , filePath )
54
+ const size = fs . statSync ( filePath ) . size
54
55
if ( ! fs . existsSync ( path . join ( ROOT , relPath ) ) ) {
55
- countOrphan ++
56
- if ( deleted < options . max ) {
56
+ orphan . push ( size )
57
+ if ( deleted . length < options . max ) {
57
58
if ( options . dryRun ) {
58
59
console . log ( 'DELETE' , filePath )
59
60
} else {
60
61
fs . rmSync ( filePath )
61
62
console . log ( 'DELETED' , filePath )
62
63
}
63
- deleted ++
64
+ deleted . push ( size )
64
65
65
- if ( deleted >= options . max ) {
66
+ if ( deleted . length >= options . max ) {
66
67
console . log ( `Max. number (${ options . max } ) of files deleted` )
67
68
}
68
69
}
69
70
} else {
70
- countInSync ++
71
+ inSync . push ( size )
71
72
}
72
73
}
73
- console . log ( `In conclusion, deleted ${ deleted . toLocaleString ( ) } files.` )
74
+ const sumDeleted = deleted . reduce ( ( a , b ) => a + b , 0 )
74
75
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 } `,
76
88
)
77
89
}
78
90
@@ -82,3 +94,13 @@ function getContentAndDataFiles(root: string) {
82
94
...walkFiles ( path . join ( root , 'data' ) , [ '.md' , '.yml' ] ) ,
83
95
]
84
96
}
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