@@ -15,20 +15,42 @@ const path = require("path");
1515const BUILD_DIR = path . join ( __dirname , ".." , "build" ) ;
1616const STATIC_DIR = path . join ( __dirname , ".." , "static" ) ;
1717
18- // Load version from developer_versions.json (same as docusaurus.config.js)
18+ // Load version config (source of truth for type→version mapping)
19+ let developerVersionConfig ;
20+ try {
21+ developerVersionConfig = require ( "../developer_version_config.json" ) ;
22+ } catch {
23+ // Fallback to legacy array-based detection
24+ developerVersionConfig = null ;
25+ }
1926const developerVersions = require ( "../developer_versions.json" ) ;
2027
21- // Find testnet version dynamically (same logic as docusaurus.config.js)
22- const testnetVersion = developerVersions . find ( ( v ) => v . includes ( "rc" ) || v . includes ( "testnet" ) ) ;
23-
24- // The API docs directories use stable folder names
25- const API_DIRS = [
26- ...( testnetVersion ? [ {
27- name : "Aztec.nr API Reference (Testnet)" ,
28- dir : "aztec-nr-api/testnet" ,
29- description : `Auto-generated API documentation for Aztec.nr (${ testnetVersion } )` ,
30- } ] : [ ] ) ,
31- ] ;
28+ // Determine the default (highest-priority) API docs version to append.
29+ // Only include one set to avoid bloating llms.txt. Priority: mainnet > testnet.
30+ const defaultType = developerVersionConfig ?. mainnet ? "mainnet"
31+ : developerVersionConfig ?. testnet ? "testnet"
32+ : null ;
33+ const defaultVersion = defaultType ? developerVersionConfig [ defaultType ] : ( developerVersions [ 0 ] || null ) ;
34+
35+ const API_DIRS = [ ] ;
36+ if ( defaultType && fs . existsSync ( path . join ( STATIC_DIR , `aztec-nr-api/${ defaultType } ` ) ) ) {
37+ API_DIRS . push ( {
38+ name : "Aztec.nr API Reference" ,
39+ dir : `aztec-nr-api/${ defaultType } ` ,
40+ description : `Auto-generated API documentation for Aztec.nr (${ defaultVersion } )` ,
41+ format : "html" ,
42+ } ) ;
43+ } else if ( ! defaultType ) {
44+ console . warn ( "Warning: No default version found for API docs" ) ;
45+ }
46+ if ( defaultType && fs . existsSync ( path . join ( STATIC_DIR , `typescript-api/${ defaultType } ` ) ) ) {
47+ API_DIRS . push ( {
48+ name : "TypeScript API Reference" ,
49+ dir : `typescript-api/${ defaultType } ` ,
50+ description : `Auto-generated TypeScript API documentation for Aztec packages (${ defaultVersion } )` ,
51+ format : "markdown" ,
52+ } ) ;
53+ }
3254
3355/**
3456 * Extract text content from HTML, stripping tags and normalizing whitespace.
@@ -81,9 +103,9 @@ function htmlToText(html) {
81103}
82104
83105/**
84- * Recursively find all HTML files in a directory.
106+ * Recursively find all files with a given extension in a directory.
85107 */
86- function findHtmlFiles ( dir , files = [ ] ) {
108+ function findFiles ( dir , ext , files = [ ] ) {
87109 if ( ! fs . existsSync ( dir ) ) {
88110 return files ;
89111 }
@@ -93,15 +115,30 @@ function findHtmlFiles(dir, files = []) {
93115 for ( const entry of entries ) {
94116 const fullPath = path . join ( dir , entry . name ) ;
95117 if ( entry . isDirectory ( ) ) {
96- findHtmlFiles ( fullPath , files ) ;
97- } else if ( entry . name . endsWith ( ".html" ) ) {
118+ findFiles ( fullPath , ext , files ) ;
119+ } else if ( entry . name . endsWith ( ext ) ) {
98120 files . push ( fullPath ) ;
99121 }
100122 }
101123
102124 return files ;
103125}
104126
127+ /**
128+ * Recursively find all HTML files in a directory.
129+ */
130+ function findHtmlFiles ( dir ) {
131+ return findFiles ( dir , ".html" ) ;
132+ }
133+
134+ /**
135+ * Recursively find all markdown files in a directory.
136+ * Note: `llm-summary.txt` is naturally excluded since it does not end in `.md`.
137+ */
138+ function findMarkdownFiles ( dir ) {
139+ return findFiles ( dir , ".md" ) ;
140+ }
141+
105142/**
106143 * Get the relative URL path for a file.
107144 */
@@ -158,6 +195,7 @@ function main() {
158195 : "" ;
159196
160197 let totalFiles = 0 ;
198+ let sectionsAdded = 0 ;
161199 let linksSection = "\n\n# API Reference Documentation\n\n" ;
162200 let fullContentSection = "\n\n---\n\n# API Reference Documentation\n\n" ;
163201
@@ -169,43 +207,66 @@ function main() {
169207 continue ;
170208 }
171209
172- const htmlFiles = sortByImportance ( findHtmlFiles ( dirPath ) ) ;
173- console . log ( `Found ${ htmlFiles . length } HTML files in ${ apiDir . dir } ` ) ;
210+ const isMarkdown = apiDir . format === "markdown" ;
211+ const files = isMarkdown
212+ ? findMarkdownFiles ( dirPath ) . sort ( )
213+ : sortByImportance ( findHtmlFiles ( dirPath ) ) ;
214+ const ext = isMarkdown ? ".md" : ".html" ;
215+ console . log ( `Found ${ files . length } ${ isMarkdown ? "markdown" : "HTML" } files in ${ apiDir . dir } ` ) ;
174216
175- if ( htmlFiles . length === 0 ) {
217+ if ( files . length === 0 ) {
176218 continue ;
177219 }
178220
221+ sectionsAdded ++ ;
222+
179223 // Add section header
180224 linksSection += `## ${ apiDir . name } \n\n` ;
181225 linksSection += `${ apiDir . description } \n\n` ;
182226 fullContentSection += `## ${ apiDir . name } \n\n` ;
183227 fullContentSection += `${ apiDir . description } \n\n` ;
184228
185- // Process only index files for links to avoid overwhelming the llms.txt
186- const indexFiles = htmlFiles . filter (
187- ( f ) => f . endsWith ( "index.html" ) || f . includes ( "/fn." ) || f . includes ( "/struct." ) || f . includes ( "/trait." )
188- ) ;
189-
190- // Add links for key files
191- for ( const file of indexFiles . slice ( 0 , 100 ) ) {
192- // Limit to 100 links per section
193- const urlPath = getUrlPath ( file , STATIC_DIR ) ;
194- const fileName = path . basename ( file , ".html" ) ;
195- linksSection += `- [${ fileName } ](${ urlPath } )\n` ;
196- }
229+ if ( isMarkdown ) {
230+ // For markdown API docs, add a link per file and include llm-summary.txt if present
231+ const summaryPath = path . join ( dirPath , "llm-summary.txt" ) ;
232+ if ( fs . existsSync ( summaryPath ) ) {
233+ linksSection += fs . readFileSync ( summaryPath , "utf-8" ) + "\n\n" ;
234+ }
235+ // Cap link list at 100 entries to bound llms.txt size as the API surface grows.
236+ for ( const file of files . slice ( 0 , 100 ) ) {
237+ const urlPath = getUrlPath ( file , STATIC_DIR ) ;
238+ const fileName = path . basename ( file , ext ) ;
239+ linksSection += `- [${ fileName } ](${ urlPath } )\n` ;
240+ }
241+ if ( files . length > 100 ) {
242+ linksSection += `- ... and ${ files . length - 100 } more files\n` ;
243+ }
244+ } else {
245+ // For HTML API docs, process only index files for links
246+ const indexFiles = files . filter (
247+ ( f ) => f . endsWith ( "index.html" ) || f . includes ( "/fn." ) || f . includes ( "/struct." ) || f . includes ( "/trait." )
248+ ) ;
249+
250+ // Add links for key files
251+ for ( const file of indexFiles . slice ( 0 , 100 ) ) {
252+ // Limit to 100 links per section
253+ const urlPath = getUrlPath ( file , STATIC_DIR ) ;
254+ const fileName = path . basename ( file , ext ) ;
255+ linksSection += `- [${ fileName } ](${ urlPath } )\n` ;
256+ }
197257
198- if ( indexFiles . length > 100 ) {
199- linksSection += `- ... and ${ indexFiles . length - 100 } more files\n` ;
258+ if ( indexFiles . length > 100 ) {
259+ linksSection += `- ... and ${ indexFiles . length - 100 } more files\n` ;
260+ }
200261 }
201262
202263 linksSection += "\n" ;
203264
204265 // Add full content for all files
205- for ( const file of htmlFiles ) {
266+ for ( const file of files ) {
206267 try {
207- const html = fs . readFileSync ( file , "utf-8" ) ;
208- const text = htmlToText ( html ) ;
268+ const raw = fs . readFileSync ( file , "utf-8" ) ;
269+ const text = isMarkdown ? raw . trim ( ) : htmlToText ( raw ) ;
209270
210271 if ( text . length > 100 ) {
211272 // Only include if there's meaningful content
@@ -220,6 +281,11 @@ function main() {
220281 }
221282 }
222283
284+ if ( sectionsAdded === 0 ) {
285+ console . log ( "No API docs found on disk — leaving llms.txt and llms-full.txt unchanged" ) ;
286+ return ;
287+ }
288+
223289 // Append to llms.txt
224290 fs . writeFileSync ( llmsTxtPath , llmsTxtContent + linksSection ) ;
225291 console . log ( `Updated llms.txt with API reference links` ) ;
0 commit comments