@@ -18,8 +18,8 @@ function updateFrontmatter(existingFrontmatter, additionalFrontmatter) {
18
18
}
19
19
20
20
function createFrontMatter ( frontMatter ) {
21
- let frontMatterString = `---\ntitle: ${ frontMatter . name } \ndescription: ${ frontMatter . description } \n---\n`
22
- return frontMatterString ;
21
+ let frontMatterString = yaml . dump ( frontMatter ) ;
22
+ return `---\n ${ frontMatterString } ---\n` ;
23
23
}
24
24
25
25
function createCategoryFile ( categoryPath , categoryName ) {
@@ -39,6 +39,30 @@ function createCategoryFile(categoryPath, categoryName) {
39
39
}
40
40
}
41
41
42
+
43
+ function writeToFile ( filePath , frontMatterVars ) {
44
+ let originalfileContent = '' ;
45
+ let newFileContent = '' ;
46
+
47
+ if ( fs . existsSync ( filePath ) ) {
48
+ originalfileContent = fs . readFileSync ( filePath , 'utf8' ) ;
49
+ const frontMatterMatch = originalfileContent . match ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - / ) ;
50
+ if ( frontMatterMatch ) {
51
+ const frontMatterContent = frontMatterMatch [ 1 ] ;
52
+ let newYamlContent = updateFrontmatter ( frontMatterContent , { "cbbaseinfo" : frontMatterVars . cbbaseinfo , "cbparameters" : frontMatterVars . cbparameters } ) ;
53
+ newFileContent = originalfileContent . replace ( frontMatterMatch [ 0 ] , `---\n${ newYamlContent } ---` ) ;
54
+ } else {
55
+ const frontMatter = createFrontMatter ( { name : frontMatterVars . data . name , "cblibrary" : frontMatterVars . cbbaseinfo , "cbparameters" : frontMatterVars . cbparameters } ) ;
56
+ newFileContent = frontMatter + originalfileContent ;
57
+ }
58
+ fs . writeFileSync ( filePath , newFileContent ) ;
59
+ } else {
60
+ const frontMatter = createFrontMatter ( { name : frontMatterVars . data . name , "cblibrary" : frontMatterVars . cbbaseinfo , "cbparameters" : frontMatterVars . cbparameters } ) ;
61
+ newFileContent = frontMatter + "<CBBaseInfo/>" ;
62
+ fs . writeFileSync ( filePath , newFileContent ) ;
63
+ }
64
+ }
65
+
42
66
if ( codeboltChild && codeboltChild . children ) {
43
67
codeboltChild . children . forEach ( CbProperties => {
44
68
const dir = `../docs/api/${ CbProperties . name } ` ;
@@ -52,46 +76,45 @@ if (codeboltChild && codeboltChild.children) {
52
76
const categoryFilePath = `${ dir } /_category_.json` ;
53
77
createCategoryFile ( categoryFilePath , CbProperties . name ) ;
54
78
79
+ let frontMatterVars = {
80
+ "data" : {
81
+ "name" : " " ,
82
+ "category" : " " ,
83
+ } ,
84
+ "cbbaseinfo" : {
85
+ "description" : " " ,
86
+ } ,
87
+ "cbparameters" : {
88
+ "parameters" : [ ] ,
89
+ "returndata" : " " ,
90
+ }
91
+ }
92
+
55
93
56
94
if ( CbProperties . type && CbProperties . type . declaration && CbProperties . type . declaration . children ) {
57
95
CbProperties . type . declaration . children . forEach ( CbFunctions => {
58
- let content = `${ CbProperties . name } - ${ CbFunctions . name } \n` ;
59
- let description = CbFunctions . comment && CbFunctions . comment . summary && CbFunctions . comment . summary . length > 0 ? CbFunctions . comment . summary [ 0 ] . text : '' ;
60
- let returndata = "" ;
61
- let parameterNames = [ ] ;
96
+
97
+ frontMatterVars . data . category = CbProperties . name ;
98
+ frontMatterVars . data . name = CbFunctions . name ;
99
+ frontMatterVars . cbbaseinfo . description = CbFunctions . comment && CbFunctions . comment . summary && CbFunctions . comment . summary . length > 0 ? CbFunctions . comment . summary [ 0 ] . text : ' ' ;
100
+
101
+
62
102
if ( CbFunctions . type && CbFunctions . type . declaration && CbFunctions . type . declaration . signatures ) {
63
103
CbFunctions . type . declaration . signatures . forEach ( signature => {
64
104
if ( signature . parameters ) {
65
105
signature . parameters . forEach ( param => {
66
- parameterNames . push ( `${ param . name } : ${ param . type . name } ` ) ;
106
+ frontMatterVars . cbparameters . parameters . push ( `${ param . name } : ${ param . type . name } ` ) ;
67
107
console . log ( `${ param . name } : ${ param . type . name } ` ) ;
68
108
} ) ;
69
109
}
70
- returndata = `Returns: ${ signature . type . name } \n` ;
110
+ frontMatterVars . cbparameters . returndata = signature . type . name ;
71
111
} ) ;
72
112
}
73
113
74
- const filePath = `${ dir } /${ CbFunctions . name } .md` ;
75
- let originalfileContent = '' ;
76
- let newFileContent = '' ;
77
-
78
- if ( fs . existsSync ( filePath ) ) {
79
- originalfileContent = fs . readFileSync ( filePath , 'utf8' ) ;
80
- const frontMatterMatch = originalfileContent . match ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - / ) ;
81
- if ( frontMatterMatch ) {
82
- const frontMatterContent = frontMatterMatch [ 1 ] ;
83
- let newYamlContent = updateFrontmatter ( frontMatterContent , { "cblibrary" : { "description" : description } } )
84
- newFileContent = originalfileContent . replace ( frontMatterMatch [ 0 ] , `---\n${ newYamlContent } ---` ) ;
85
- } else {
86
- const frontMatter = createFrontMatter ( { name : CbFunctions . name , description : description } ) ;
87
- newFileContent = frontMatter + originalfileContent ;
88
- }
89
- fs . writeFileSync ( filePath , newFileContent ) ;
90
- } else {
91
- const frontMatter = createFrontMatter ( { name : CbFunctions . name , description : description } ) ;
92
- newFileContent = frontMatter + `${ content } \n${ parameterNames . join ( '\n' ) } \n${ returndata } <CBBaseInfo/>` ;
93
- fs . writeFileSync ( filePath , newFileContent ) ;
94
- }
114
+
115
+ const filePath = `${ dir } /${ frontMatterVars . data . name } .md` ;
116
+ writeToFile ( filePath , frontMatterVars )
117
+
95
118
} ) ;
96
119
}
97
120
} ) ;
0 commit comments