@@ -10,25 +10,20 @@ import {
1010 getSeverityPerRule ,
1111 merge ,
1212} from './utils.js' ;
13+ import config from './config.js' ;
1314const { Spectral } = spectral ;
1415
15- //TBD
16- const oasFile = '../../../../openapi/v2.json' ;
17- const dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
18- const collectorResultsFile = path . join ( dirname , '../ipa-collector-results-combined.log' ) ;
19-
20- async function runMetricCollectionJob ( ) {
16+ async function runMetricCollectionJob ( oasFilePath = config . defaultOasFilePath ) {
2117 try {
22- console . log ( ' Loading OpenAPI file...' ) ;
23- const oasContent = loadOpenAPIFile ( oasFile ) ;
18+ console . log ( ` Loading OpenAPI file: ${ oasFilePath } ` ) ;
19+ const oasContent = loadOpenAPIFile ( oasFilePath ) ;
2420
2521 console . log ( 'Extracting team ownership data...' ) ;
2622 const ownershipData = extractTeamOwnership ( oasContent ) ;
2723
2824 console . log ( 'Initializing Spectral...' ) ;
2925 const spectral = new Spectral ( ) ;
30- const rulesetPath = path . join ( dirname , '../ipa-spectral.yaml' ) ;
31- const ruleset = await loadRuleset ( rulesetPath , spectral ) ;
26+ const ruleset = await loadRuleset ( config . defaultRulesetFilePath , spectral ) ;
3227
3328 console . log ( 'Getting rule severities...' ) ;
3429 const ruleSeverityMap = getSeverityPerRule ( ruleset ) ;
@@ -37,7 +32,7 @@ async function runMetricCollectionJob() {
3732 const spectralResults = await spectral . run ( oasContent ) ;
3833
3934 console . log ( 'Loading collector results...' ) ;
40- const collectorResults = loadCollectorResults ( collectorResultsFile ) ;
35+ const collectorResults = loadCollectorResults ( config . defaultCollectorResultsFilePath ) ;
4136
4237 console . log ( 'Merging results...' ) ;
4338 const mergedResults = merge ( spectralResults , ownershipData , collectorResults , ruleSeverityMap ) ;
@@ -50,6 +45,9 @@ async function runMetricCollectionJob() {
5045 }
5146}
5247
53- runMetricCollectionJob ( )
54- . then ( ( results ) => fs . writeFileSync ( 'results.log' , JSON . stringify ( results ) ) )
48+ const args = process . argv . slice ( 2 ) ;
49+ const customOasFile = args [ 0 ] ;
50+
51+ runMetricCollectionJob ( customOasFile )
52+ . then ( ( results ) => fs . writeFileSync ( config . defaultMetricCollectionResultsFilePath , JSON . stringify ( results ) ) )
5553 . catch ( ( error ) => console . error ( error . message ) ) ;
0 commit comments