@@ -3,7 +3,7 @@ import fs from 'fs';
33import { promisify } from 'util' ;
44import { cloneGitRepo } from './git' ;
55import { findRecursive , lowerCaseEquals } from './utils' ;
6- import { ApiVersionFile , AutoGenConfig , CodeBlock } from './models' ;
6+ import { ReadmeTag , AutoGenConfig , CodeBlock } from './models' ;
77import * as constants from './constants'
88import * as cm from '@ts-common/commonmark-to-markdown'
99import * as yaml from 'js-yaml'
@@ -90,19 +90,52 @@ export async function prepareReadme(readme: string, autoGenConfig?: AutoGenConfi
9090 }
9191 }
9292
93- const result = { } as ApiVersionFile ;
93+ let readmeTag = { } as ReadmeTag ;
9494 fileSet . forEach ( inputFile => {
9595 const match = constants . pathRegex . exec ( inputFile ) ;
9696 if ( ! ! match ) {
9797 const mNamespace = match [ 1 ] ;
9898 const mApiVersion = match [ 2 ] ;
9999 if ( ! autoGenConfig || lowerCaseEquals ( mNamespace , autoGenConfig . namespace ) ) {
100- if ( ! result [ mApiVersion ] ) {
101- result [ mApiVersion ] = [ ] ;
100+ if ( ! readmeTag [ mApiVersion ] ) {
101+ readmeTag [ mApiVersion ] = [ ] ;
102102 }
103- result [ mApiVersion ] . push ( inputFile ) ;
103+ readmeTag [ mApiVersion ] . push ( inputFile ) ;
104104 }
105105 }
106106 } ) ;
107107
108+ if ( ! ! autoGenConfig ?. readmeTag ) {
109+ readmeTag = { ...readmeTag , ...autoGenConfig . readmeTag } ;
110+ }
111+
112+ const schemaReadmeContent = compositeSchemaReadme ( readmeTag ) ;
113+
114+ const schemaReadme = readme . replace ( / \. m d $ / i, '.azureresourceschema.md' ) ;
115+
116+ fs . writeFileSync ( schemaReadme , schemaReadmeContent ) ;
117+ }
118+
119+ function compositeSchemaReadme ( readmeTag : ReadmeTag ) : string {
120+ let content =
121+ `## AzureResourceSchema
122+
123+ ### AzureResourceSchema multi-api
124+
125+ \`\`\` yaml $(azureresourceschema) && $(multiapi)
126+ ${ yaml . dump ( { 'batch' : Object . keys ( readmeTag ) . map ( apiVersion => ( { 'tag' : `schema-${ apiVersion } ` } ) ) } , { lineWidth : 1000 } ) }
127+ \`\`\`
128+
129+ `
130+ for ( const apiVersion of Object . keys ( readmeTag ) ) {
131+ content +=
132+ `
133+ ### Tag: schema-${ apiVersion } and azureresourceschema
134+
135+ \`\`\` yaml $(tag) == 'schema-${ apiVersion } ' && $(azureresourceschema)
136+ ${ yaml . dump ( { 'input-file' : readmeTag [ apiVersion ] } , { lineWidth : 1000 } ) }
137+ \`\`\`
138+ `
139+ }
140+ return content ;
108141}
0 commit comments