@@ -67,7 +67,7 @@ const pathsToProcess = [
6767 '**/src/*/*.{js,ts,tsx}' , // component src files
6868 '**/src/*/*/*.{js,ts,tsx}' , // child component src files
6969 'CODE_OF_CONDUCT.md' ,
70- 'LICENSE.md'
70+ 'LICENSE.md' ,
7171]
7272
7373const pathsToIgnore = [
@@ -117,7 +117,7 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
117117 buildDocs ( )
118118}
119119
120- function buildDocs ( ) {
120+ async function buildDocs ( ) {
121121 // eslint-disable-next-line no-console
122122 console . log ( 'Start building application data' )
123123
@@ -127,17 +127,20 @@ function buildDocs() {
127127 // globby needs the posix format
128128 const files = pathsToProcess . map ( ( file ) => path . posix . join ( packagesDir , file ) )
129129 const ignore = pathsToIgnore . map ( ( file ) => path . posix . join ( packagesDir , file ) )
130+
130131 globby ( files , { ignore } )
131- . then ( ( matches ) => {
132+ . then ( async ( matches ) => {
133+
132134 fs . mkdirSync ( buildDir + 'docs/' , { recursive : true } )
133135 // eslint-disable-next-line no-console
134136 console . log (
135137 'Parsing markdown and source files... (' + matches . length + ' files)'
136138 )
137- const docs = matches . map ( ( relativePath ) => {
139+ const docs = await Promise . all ( matches . map ( async ( relativePath ) => {
138140 // loop trough every source and Readme file
139- return processSingleFile ( path . resolve ( relativePath ) )
140- } )
141+ return await processSingleFile ( path . resolve ( relativePath ) )
142+ } ) )
143+
141144 const themes = parseThemes ( )
142145 const clientProps = getClientProps ( docs , library )
143146 const props : MainDocsData = {
@@ -146,6 +149,7 @@ function buildDocs() {
146149 library
147150 }
148151 const markdownsAndSources = JSON . stringify ( props )
152+
149153 fs . writeFileSync (
150154 buildDir + 'markdown-and-sources-data.json' ,
151155 markdownsAndSources
@@ -182,12 +186,13 @@ function buildDocs() {
182186// This function is also called by Webpack if a file changes
183187// TODO this parses some files twice, its needed for the Webpack watcher but not
184188// for the full build.
185- function processSingleFile ( fullPath : string ) {
189+ async function processSingleFile ( fullPath : string ) {
190+
186191 let docObject
187192 const dirName = path . dirname ( fullPath )
188193 const fileName = path . parse ( fullPath ) . name
189194 if ( fileName === 'index' ) {
190- docObject = processFile ( fullPath , projectRoot , library )
195+ docObject = await processFile ( fullPath , projectRoot , library )
191196 // Some Components (e.g. Alert) store their descriptions in README.md files.
192197 // Add this to the final JSON if it's edited
193198 const readmeDesc = tryParseReadme ( dirName )
@@ -203,20 +208,23 @@ function processSingleFile(fullPath: string) {
203208 componentIndexFile = path . join ( dirName , 'index.ts' )
204209 }
205210 if ( componentIndexFile ) {
206- docObject = processFile ( componentIndexFile , projectRoot , library )
211+ docObject = await processFile ( componentIndexFile , projectRoot , library )
207212 const readmeDesc = tryParseReadme ( dirName )
208213 docObject . description = readmeDesc ? readmeDesc : docObject . description
209214 } else {
210215 // just a README.md, has no index file
211- docObject = processFile ( fullPath , projectRoot , library )
216+ docObject = await processFile ( fullPath , projectRoot , library )
212217 }
213218 } else {
214219 // documentation .md files, utils ts and tsx files
215- docObject = processFile ( fullPath , projectRoot , library )
220+ docObject = await processFile ( fullPath , projectRoot , library )
216221 }
222+
217223 const docJSON = JSON . stringify ( docObject ! )
218224 fs . writeFileSync ( buildDir + 'docs/' + docObject ! . id + '.json' , docJSON )
225+
219226 return docObject !
227+
220228}
221229
222230function tryParseReadme ( dirName : string ) {
0 commit comments