11import * as constants from '../constants' ;
2- import { cloneAndGenerateBasePaths , 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' ;
6- import { flatten , chunk } from 'lodash' ;
7- import { executeSynchronous , chunker } from '../utils' ;
6+ import { flatten } from 'lodash' ;
7+ import { executeSynchronous , chunker , writeJsonFile } from '../utils' ;
8+ import { Package } from '../models' ;
89
910interface GenerateAllParams {
1011 batchCount ?: number ,
1112 batchIndex ?: number ,
13+ localPath ?: string ,
14+ readmeFiles ?: string [ ] ,
15+ outputPath ?: string ,
1216}
1317
1418function parseParams ( ) : GenerateAllParams {
@@ -27,29 +31,62 @@ executeSynchronous(async () => {
2731 filteredAutogenlist = chunker ( filteredAutogenlist , params . batchCount ) [ params . batchIndex ] ;
2832 }
2933
30- await cloneAndGenerateBasePaths ( constants . specsRepoPath , constants . specsRepoUri , constants . specsRepoCommitHash ) ;
34+ let localPath = params . localPath ;
35+ if ( ! localPath ) {
36+ localPath = constants . specsRepoPath ;
37+ await cloneAndGenerateBasePaths ( localPath , constants . specsRepoUri , constants . specsRepoCommitHash ) ;
38+ } else {
39+ localPath = await resolveAbsolutePath ( localPath ) ;
40+ }
41+
42+ if ( ! ! params . readmeFiles ) {
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+ }
51+ ) ;
52+ }
3153
3254 await clearAutogeneratedSchemaRefs ( filteredAutogenlist ) ;
3355
3456 const schemaConfigs : SchemaConfiguration [ ] = [ ] ;
3557 const errors = [ ] ;
58+ const packages : Package [ ] = [ ] ;
3659 for ( const autogenlistConfig of filteredAutogenlist ) {
60+ let pkg = {
61+ path : [ 'schemas' ]
62+ } as Package ;
3763 try {
38- const readme = await validateAndReturnReadmePath ( autogenlistConfig . basePath ) ;
64+ const readme = await validateAndReturnReadmePath ( localPath , autogenlistConfig . readmeFile || autogenlistConfig . basePath ) ;
65+ pkg . packageName = getPackageString ( readme ) ;
3966
4067 const newConfigs = await generateSchemas ( readme , autogenlistConfig ) ;
4168 schemaConfigs . push ( ...newConfigs ) ;
69+ pkg . result = 'succeeded' ;
4270 } catch ( error ) {
71+ pkg . packageName = autogenlistConfig . basePath ;
72+ pkg . result = 'failed' ;
4373 console . log ( chalk . red ( `Caught exception processing autogenlist entry ${ autogenlistConfig . basePath } .` ) ) ;
4474 console . log ( chalk . red ( error ) ) ;
4575
4676 errors . push ( error ) ;
4777 }
78+ packages . push ( pkg ) ;
4879 }
4980
5081 await saveAutogeneratedSchemaRefs ( flatten ( schemaConfigs ) ) ;
5182
52- if ( errors . length > 0 ) {
53- throw new Error ( `Autogeneration failed with ${ errors . length } errors. See logs for detailed information.` ) ;
83+ if ( ! ! params . outputPath ) {
84+ const outputPath = await resolveAbsolutePath ( params . outputPath ) ;
85+ await writeJsonFile ( outputPath , { packages } ) ;
86+ } else {
87+ if ( errors . length > 0 ) {
88+ throw new Error ( `Autogeneration failed with ${ errors . length } errors. See logs for detailed information.` ) ;
89+ }
5490 }
91+
5592} ) ;
0 commit comments