@@ -13,6 +13,7 @@ export const runMetricsCommand = new Command()
1313 . option ( '--chart' , 'Generate chart visualization' , false )
1414 . option ( '--chartType <chartType>' , 'Chart type (bar | line | stacked)' , 'bar' )
1515 . option ( '--inputFiles <inputFiles...>' , 'List of input files to use (without .json)' )
16+ . option ( '--plugin <plugin>' , 'Plugin name to resolve input file prefixes' )
1617 . action ( runMetrics ) ;
1718
1819export interface MetricOptions {
@@ -21,6 +22,7 @@ export interface MetricOptions {
2122 chart : boolean ;
2223 chartType : ( 'line' | 'bar' | 'stacked' | 'stacked-area' ) [ ] ;
2324 inputFiles : string [ ] ;
25+ plugin : string ;
2426}
2527
2628export async function runMetrics ( folder : string , options : MetricOptions ) : Promise < void > {
@@ -30,34 +32,34 @@ export async function runMetrics(folder: string, options: MetricOptions): Promis
3032 return ;
3133 }
3234
33- if ( options . inputFiles . length === 0 ) {
34- console . error ( '❌ No valid input files provided.' ) ;
35+ if ( ! options . inputFiles || options . inputFiles . length === 0 ) {
36+ console . error ( '❌ No input files provided.' ) ;
3537 return ;
3638 }
3739
38- const requiredFiles = getRequiredInputFilesForMetric ( options . metric ) ;
40+ const basePrefixes = getRequiredInputFilesForMetric ( options . metric ) ;
41+ const requiredPrefixes = getFilePrefixesForPlugin ( basePrefixes , options . plugin ) ;
42+ const validInputFiles = filterValidInputFiles ( options . inputFiles , requiredPrefixes ) ;
3943
40- for ( const relativePath of options . inputFiles ) {
41- const fileName = relativePath . endsWith ( '.json' ) ? relativePath : `${ relativePath } .json` ;
42- const fileBase = path . basename ( fileName ) ;
43- if ( ! requiredFiles . some ( prefix => fileBase . startsWith ( prefix ) ) ) {
44- console . log ( `ℹ️ Skipping file '${ fileBase } ' — not required for metric '${ options . metric } '.` ) ;
45- continue ;
46- }
44+ if ( validInputFiles . length === 0 ) {
45+ console . warn ( `⚠️ No input files matched the required pattern for metric '${ options . metric } '` ) ;
46+ return ;
47+ }
4748
49+ for ( const relativePath of validInputFiles ) {
50+ const fileName = relativePath . endsWith ( '.json' ) ? relativePath : `${ relativePath } .json` ;
4851 const filePath = path . join ( folder , fileName ) ;
4952 const fileContents = fs . readFileSync ( filePath , 'utf-8' ) ;
5053 const data : CommitDependencyHistory = JSON . parse ( fileContents ) ;
5154 const results = metricProcessor ( data ) ;
52-
5355 const resultsFolder = path . join ( path . dirname ( filePath ) , options . results ) ;
5456 fs . mkdirSync ( resultsFolder , { recursive : true } ) ;
5557 const outputFile = path . join ( resultsFolder , `${ path . parse ( filePath ) . name } -${ options . metric } -metric.json` ) ;
5658 fs . writeFileSync ( outputFile , JSON . stringify ( results , null , 2 ) ) ;
5759
5860 if ( options . chart ) {
5961 const chartConfigs = getChartDataForMetric ( options . metric , results , options ) ;
60- if ( chartConfigs && chartConfigs . length > 0 ) {
62+ if ( chartConfigs ? .length ) {
6163 await generateHtmlChart ( outputFile , chartConfigs ) ;
6264 } else {
6365 console . warn ( `⚠️ No chart generator defined for metric '${ options . metric } '. Skipping chart.` ) ;
@@ -68,6 +70,16 @@ export async function runMetrics(folder: string, options: MetricOptions): Promis
6870 }
6971}
7072
73+ function getFilePrefixesForPlugin ( basePrefixes : string [ ] , plugin ?: string ) : string [ ] {
74+ return basePrefixes . map ( base => ( plugin ? `${ base } -${ plugin } ` : base ) ) ;
75+ }
76+
77+ function filterValidInputFiles ( inputFiles : string [ ] , requiredPrefixes : string [ ] ) : string [ ] {
78+ return inputFiles . filter ( file =>
79+ requiredPrefixes . some ( prefix => file . startsWith ( prefix ) )
80+ ) ;
81+ }
82+
7183function getMetricProcessor ( metricType : string ) : ( ( data : CommitDependencyHistory ) => any ) | undefined {
7284 switch ( metricType ) {
7385 case 'growth-pattern' :
0 commit comments