1
1
import path from 'path' ;
2
2
// @ts -expect-error missing from Bun types
3
3
import { globSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ;
4
+ import { write } from 'node:console' ;
4
5
5
6
const DefaultOpenGroups : string [ ] = [ ] ;
6
7
const AlwaysOpenGroups : string [ ] = [ 'configuration.setup' ] ;
@@ -138,7 +139,16 @@ export async function getGuidesStructure(withRewrites = false) {
138
139
const result = deepConvert ( groups ) ;
139
140
// console.log(JSON.stringify(result, null, 2));
140
141
// console.log(JSON.stringify(rewritten, null, 2));
141
-
142
+ const structure = { paths : result , rewritten } ;
143
+
144
+ writeFileSync (
145
+ path . join ( __dirname , '../docs.warp-drive.io/guides/nav.json' ) ,
146
+ JSON . stringify ( structure , null , 2 ) ,
147
+ 'utf-8'
148
+ ) ;
149
+ await import ( path . join ( __dirname , '../docs.warp-drive.io/guides/nav.json' ) , {
150
+ with : { type : 'json' } ,
151
+ } ) ;
142
152
return { paths : result , rewritten } ;
143
153
}
144
154
@@ -158,7 +168,7 @@ function deepConvert(obj: Record<string, any>) {
158
168
} ) ;
159
169
}
160
170
161
- type SidebarItem = { text : string ; items ?: SidebarItem [ ] } ;
171
+ type SidebarItem = { text : string ; items ?: SidebarItem [ ] ; link ?: string ; collapsed ?: boolean } ;
162
172
163
173
const OLD_PACKAGES = [
164
174
'@ember-data/adapter' ,
@@ -256,24 +266,40 @@ outline:
256
266
level: [2, 3]
257
267
---
258
268
` ;
269
+ const ApiDocumentation = `# API Docs\n\n` ;
259
270
260
271
export async function postProcessApiDocs ( ) {
261
272
const dir = path . join ( __dirname , '../tmp/api' ) ;
262
273
const outDir = path . join ( __dirname , '../docs.warp-drive.io/api' ) ;
263
274
mkdirSync ( outDir , { recursive : true } ) ;
264
- console . log ( 'Ensured API Docs Directory Exists:' , outDir ) ;
265
275
266
276
// cleanup and prepare the sidebar items
267
277
const sidebarPath = path . join ( outDir , 'typedoc-sidebar.json' ) ;
268
278
const navStructure = JSON . parse ( readFileSync ( path . join ( dir , 'typedoc-sidebar.json' ) , 'utf-8' ) ) as SidebarItem [ ] ;
269
279
const sidebar = splitApiDocsSidebar ( cleanSidebarItems ( navStructure ) ) ;
270
280
writeFileSync ( sidebarPath , JSON . stringify ( sidebar , null , 2 ) , 'utf-8' ) ;
271
281
272
- console . log ( `Processed API Docs Sidebar: ${ sidebarPath } ` ) ;
282
+ // get the package list
283
+ const NewPackages : string [ ] = [ ] ;
284
+ const OldPackages : string [ ] = [ ] ;
285
+ for ( const item of sidebar . newPackages ) {
286
+ NewPackages . push ( `- [${ item . text } ](${ item . link ! } )` ) ;
287
+ }
288
+ for ( const item of sidebar . oldPackages ) {
289
+ OldPackages . push ( `- [${ item . text } ](${ item . link ! } )` ) ;
290
+ }
291
+
292
+ // generate the API documentation
293
+ const apiDocumentation = `${ ApiDocumentation } \n\n## Main Packages\n\n${ NewPackages . join ( '\n' ) } \n\n## Legacy Packages\n\n${ OldPackages . join ( '\n' ) } \n\n` ;
273
294
274
295
// copy the rest of the files
275
296
const files = globSync ( '**/*.md' , { cwd : dir , nodir : true } ) ;
276
297
for ( const file of files ) {
298
+ if ( file === 'index.md' ) {
299
+ // Generate a custom index.md file
300
+ writeFileSync ( path . join ( outDir , 'index.md' ) , apiDocumentation , 'utf-8' ) ;
301
+ continue ;
302
+ }
277
303
const content = readFileSync ( path . join ( dir , file ) , 'utf-8' ) ;
278
304
const outFile = path . join ( outDir , file ) ;
279
305
mkdirSync ( path . dirname ( outFile ) , { recursive : true } ) ;
0 commit comments