|
| 1 | + |
| 2 | +const fs = require('fs'); |
| 3 | + |
| 4 | +let rawdata = fs.readFileSync('./out.json'); |
| 5 | +let outJson = JSON.parse(rawdata); |
| 6 | +console.log("Json Parsed"); |
| 7 | + |
| 8 | +const codeboltChild = outJson.children[0].children.find(child => child.name === "Codebolt"); |
| 9 | + |
| 10 | +fs.writeFileSync('./newfile.json', JSON.stringify(codeboltChild, null, 2)); |
| 11 | + |
| 12 | + |
| 13 | +if (codeboltChild && codeboltChild.children) { |
| 14 | + codeboltChild.children.forEach(CbProperties => { |
| 15 | + const dir = `../codeboltLib/docs/api/${CbProperties.name}`; |
| 16 | + if (!fs.existsSync(dir)){ |
| 17 | + fs.mkdirSync(dir, { recursive: true }); |
| 18 | + } |
| 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)); |
| 31 | + if (CbProperties.type && CbProperties.type.declaration && CbProperties.type.declaration.children) { |
| 32 | + CbProperties.type.declaration.children.forEach(CbFunctions => { |
| 33 | + let content = `${CbProperties.name} - ${CbFunctions.name}\n`; |
| 34 | + let description = CbFunctions.comment && CbFunctions.comment.summary && CbFunctions.comment.summary.length > 0 ? CbFunctions.comment.summary[0].text : ''; |
| 35 | + let returndata = ""; |
| 36 | + let parameterNames = []; |
| 37 | + if (CbFunctions.type && CbFunctions.type.declaration && CbFunctions.type.declaration.signatures) { |
| 38 | + CbFunctions.type.declaration.signatures.forEach(signature => { |
| 39 | + if (signature.parameters) { |
| 40 | + signature.parameters.forEach(param => { |
| 41 | + parameterNames.push(`${param.name}: ${param.type.name}`); |
| 42 | + console.log(`${param.name}: ${param.type.name}`); |
| 43 | + }); |
| 44 | + } |
| 45 | + returndata = `Returns: ${signature.type.name}\n`; |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + fs.writeFileSync(`${dir}/${CbFunctions.name}.md`, content + '\n' + description + '\n' + parameterNames.join('\n') + "\n"+ returndata); |
| 50 | + }); |
| 51 | + } |
| 52 | + }); |
| 53 | +} else { |
| 54 | + console.log('codeboltChild has no children or does not exist.'); |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
0 commit comments