11import * as constants from '../constants' ;
2- import { cloneAndGenerateBasePaths , resolveLocalPath , validateAndReturnReadmePath } from '../specs' ;
2+ import { cloneAndGenerateBasePaths , getPackageString , resolveAbsolutePath , validateAndReturnReadmePath } from '../specs' ;
33import { SchemaConfiguration , generateSchemas , clearAutogeneratedSchemaRefs , saveAutogeneratedSchemaRefs } from '../generate' ;
44import { getAutogenlist } from '../autogenlist' ;
55import chalk from 'chalk' ;
66import { flatten } from 'lodash' ;
7- import { executeSynchronous , chunker } from '../utils' ;
7+ import { executeSynchronous , chunker , writeJsonFile } from '../utils' ;
8+ import { Package } from '../models' ;
89
910interface GenerateAllParams {
1011 batchCount ?: number ,
1112 batchIndex ?: number ,
1213 localPath ?: string ,
1314 readmeFiles ?: string [ ] ,
15+ outputPath ?: string ,
1416}
1517
1618function parseParams ( ) : GenerateAllParams {
@@ -34,36 +36,55 @@ executeSynchronous(async () => {
3436 localPath = constants . specsRepoPath ;
3537 await cloneAndGenerateBasePaths ( localPath , constants . specsRepoUri , constants . specsRepoCommitHash ) ;
3638 } else {
37- localPath = await resolveLocalPath ( localPath ) ;
39+ localPath = await resolveAbsolutePath ( localPath ) ;
3840 }
3941
4042 if ( ! ! params . readmeFiles ) {
41- filteredAutogenlist = filteredAutogenlist . filter ( c =>
42- ! ! ( params . readmeFiles ?. find ( f => f . startsWith ( 'specification/' + c . basePath ) ) )
43+ filteredAutogenlist = filteredAutogenlist . filter ( c => {
44+ let r = params . readmeFiles ?. find ( f => f . startsWith ( 'specification/' + c . basePath ) ) ;
45+ if ( ! ! r ) {
46+ c . readmeFile = r ;
47+ return true ;
48+ }
49+ return false ;
50+ }
4351 ) ;
4452 }
4553
4654 await clearAutogeneratedSchemaRefs ( filteredAutogenlist ) ;
4755
4856 const schemaConfigs : SchemaConfiguration [ ] = [ ] ;
4957 const errors = [ ] ;
58+ const packages : Package [ ] = [ ] ;
5059 for ( const autogenlistConfig of filteredAutogenlist ) {
60+ let pkg = { } as Package ;
5161 try {
52- const readme = await validateAndReturnReadmePath ( localPath , autogenlistConfig . basePath ) ;
62+ const readme = await validateAndReturnReadmePath ( localPath , autogenlistConfig . readmeFile || autogenlistConfig . basePath ) ;
63+ pkg . packageName = getPackageString ( readme ) ;
5364
5465 const newConfigs = await generateSchemas ( readme , autogenlistConfig ) ;
5566 schemaConfigs . push ( ...newConfigs ) ;
67+ pkg . result = 'succeeded' ;
5668 } catch ( error ) {
69+ pkg . packageName = autogenlistConfig . basePath ;
70+ pkg . result = 'failed' ;
5771 console . log ( chalk . red ( `Caught exception processing autogenlist entry ${ autogenlistConfig . basePath } .` ) ) ;
5872 console . log ( chalk . red ( error ) ) ;
5973
6074 errors . push ( error ) ;
6175 }
76+ packages . push ( pkg ) ;
6277 }
6378
6479 await saveAutogeneratedSchemaRefs ( flatten ( schemaConfigs ) ) ;
6580
66- if ( errors . length > 0 ) {
67- throw new Error ( `Autogeneration failed with ${ errors . length } errors. See logs for detailed information.` ) ;
81+ if ( ! ! params . outputPath ) {
82+ const outputPath = await resolveAbsolutePath ( params . outputPath ) ;
83+ await writeJsonFile ( outputPath , { packages } ) ;
84+ } else {
85+ if ( errors . length > 0 ) {
86+ throw new Error ( `Autogeneration failed with ${ errors . length } errors. See logs for detailed information.` ) ;
87+ }
6888 }
89+
6990} ) ;
0 commit comments