File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,22 +18,37 @@ const { number, numberNonBlank } = program.opts();
1818
1919// --- Read files and sizes ---
2020let content = "" ;
21- let fileSize ;
21+ let fileSize ,
22+ wordCount ,
23+ lineCount ,
24+ lineCountTotal = 0 ,
25+ wordCountTotal = 0 ,
26+ fileSizeTotal = 0 ;
2227
2328for ( const path of paths ) {
2429 content = await fs . readFile ( path , "utf-8" ) ;
2530 if ( content . endsWith ( "\n" ) ) {
2631 content = content . slice ( 0 , - 1 ) ;
2732 }
2833 fileSize = await fs . stat ( path ) ;
34+ fileSizeTotal += fileSize . size ;
35+ wordCount = getWordCount ( content ) ;
36+ wordCountTotal += wordCount ;
37+ lineCount = getLineCount ( content ) ;
38+ lineCountTotal += lineCount ;
2939 console . log (
30- getLineCount ( content ) ,
31- getWordCount ( content ) ,
32- fileSize . size ,
33- path
40+ `${ String ( lineCount ) . padStart ( 3 ) } ${ String ( wordCount ) . padStart ( 4 ) } ${ String (
41+ fileSize . size
42+ ) . padStart ( 4 ) } ${ path } `
3443 ) ;
3544}
3645
46+ console . log (
47+ `${ String ( lineCountTotal ) . padStart ( 3 ) } ${ String ( wordCountTotal ) . padStart (
48+ 4
49+ ) } ${ String ( fileSizeTotal ) . padStart ( 4 ) } total`
50+ ) ;
51+
3752function getWordCount ( text ) {
3853 let words , lines ;
3954
You can’t perform that action at this time.
0 commit comments