@@ -23,11 +23,11 @@ const cli = meow(
2323 $ pnpm run generate-guide --version=core-3 --sdk=react > react-guide.md
2424` ,
2525 {
26- importMeta : import . meta,
2726 flags : {
28- version : { type : 'string' , isRequired : true } ,
29- sdk : { type : 'string' , isRequired : true } ,
27+ sdk : { isRequired : true , type : 'string' } ,
28+ version : { isRequired : true , type : 'string' } ,
3029 } ,
30+ importMeta : import . meta,
3131 } ,
3232) ;
3333
@@ -101,8 +101,8 @@ function getCategoryHeading(category) {
101101 breaking : 'Breaking Changes' ,
102102 deprecation : 'Deprecations' ,
103103 'deprecation-removal' : 'Deprecation Removals' ,
104- warning : 'Warnings' ,
105104 version : 'Version' ,
105+ warning : 'Warnings' ,
106106 } ;
107107 if ( headings [ category ] ) {
108108 return headings [ category ] ;
@@ -111,6 +111,32 @@ function getCategoryHeading(category) {
111111 return category . replace ( / [ - _ ] + / g, ' ' ) . replace ( / \b \w / g, char => char . toUpperCase ( ) ) ;
112112}
113113
114+ function normalizeSdk ( sdk ) {
115+ return sdk . replace ( / ^ @ c l e r k \/ / , '' ) ;
116+ }
117+
118+ function renderAccordionCategory ( lines , category , categoryChanges ) {
119+ const sortedChanges = [ ...categoryChanges ] . sort ( ( a , b ) => a . title . localeCompare ( b . title ) ) ;
120+ const titles = sortedChanges . map ( change => JSON . stringify ( change . title ) ) ;
121+
122+ lines . push ( `## ${ getCategoryHeading ( category ) } ` ) ;
123+ lines . push ( '' ) ;
124+ lines . push ( `<Accordion titles={[${ titles . join ( ', ' ) } ]}>` ) ;
125+ lines . push ( '' ) ;
126+
127+ for ( const change of sortedChanges ) {
128+ lines . push ( ' <AccordionPanel>' ) ;
129+ lines . push ( '' ) ;
130+ lines . push ( change . content ) ;
131+ lines . push ( '' ) ;
132+ lines . push ( ' </AccordionPanel>' ) ;
133+ lines . push ( '' ) ;
134+ }
135+
136+ lines . push ( '</Accordion>' ) ;
137+ lines . push ( '' ) ;
138+ }
139+
114140function generateMarkdown ( sdk , versionConfig , changes ) {
115141 const lines = [ ] ;
116142 const versionName = versionConfig . name || versionConfig . id ;
@@ -134,6 +160,11 @@ function generateMarkdown(sdk, versionConfig, changes) {
134160 }
135161
136162 seenCategories . add ( category ) ;
163+ if ( category === 'breaking' ) {
164+ renderAccordionCategory ( lines , category , categoryChanges ) ;
165+ continue ;
166+ }
167+
137168 lines . push ( `## ${ getCategoryHeading ( category ) } ` ) ;
138169 lines . push ( '' ) ;
139170
@@ -151,6 +182,11 @@ function generateMarkdown(sdk, versionConfig, changes) {
151182 continue ;
152183 }
153184
185+ if ( category === 'breaking' ) {
186+ renderAccordionCategory ( lines , category , categoryChanges ) ;
187+ continue ;
188+ }
189+
154190 lines . push ( `## ${ getCategoryHeading ( category ) } ` ) ;
155191 lines . push ( '' ) ;
156192
@@ -166,17 +202,18 @@ function generateMarkdown(sdk, versionConfig, changes) {
166202}
167203
168204async function main ( ) {
169- const { version, sdk } = cli . flags ;
205+ const { sdk, version } = cli . flags ;
206+ const normalizedSdk = normalizeSdk ( sdk ) ;
170207
171208 const versionConfig = await loadVersionConfig ( version ) ;
172- const changes = loadChanges ( version , sdk ) ;
209+ const changes = loadChanges ( version , normalizedSdk ) ;
173210
174211 if ( changes . length === 0 ) {
175- console . error ( `No changes found for ${ sdk } in ${ version } ` ) ;
212+ console . error ( `No changes found for ${ normalizedSdk } in ${ version } ` ) ;
176213 process . exit ( 1 ) ;
177214 }
178215
179- const markdown = generateMarkdown ( sdk , versionConfig , changes ) ;
216+ const markdown = generateMarkdown ( normalizedSdk , versionConfig , changes ) ;
180217 console . log ( markdown ) ;
181218}
182219
0 commit comments