@@ -5,27 +5,28 @@ import { getHeaders } from '@mui/markdown';
5
5
import findPagesMarkdown from '@mui-internal/api-docs-builder/utils/findPagesMarkdown' ;
6
6
import { writePrettifiedFile } from '@mui-internal/api-docs-builder/buildApiUtils' ;
7
7
8
- export function generateBaseUIApiPages ( ) {
9
- findPagesMarkdown ( ) . forEach ( ( markdown ) => {
10
- const markdownContent = fs . readFileSync ( markdown . filename , 'utf8' ) ;
11
- const markdownHeaders = getHeaders ( markdownContent ) as any ;
12
- const pathnameTokens = markdown . pathname . split ( '/' ) ;
13
- const productName = pathnameTokens [ 1 ] ;
14
- const componentName = pathnameTokens [ 3 ] ;
15
-
16
- // TODO: fix `productName` should be called `productId` and include the full name,
17
- // e.g. base-ui below.
18
- if (
19
- productName === 'base' &&
20
- ( markdown . filename . indexOf ( '\\components\\' ) >= 0 ||
21
- markdown . filename . indexOf ( '/components/' ) >= 0 )
22
- ) {
23
- const { components, hooks } = markdownHeaders ;
24
-
25
- const tokens = markdown . pathname . split ( '/' ) ;
26
- const name = tokens [ tokens . length - 1 ] ;
27
- const importStatement = `docs/data${ markdown . pathname } /${ name } .md` ;
28
- const demosSource = `
8
+ export async function generateBaseUIApiPages ( ) {
9
+ await Promise . all (
10
+ findPagesMarkdown ( ) . map ( async ( markdown ) => {
11
+ const markdownContent = fs . readFileSync ( markdown . filename , 'utf8' ) ;
12
+ const markdownHeaders = getHeaders ( markdownContent ) as any ;
13
+ const pathnameTokens = markdown . pathname . split ( '/' ) ;
14
+ const productName = pathnameTokens [ 1 ] ;
15
+ const componentName = pathnameTokens [ 3 ] ;
16
+
17
+ // TODO: fix `productName` should be called `productId` and include the full name,
18
+ // e.g. base-ui below.
19
+ if (
20
+ productName === 'base' &&
21
+ ( markdown . filename . indexOf ( '\\components\\' ) >= 0 ||
22
+ markdown . filename . indexOf ( '/components/' ) >= 0 )
23
+ ) {
24
+ const { components, hooks } = markdownHeaders ;
25
+
26
+ const tokens = markdown . pathname . split ( '/' ) ;
27
+ const name = tokens [ tokens . length - 1 ] ;
28
+ const importStatement = `docs/data${ markdown . pathname } /${ name } .md` ;
29
+ const demosSource = `
29
30
import * as React from 'react';
30
31
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
31
32
import AppFrame from 'docs/src/modules/components/AppFrame';
@@ -41,77 +42,77 @@ Page.getLayout = (page) => {
41
42
};
42
43
` ;
43
44
44
- const componentPageDirectory = `docs/pages/${ productName } -ui/react-${ componentName } /` ;
45
- if ( ! fs . existsSync ( componentPageDirectory ) ) {
46
- fs . mkdirSync ( componentPageDirectory , { recursive : true } ) ;
47
- }
48
- writePrettifiedFile (
49
- path . join ( process . cwd ( ) , `${ componentPageDirectory } /index.js` ) ,
50
- demosSource ,
51
- ) ;
52
-
53
- if ( ( ! components || components . length === 0 ) && ( ! hooks || hooks . length === 0 ) ) {
54
- // Early return if it's a markdown file without components/hooks.
55
- return ;
56
- }
57
-
58
- let apiTabImportStatements = '' ;
59
- let staticProps = 'export const getStaticProps = () => {' ;
60
- let componentsApiDescriptions = '' ;
61
- let componentsPageContents = '' ;
62
- let hooksApiDescriptions = '' ;
63
- let hooksPageContents = '' ;
64
-
65
- if ( components && components . length > 0 ) {
66
- components . forEach ( ( component : string ) => {
67
- const componentNameKebabCase = kebabCase ( component ) ;
68
- apiTabImportStatements += `import ${ component } ApiJsonPageContent from '../../api/${ componentNameKebabCase } .json';` ;
69
- staticProps += `
45
+ const componentPageDirectory = `docs/pages/${ productName } -ui/react-${ componentName } /` ;
46
+ if ( ! fs . existsSync ( componentPageDirectory ) ) {
47
+ fs . mkdirSync ( componentPageDirectory , { recursive : true } ) ;
48
+ }
49
+ await writePrettifiedFile (
50
+ path . join ( process . cwd ( ) , `${ componentPageDirectory } /index.js` ) ,
51
+ demosSource ,
52
+ ) ;
53
+
54
+ if ( ( ! components || components . length === 0 ) && ( ! hooks || hooks . length === 0 ) ) {
55
+ // Early return if it's a markdown file without components/hooks.
56
+ return ;
57
+ }
58
+
59
+ let apiTabImportStatements = '' ;
60
+ let staticProps = 'export const getStaticProps = () => {' ;
61
+ let componentsApiDescriptions = '' ;
62
+ let componentsPageContents = '' ;
63
+ let hooksApiDescriptions = '' ;
64
+ let hooksPageContents = '' ;
65
+
66
+ if ( components && components . length > 0 ) {
67
+ components . forEach ( ( component : string ) => {
68
+ const componentNameKebabCase = kebabCase ( component ) ;
69
+ apiTabImportStatements += `import ${ component } ApiJsonPageContent from '../../api/${ componentNameKebabCase } .json';` ;
70
+ staticProps += `
70
71
const ${ component } ApiReq = require.context(
71
72
'docs/translations/api-docs-base/${ componentNameKebabCase } ',
72
73
false,
73
74
/${ componentNameKebabCase } .*.json$/,
74
75
);
75
76
const ${ component } ApiDescriptions = mapApiPageTranslations(${ component } ApiReq);
76
77
` ;
77
- componentsApiDescriptions += `${ component } : ${ component } ApiDescriptions ,` ;
78
- componentsPageContents += `${ component } : ${ component } ApiJsonPageContent ,` ;
79
- } ) ;
80
- }
81
-
82
- if ( hooks && hooks . length > 0 ) {
83
- hooks . forEach ( ( hook : string ) => {
84
- const hookNameKebabCase = kebabCase ( hook ) ;
85
- apiTabImportStatements += `import ${ hook } ApiJsonPageContent from '../../api/${ hookNameKebabCase } .json';` ;
86
- staticProps += `
78
+ componentsApiDescriptions += `${ component } : ${ component } ApiDescriptions ,` ;
79
+ componentsPageContents += `${ component } : ${ component } ApiJsonPageContent ,` ;
80
+ } ) ;
81
+ }
82
+
83
+ if ( hooks && hooks . length > 0 ) {
84
+ hooks . forEach ( ( hook : string ) => {
85
+ const hookNameKebabCase = kebabCase ( hook ) ;
86
+ apiTabImportStatements += `import ${ hook } ApiJsonPageContent from '../../api/${ hookNameKebabCase } .json';` ;
87
+ staticProps += `
87
88
const ${ hook } ApiReq = require.context(
88
89
'docs/translations/api-docs/${ hookNameKebabCase } ',
89
90
false,
90
91
/${ hookNameKebabCase } .*.json$/,
91
92
);
92
93
const ${ hook } ApiDescriptions = mapApiPageTranslations(${ hook } ApiReq);
93
94
` ;
94
- hooksApiDescriptions += `${ hook } : ${ hook } ApiDescriptions ,` ;
95
- hooksPageContents += `${ hook } : ${ hook } ApiJsonPageContent ,` ;
96
- } ) ;
97
- }
95
+ hooksApiDescriptions += `${ hook } : ${ hook } ApiDescriptions ,` ;
96
+ hooksPageContents += `${ hook } : ${ hook } ApiJsonPageContent ,` ;
97
+ } ) ;
98
+ }
98
99
99
- staticProps += `
100
+ staticProps += `
100
101
return { props: { componentsApiDescriptions: {` ;
101
- staticProps += componentsApiDescriptions ;
102
+ staticProps += componentsApiDescriptions ;
102
103
103
- staticProps += '}, componentsApiPageContents: { ' ;
104
- staticProps += componentsPageContents ;
104
+ staticProps += '}, componentsApiPageContents: { ' ;
105
+ staticProps += componentsPageContents ;
105
106
106
- staticProps += '}, hooksApiDescriptions: {' ;
107
- staticProps += hooksApiDescriptions ;
107
+ staticProps += '}, hooksApiDescriptions: {' ;
108
+ staticProps += hooksApiDescriptions ;
108
109
109
- staticProps += '}, hooksApiPageContents: {' ;
110
- staticProps += hooksPageContents ;
110
+ staticProps += '}, hooksApiPageContents: {' ;
111
+ staticProps += hooksPageContents ;
111
112
112
- staticProps += ` },},};};` ;
113
+ staticProps += ` },},};};` ;
113
114
114
- const tabsApiSource = `
115
+ const tabsApiSource = `
115
116
import * as React from 'react';
116
117
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
117
118
import AppFrame from 'docs/src/modules/components/AppFrame';
@@ -138,14 +139,15 @@ export const getStaticPaths = () => {
138
139
${ staticProps }
139
140
` ;
140
141
141
- const docsTabsPagesDirectory = `${ componentPageDirectory } /[docsTab]` ;
142
- if ( ! fs . existsSync ( docsTabsPagesDirectory ) ) {
143
- fs . mkdirSync ( docsTabsPagesDirectory , { recursive : true } ) ;
142
+ const docsTabsPagesDirectory = `${ componentPageDirectory } /[docsTab]` ;
143
+ if ( ! fs . existsSync ( docsTabsPagesDirectory ) ) {
144
+ fs . mkdirSync ( docsTabsPagesDirectory , { recursive : true } ) ;
145
+ }
146
+ await writePrettifiedFile (
147
+ path . join ( process . cwd ( ) , `${ docsTabsPagesDirectory } /index.js` ) ,
148
+ tabsApiSource ,
149
+ ) ;
144
150
}
145
- writePrettifiedFile (
146
- path . join ( process . cwd ( ) , `${ docsTabsPagesDirectory } /index.js` ) ,
147
- tabsApiSource ,
148
- ) ;
149
- }
150
- } ) ;
151
+ } ) ,
152
+ ) ;
151
153
}
0 commit comments