generateDynamicImports.mjs30 lines · main
| 1 | import path from 'path' |
| 2 | import { appendFile, resetFile } from '../utils/helpers.mjs' |
| 3 | |
| 4 | export default function generateDynamicImports({ |
| 5 | iconNodes, |
| 6 | outputDirectory, |
| 7 | fileExtension, |
| 8 | showLog = true, |
| 9 | }) { |
| 10 | const fileName = path.basename(`dynamicIconImports${fileExtension}`) |
| 11 | const icons = Object.keys(iconNodes) |
| 12 | |
| 13 | // Reset file |
| 14 | resetFile(fileName, outputDirectory) |
| 15 | |
| 16 | let importString = `const dynamicIconImports = {\n` |
| 17 | |
| 18 | // Generate Import for Icon VNodes |
| 19 | icons.forEach((iconName) => { |
| 20 | importString += ` '${iconName}': () => import('./icons/${iconName}'),\n` |
| 21 | }) |
| 22 | |
| 23 | importString += '};\nexport default dynamicIconImports;\n' |
| 24 | |
| 25 | appendFile(importString, fileName, outputDirectory) |
| 26 | |
| 27 | if (showLog) { |
| 28 | console.log(`Successfully generated ${fileName} file`) |
| 29 | } |
| 30 | } |