@@ -17,9 +17,28 @@ if (!fs.existsSync(COMPONENTS_DOCS_DIR)) {
17
17
fs . mkdirSync ( COMPONENTS_DOCS_DIR ) ;
18
18
}
19
19
20
+ const compoundComponents = components . filter ( c => c . name . includes ( '.' ) ) ;
21
+ const parentComponents = _ . chain ( compoundComponents )
22
+ . map ( c => c . name . split ( '.' ) [ 0 ] )
23
+ . uniq ( )
24
+ . value ( ) ;
25
+
20
26
components . forEach ( component => {
27
+ const [ componentName , componentParentName ] = getComponentNameParts ( component . name ) ;
28
+ const isParentComponent = parentComponents . includes ( componentName ) ;
29
+
30
+ let content = '' ;
31
+ /* Markdown Front Matter */
32
+ content += `---\n` ;
33
+ if ( isParentComponent ) {
34
+ content += `sidebar_position: 1\n` ;
35
+ }
36
+ content += `sidebar_label: ${ componentName } \n` ;
37
+ content += `title: ${ component . name } \n` ;
38
+ content += `---\n` ;
39
+
21
40
/* General */
22
- let content = `${ component . description } \n` ;
41
+ content + = `${ component . description } \n` ;
23
42
content += `[(code example)](${ component . example } )\n` ;
24
43
25
44
if ( component . extends ) {
@@ -51,9 +70,21 @@ components.forEach(component => {
51
70
content += `<code>${ _ . escape ( prop . type ) } </code>\n\n` ;
52
71
} ) ;
53
72
54
- if ( ! fs . existsSync ( `${ COMPONENTS_DOCS_DIR } /${ component . category } ` ) ) {
55
- fs . mkdirSync ( `${ COMPONENTS_DOCS_DIR } /${ component . category } ` ) ;
73
+ const componentParentDir = ( componentParentName || isParentComponent ) ? `/${ componentParentName || componentName } ` : '' ;
74
+ const dirPath = `${ COMPONENTS_DOCS_DIR } /${ component . category } ${ componentParentDir } ` ;
75
+
76
+ if ( ! fs . existsSync ( dirPath ) ) {
77
+ fs . mkdirSync ( dirPath , { recursive : true } ) ;
56
78
}
57
79
58
- fs . writeFileSync ( `${ COMPONENTS_DOCS_DIR } / ${ component . category } /${ component . name } .md` , content , { encoding : 'utf8' } ) ;
80
+ fs . writeFileSync ( `${ dirPath } /${ component . name } .md` , content , { encoding : 'utf8' } ) ;
59
81
} ) ;
82
+
83
+ function getComponentNameParts ( componentName ) {
84
+ const parts = componentName . split ( '.' ) ;
85
+ if ( parts . length === 1 ) {
86
+ return [ parts [ 0 ] , undefined ] ;
87
+ } else {
88
+ return [ parts [ 1 ] , parts [ 0 ] ] ;
89
+ }
90
+ }
0 commit comments