@@ -22,6 +22,7 @@ program
22
22
. option ( '-j|--json [bool]' , 'Display the output as JSON' , false )
23
23
. option ( '-t|--tree <traversal>' , 'Which part of the output JSON to display (dot-delimited)' )
24
24
. option ( '-F|--listFiles [bool]' , 'Whether to list every matching file under the language results' , false )
25
+ . option ( '-m|--minSize <size>' , 'Minimum file size to show language results for (must have a unit: b, kb, mb, %)' )
25
26
. option ( '-q|--quick [bool]' , 'Skip complex language analysis (alias for -{A|I|H|S}=false)' , false )
26
27
. option ( '-o|--offline [bool]' , 'Use packaged data files instead of fetching latest from GitHub' , false )
27
28
. option ( '-L|--calculateLines [bool]' , 'Calculate lines of code totals' , true )
@@ -61,12 +62,41 @@ if (args.analyze) (async () => {
61
62
const { files, languages, unknown } = data ;
62
63
// Print output
63
64
if ( ! args . json ) {
64
- const sortedEntries = Object . entries ( languages . results ) . sort ( ( a , b ) => a [ 1 ] . bytes < b [ 1 ] . bytes ? + 1 : - 1 ) ;
65
+ // Ignore languages with a bytes/% size less than the declared min size
66
+ if ( args . minSize ) {
67
+ const totalSize = languages . bytes ;
68
+ const minSizeAmt = parseFloat ( args . minSize . replace ( / [ a - z ] + $ / i, '' ) ) ; // '2KB' -> 2
69
+ const minSizeUnit = args . minSize . replace ( / ^ \d + / , '' ) . toLowerCase ( ) ; // '2KB' -> 'kb'
70
+ const conversionFactors : Record < string , ( n : number ) => number > = {
71
+ 'b' : n => n ,
72
+ 'kb' : n => n * 1e3 ,
73
+ 'mb' : n => n * 1e6 ,
74
+ '%' : n => n * totalSize / 100 ,
75
+ } ;
76
+ const minBytesSize = conversionFactors [ minSizeUnit ] ( + minSizeAmt ) ;
77
+ const other = { bytes : 0 , lines : { total : 0 , content : 0 , code : 0 } } ;
78
+ // Apply specified minimums: delete language results that do not reach the threshold
79
+ for ( const [ lang , data ] of Object . entries ( languages . results ) ) {
80
+ if ( data . bytes < minBytesSize ) {
81
+ // Add to 'other' count
82
+ other . bytes += data . bytes ;
83
+ other . lines . total += data . lines . total ;
84
+ other . lines . content += data . lines . content ;
85
+ other . lines . code += data . lines . code ;
86
+ // Remove language result
87
+ delete languages . results [ lang ] ;
88
+ }
89
+ }
90
+ languages . results [ 'Other' ] = { ...other , type : null ! } ;
91
+ }
92
+
93
+ const sortedEntries = Object . entries ( languages . results ) . sort ( ( a , b ) => ( a [ 1 ] . bytes < b [ 1 ] . bytes ? + 1 : - 1 ) ) ;
65
94
const totalBytes = languages . bytes ;
66
95
console . log ( `\n Analysed ${ files . bytes . toLocaleString ( ) } B from ${ files . count } files with linguist-js` ) ;
67
96
console . log ( `\n Language analysis results: \n` ) ;
68
97
let count = 0 ;
69
98
if ( sortedEntries . length === 0 ) console . log ( ` None` ) ;
99
+
70
100
// Collate files per language
71
101
const filesPerLanguage : Record < string , string [ ] > = { } ;
72
102
if ( args . listFiles ) {
0 commit comments