@@ -2,16 +2,17 @@ import { writeFileSync } from 'node:fs';
22import { resolve } from 'node:path' ;
33import type { ProjectReflection } from 'typedoc' ;
44import type { Method } from '../../docs/.vitepress/components/api-docs/method' ;
5- import type { APIGroup , APIItem } from '../../docs/api/api-types' ;
5+ import type { APIGroup } from '../../docs/api/api-types' ;
66import { formatMarkdown , formatTypescript } from './format' ;
7+ import { extractSourceBaseUrl } from './typedoc' ;
8+ import type { DocsApiDiffIndex , ModuleSummary , Page } from './utils' ;
79import {
8- extractModuleName ,
9- extractSourceBaseUrl ,
10- selectApiMethods ,
11- selectApiModules ,
12- } from './typedoc' ;
13- import type { DocsApiDiffIndex , PageIndex } from './utils' ;
14- import { pathDocsDiffIndexFile , pathDocsDir , pathOutputDir } from './utils' ;
10+ diffHash ,
11+ methodDiffHash ,
12+ pathDocsDiffIndexFile ,
13+ pathDocsDir ,
14+ pathOutputDir ,
15+ } from './utils' ;
1516
1617const pathDocsApiPages = resolve ( pathDocsDir , '.vitepress' , 'api-pages.ts' ) ;
1718const pathDocsApiSearchIndex = resolve (
@@ -29,6 +30,52 @@ editLink: false
2930
3031` ;
3132
33+ /**
34+ * Writes the api docs for the given modules.
35+ *
36+ * @param moduleName The name of the module to write the docs for.
37+ * @param lowerModuleName The lowercase name of the module.
38+ * @param comment The module comments.
39+ * @param deprecated The deprecation message.
40+ * @param methods The methods of the module.
41+ */
42+ export function writeApiDocsModule (
43+ moduleName : string ,
44+ lowerModuleName : string ,
45+ comment : string ,
46+ deprecated : string | undefined ,
47+ methods : Method [ ]
48+ ) : ModuleSummary {
49+ writeApiDocsModulePage (
50+ moduleName ,
51+ lowerModuleName ,
52+ comment ,
53+ deprecated ,
54+ methods
55+ ) ;
56+ writeApiDocsModuleData ( lowerModuleName , methods ) ;
57+
58+ return {
59+ text : moduleName ,
60+ link : `/api/${ lowerModuleName } .html` ,
61+ methods,
62+ diff : methods . reduce (
63+ ( data , method ) => ( {
64+ ...data ,
65+ [ method . name ] : methodDiffHash ( method ) ,
66+ } ) ,
67+ {
68+ moduleHash : diffHash ( {
69+ name : moduleName ,
70+ field : lowerModuleName ,
71+ deprecated,
72+ comment,
73+ } ) ,
74+ }
75+ ) ,
76+ } ;
77+ }
78+
3279/**
3380 * Writes the api page for the given module to the correct location.
3481 *
@@ -37,7 +84,7 @@ editLink: false
3784 * @param comment The module comments.
3885 * @param methods The methods of the module.
3986 */
40- export function writeApiDocsModulePage (
87+ function writeApiDocsModulePage (
4188 moduleName : string ,
4289 lowerModuleName : string ,
4390 comment : string ,
@@ -94,7 +141,7 @@ export function writeApiDocsModulePage(
94141 * @param lowerModuleName The lowercase name of the module.
95142 * @param methods The methods data to save.
96143 */
97- export function writeApiDocsData (
144+ function writeApiDocsModuleData (
98145 lowerModuleName : string ,
99146 methods : Method [ ]
100147) : void {
@@ -116,10 +163,9 @@ export function writeApiDocsData(
116163 *
117164 * @param pages The pages to write into the index.
118165 */
119- export function writeApiPagesIndex ( pages : PageIndex ) : void {
166+ export function writeApiPagesIndex ( pages : Page [ ] ) : void {
120167 // Write api-pages.ts
121168 console . log ( 'Updating api-pages.ts' ) ;
122- pages . sort ( ( a , b ) => a . text . localeCompare ( b . text ) ) ;
123169 pages . splice ( 0 , 0 , { text : 'Overview' , link : '/api/' } ) ;
124170 let apiPagesContent = `
125171 // This file is automatically generated.
@@ -146,33 +192,20 @@ export function writeApiDiffIndex(diffIndex: DocsApiDiffIndex): void {
146192 *
147193 * @param project The typedoc project.
148194 */
149- export function writeApiSearchIndex ( project : ProjectReflection ) : void {
150- const apiIndex : APIGroup [ ] = [ ] ;
151-
152- const moduleApiSection : APIGroup = {
153- text : 'Module API' ,
154- items : [ ] ,
155- } ;
156-
157- apiIndex . push ( moduleApiSection ) ;
158-
159- const apiModules = selectApiModules ( project ) ;
160-
161- moduleApiSection . items = apiModules
162- . map ( ( module ) => {
163- const moduleName = extractModuleName ( module ) ;
164- const apiSection : APIItem = {
165- text : moduleName ,
166- link : moduleName . toLowerCase ( ) ,
167- headers : selectApiMethods ( module ) . map ( ( child ) => ( {
168- anchor : child . name ,
169- text : child . name ,
195+ export function writeApiSearchIndex ( pages : ModuleSummary [ ] ) : void {
196+ const apiIndex : APIGroup [ ] = [
197+ {
198+ text : 'Module API' ,
199+ items : pages . map ( ( module ) => ( {
200+ text : module . text ,
201+ link : module . link ,
202+ headers : module . methods . map ( ( method ) => ( {
203+ anchor : method . name ,
204+ text : method . name ,
170205 } ) ) ,
171- } ;
172-
173- return apiSection ;
174- } )
175- . sort ( ( a , b ) => a . text . localeCompare ( b . text ) ) ;
206+ } ) ) ,
207+ } ,
208+ ] ;
176209
177210 writeFileSync ( pathDocsApiSearchIndex , JSON . stringify ( apiIndex ) ) ;
178211}
0 commit comments