generateExportsFile.mjs23 lines · main
| 1 | import path from 'path' |
| 2 | |
| 3 | import { appendFile, resetFile, toPascalCase } from '../utils/helpers.mjs' |
| 4 | |
| 5 | export default (inputEntry, outputDirectory, iconNodes, iconFileExtension = '') => { |
| 6 | const fileName = path.basename(inputEntry) |
| 7 | |
| 8 | // Reset file |
| 9 | resetFile(fileName, outputDirectory) |
| 10 | |
| 11 | const icons = Object.keys(iconNodes) |
| 12 | |
| 13 | // Generate Import for Icon VNodes |
| 14 | icons.forEach((iconName) => { |
| 15 | const componentName = toPascalCase(iconName) |
| 16 | const importString = `export { default as ${componentName} } from './${iconName}${iconFileExtension}';\n` |
| 17 | appendFile(importString, fileName, outputDirectory) |
| 18 | }) |
| 19 | |
| 20 | appendFile('\n', fileName, outputDirectory) |
| 21 | |
| 22 | console.log(`Successfully generated ${fileName} file`) |
| 23 | } |