1- import { existsSync , readdirSync } from "node:fs" ;
1+ import { existsSync , readFileSync , readdirSync } from "node:fs" ;
22import { cp , rename , rm } from "node:fs/promises" ;
33
44import type { TypeDocOptions } from "typedoc" ;
55import { Application } from "typedoc" ;
66
77const LANGUAGES = [ "zh" ] ;
88const IGNORED_PACKAGES = [ "test-utils" ] ;
9- export const PACKAGES = readdirSync ( "../packages" , { withFileTypes : true } )
10- . filter ( ( dirent ) => dirent . isDirectory ( ) )
11- . map ( ( dirent ) => dirent . name )
12- . filter ( ( name ) => ! IGNORED_PACKAGES . includes ( name ) ) ;
9+ export const PACKAGES = Object . fromEntries (
10+ readdirSync ( "../packages" , { withFileTypes : true } )
11+ . filter ( ( dirent ) => dirent . isDirectory ( ) )
12+ . map ( ( dirent ) => dirent . name )
13+ . filter ( ( name ) => ! IGNORED_PACKAGES . includes ( name ) )
14+ . map ( ( name ) => {
15+ const pkgPath = `../packages/${ name } /package.json` ;
16+ if ( ! existsSync ( pkgPath ) ) {
17+ throw new Error ( `Package.json not found for package: ${ name } ` ) ;
18+ }
19+ const pkgJson = JSON . parse ( readFileSync ( pkgPath , "utf-8" ) ) ;
20+
21+ return [ name , pkgJson . name as string ] as const ;
22+ } )
23+ . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) ) ,
24+ ) ;
1325const tsconfig = "../tsconfig.json" ;
1426
1527if ( import . meta. main ) {
@@ -19,14 +31,14 @@ if (import.meta.main) {
1931 await rm ( "reference/api" , { recursive : true , force : true } ) ;
2032
2133 // Generate API documentation
22- for ( const pkg of PACKAGES ) {
23- console . log ( `π Generating reference for ${ pkg } ...` ) ;
34+ for ( const [ pkg , name ] of Object . entries ( PACKAGES ) ) {
35+ console . log ( `π Generating reference for ${ name } ...` ) ;
2436 await runTypedoc ( tsconfig , pkg ) ;
2537 }
2638 console . log ( "β
Reference generated successfully!" ) ;
2739 console . log ( "π Beautifying reference structure..." ) ;
2840
29- for ( const pkg of PACKAGES ) {
41+ for ( const pkg of Object . keys ( PACKAGES ) ) {
3042 if ( existsSync ( `reference/api/${ pkg } /globals.md` ) ) {
3143 await rm ( `reference/api/${ pkg } /index.md` , { force : true } ) ;
3244 await rename (
0 commit comments