1
1
2
2
const fs = require ( 'fs' ) ;
3
+ const yaml = require ( 'js-yaml' ) ;
3
4
4
5
let rawdata = fs . readFileSync ( '../temp/out.json' ) ;
5
6
let outJson = JSON . parse ( rawdata ) ;
@@ -16,18 +17,21 @@ if (codeboltChild && codeboltChild.children) {
16
17
if ( ! fs . existsSync ( dir ) ) {
17
18
fs . mkdirSync ( dir , { recursive : true } ) ;
18
19
}
19
- fs . writeFileSync ( `${ dir } /_category_.json` , JSON . stringify ( {
20
- "label" : CbProperties . name ,
21
- "position" : 2.5 ,
22
- "collapsible" : true ,
23
- "collapsed" : true ,
24
- "className" : "red" ,
25
- "link" : {
26
- "type" : "generated-index" ,
27
- "title" : CbProperties . name ,
28
- "description" : "Provides Functionality for " + CbProperties . name
29
- }
30
- } , null , 2 ) ) ;
20
+ const categoryFilePath = `${ dir } /_category_.json` ;
21
+ if ( ! fs . existsSync ( categoryFilePath ) ) {
22
+ fs . writeFileSync ( categoryFilePath , JSON . stringify ( {
23
+ "label" : CbProperties . name ,
24
+ "position" : 2.5 ,
25
+ "collapsible" : true ,
26
+ "collapsed" : true ,
27
+ "className" : "red" ,
28
+ "link" : {
29
+ "type" : "generated-index" ,
30
+ "title" : CbProperties . name ,
31
+ "description" : "Provides Functionality for " + CbProperties . name
32
+ }
33
+ } , null , 2 ) ) ;
34
+ }
31
35
if ( CbProperties . type && CbProperties . type . declaration && CbProperties . type . declaration . children ) {
32
36
CbProperties . type . declaration . children . forEach ( CbFunctions => {
33
37
let content = `${ CbProperties . name } - ${ CbFunctions . name } \n` ;
@@ -46,7 +50,26 @@ if (codeboltChild && codeboltChild.children) {
46
50
} ) ;
47
51
}
48
52
49
- fs . writeFileSync ( `${ dir } /${ CbFunctions . name } .md` , content + '\n' + description + '\n' + parameterNames . join ( '\n' ) + "\n" + returndata ) ;
53
+ const filePath = `${ dir } /${ CbFunctions . name } .md` ;
54
+ let fileContent = '' ;
55
+ if ( fs . existsSync ( filePath ) ) {
56
+ fileContent = fs . readFileSync ( filePath , 'utf8' ) ;
57
+ const frontMatterMatch = fileContent . match ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - / ) ;
58
+ if ( frontMatterMatch ) {
59
+ const frontMatterContent = frontMatterMatch [ 1 ] ;
60
+
61
+ let frontMatter = yaml . load ( frontMatterContent ) ;
62
+ frontMatter . description = description ;
63
+ const newYamlContent = yaml . dump ( frontMatter ) ;
64
+ fileContent = fileContent . replace ( frontMatterMatch [ 0 ] , `---\n${ newYamlContent } ---` ) ;
65
+ } else {
66
+ fileContent = `---\ntitle: ${ CbFunctions . name } \ndescription: ${ description } \n---\n${ content } \n${ parameterNames . join ( '\n' ) } \n${ returndata } ` ;
67
+ }
68
+ fs . writeFileSync ( filePath , fileContent ) ;
69
+ } else {
70
+ fileContent = `---\ntitle: ${ CbFunctions . name } \ndescription: ${ description } \n---\n${ content } \n${ parameterNames . join ( '\n' ) } \n${ returndata } ` ;
71
+ fs . writeFileSync ( filePath , fileContent ) ;
72
+ }
50
73
} ) ;
51
74
}
52
75
} ) ;
0 commit comments