(cwd, components, currentDir, jenkinsPosition)
| 101 | |
| 102 | // Gather all component overviews |
| 103 | function getComponents(cwd, components, currentDir, jenkinsPosition) { |
| 104 | var imgDir = path.join(currentDir, "img"); |
| 105 | if (!fs.existsSync(imgDir)) { |
| 106 | fs.mkdirSync(imgDir); |
| 107 | } |
| 108 | |
| 109 | components.forEach(function (overview) { |
| 110 | var componentDirName = path.dirname(overview); |
| 111 | var componentHeader = path.basename(componentDirName); |
| 112 | // Create the component article file, i.e. button.md |
| 113 | var componentArticleFile = path.join(currentDir, componentHeader + ".md"); |
| 114 | |
| 115 | var componentPrettyHeader = prettify(componentHeader); |
| 116 | |
| 117 | var componentArticlesOrder = []; |
| 118 | // Jenkins Header |
| 119 | // MetaData.md |
| 120 | var subDirPath = overview.replace("/overview.md", ""); |
| 121 | var pathExists = fs.existsSync(path.join(subDirPath, "metadata.md")); |
| 122 | |
| 123 | if (pathExists) { |
| 124 | var metadata = path.join(subDirPath, "metadata.md"); |
| 125 | var metadataContents = fs.readFileSync(metadata, { encoding: 'utf8' }); |
| 126 | var metadataSplit = metadataContents.split("---"); |
| 127 | fs.appendFileSync(componentArticleFile, "---\n", { encoding: 'utf8' }); |
| 128 | fs.appendFileSync(componentArticleFile, metadataSplit[1], { encoding: 'utf8' }); |
| 129 | fs.appendFileSync(componentArticleFile, "---\n\n", { encoding: 'utf8' }); |
| 130 | |
| 131 | if (metadataSplit[2].indexOf("example-order") >= 0) { |
| 132 | var exampleOrderString = metadataSplit[2].split(":"); |
| 133 | var orderString = exampleOrderString[1].replace(/\s/g, ''); |
| 134 | componentArticlesOrder = orderString.split(","); |
| 135 | } |
| 136 | } |
| 137 | else { |
| 138 | fs.appendFileSync(componentArticleFile, "---\n", { encoding: 'utf8' }); |
| 139 | fs.appendFileSync(componentArticleFile, "title: " + componentPrettyHeader + "\n", { encoding: 'utf8' }); |
| 140 | fs.appendFileSync(componentArticleFile, "description: " + componentPrettyHeader + " SDK Examples" + "\n", { encoding: 'utf8' }); |
| 141 | fs.appendFileSync(componentArticleFile, "position: " + jenkinsPosition++ + "\n", { encoding: 'utf8' }); |
| 142 | fs.appendFileSync(componentArticleFile, "slug: " + componentHeader + "\n", { encoding: 'utf8' }); |
| 143 | fs.appendFileSync(componentArticleFile, "---\n\n", { encoding: 'utf8' }); |
| 144 | } |
| 145 | |
| 146 | // Component Markdown Header |
| 147 | fs.appendFileSync(componentArticleFile, "# " + componentPrettyHeader + "\n\n", { encoding: 'utf8' }); |
| 148 | |
| 149 | // Component Overview |
| 150 | var overviewContents = fs.readFileSync(overview, { encoding: 'utf8' }); |
| 151 | fs.appendFileSync(componentArticleFile, overviewContents + "\n\n", { encoding: 'utf8' }); |
| 152 | |
| 153 | // Component Images |
| 154 | let componentImage = path.join(componentDirName, "image.png"); |
| 155 | if (fs.existsSync(componentImage)) { |
| 156 | let newImageFileName = componentHeader + "-" + "image.png"; |
| 157 | fs.copySync(componentImage, path.join(imgDir, newImageFileName)); |
| 158 | |
| 159 | fs.appendFileSync(componentArticleFile, "\n\n", { encoding: 'utf8' }); |
| 160 | } |
no test coverage detected