Skip to content

Commit b503c75

Browse files
committed
updates to script
1 parent a7cb985 commit b503c75

File tree

1 file changed

+74
-52
lines changed

1 file changed

+74
-52
lines changed

scripts/jsdoc_to_docusaurus.js

+74-52
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,88 @@ const codeboltChild = outJson.children[0].children.find(child => child.name ===
1111
fs.writeFileSync('../temp/newfile.json', JSON.stringify(codeboltChild, null, 2));
1212

1313

14+
function updateFrontmatter(existingFrontmatter, additionalFrontmatter) {
15+
let frontMatter = yaml.load(existingFrontmatter);
16+
let newfront = { ...frontMatter, ...additionalFrontmatter }
17+
return yaml.dump(newfront);
18+
}
19+
20+
function createFrontMatter(frontMatter) {
21+
let frontMatterString = `---\ntitle: ${frontMatter.name}\ndescription: ${frontMatter.description}\n---\n`
22+
return frontMatterString;
23+
}
24+
25+
function createCategoryFile(categoryPath, categoryName) {
26+
if (!fs.existsSync(categoryPath)) {
27+
fs.writeFileSync(categoryPath, JSON.stringify({
28+
"label": categoryName,
29+
"position": 2.5,
30+
"collapsible": true,
31+
"collapsed": true,
32+
"className": "red",
33+
"link": {
34+
"type": "generated-index",
35+
"title": categoryName,
36+
"description": "Provides Functionality for " + categoryName
37+
}
38+
}, null, 2));
39+
}
40+
}
41+
1442
if (codeboltChild && codeboltChild.children) {
1543
codeboltChild.children.forEach(CbProperties => {
1644
const dir = `../docs/api/${CbProperties.name}`;
17-
if (!fs.existsSync(dir)){
45+
46+
//Check Folder
47+
if (!fs.existsSync(dir)) {
1848
fs.mkdirSync(dir, { recursive: true });
1949
}
50+
51+
//Create Category
2052
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-
}
53+
createCategoryFile(categoryFilePath, CbProperties.name);
54+
55+
3556
if (CbProperties.type && CbProperties.type.declaration && CbProperties.type.declaration.children) {
36-
CbProperties.type.declaration.children.forEach(CbFunctions => {
37-
let content = `${CbProperties.name} - ${CbFunctions.name}\n`;
38-
let description = CbFunctions.comment && CbFunctions.comment.summary && CbFunctions.comment.summary.length > 0 ? CbFunctions.comment.summary[0].text : '';
39-
let returndata = "";
40-
let parameterNames = [];
41-
if (CbFunctions.type && CbFunctions.type.declaration && CbFunctions.type.declaration.signatures) {
42-
CbFunctions.type.declaration.signatures.forEach(signature => {
43-
if (signature.parameters) {
44-
signature.parameters.forEach(param => {
45-
parameterNames.push(`${param.name}: ${param.type.name}`);
46-
console.log(`${param.name}: ${param.type.name}`);
47-
});
48-
}
49-
returndata = `Returns: ${signature.type.name}\n`;
50-
});
51-
}
52-
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);
57+
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 = [];
62+
if (CbFunctions.type && CbFunctions.type.declaration && CbFunctions.type.declaration.signatures) {
63+
CbFunctions.type.declaration.signatures.forEach(signature => {
64+
if (signature.parameters) {
65+
signature.parameters.forEach(param => {
66+
parameterNames.push(`${param.name}: ${param.type.name}`);
67+
console.log(`${param.name}: ${param.type.name}`);
68+
});
7269
}
73-
});
70+
returndata = `Returns: ${signature.type.name}\n`;
71+
});
72+
}
73+
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+
}
95+
});
7496
}
7597
});
7698
} else {

0 commit comments

Comments
 (0)