1- import fs from "fs/promises " ;
1+ import fs from "fs" ;
22import { basename } from "path" ;
33
44const basePath = new URL (
@@ -50,11 +50,9 @@ function extractSummary(markdown: string): string {
5050 return normalizedText . split ( " " ) [ 0 ] || "" ; // Fallback: first word if no sentence found
5151}
5252
53- async function getDirectories ( dirPath : URL ) : Promise < URL [ ] > {
53+ function getDirectories ( dirPath : URL ) : URL [ ] {
5454 try {
55- const entries = await fs . readdir ( dirPath , {
56- withFileTypes : true ,
57- } ) ;
55+ const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
5856 return entries
5957 . filter ( ( entry ) => entry . isDirectory ( ) )
6058 . map ( ( entry ) => new URL ( entry . name + "/" , dirPath ) ) ;
@@ -64,16 +62,14 @@ async function getDirectories(dirPath: URL): Promise<URL[]> {
6462 }
6563}
6664
67- async function getIndexMdContents (
68- folders : URL [ ] ,
69- ) : Promise < { [ key : string ] : string } > {
65+ function getIndexMdContents ( folders : URL [ ] ) : { [ key : string ] : string } {
7066 const results : { [ key : string ] : string } = { } ;
7167
7268 for ( const folder of folders ) {
7369 const indexPath = new URL ( "index.md" , folder ) ;
7470
7571 try {
76- const content = await fs . readFile ( indexPath , "utf-8" ) ;
72+ const content = fs . readFileSync ( indexPath , "utf-8" ) ;
7773
7874 // Improved title extraction
7975 const titleMatch = content . match ( / t i t l e : \s * [ " ' ] ? ( [ ^ " ' \n ] + ) [ " ' ] ? / ) ;
@@ -92,17 +88,18 @@ async function getIndexMdContents(
9288 return results ;
9389}
9490
95- export async function generateDescription ( ) : Promise < Record < string , string > > {
96- const stats = await fs . stat ( basePath ) ;
91+ export function generateDescription ( ) : Record < string , string > {
92+ const stats = fs . statSync ( basePath ) ;
9793 if ( ! stats . isDirectory ( ) ) {
9894 throw new Error (
9995 "MDN submodule does not exist; try running `git submodule update --init`" ,
10096 ) ;
10197 }
98+
10299 try {
103- const folders = await getDirectories ( basePath ) ;
100+ const folders = getDirectories ( basePath ) ;
104101 if ( folders . length > 0 ) {
105- return await getIndexMdContents ( folders ) ;
102+ return getIndexMdContents ( folders ) ;
106103 }
107104 } catch ( error ) {
108105 console . error ( "Error generating API descriptions:" , error ) ;
0 commit comments