2020-10-06 20:23:26 +02:00
|
|
|
import path from 'path';
|
|
|
|
|
|
2020-12-02 13:48:39 +01:00
|
|
|
import { toPascalCase, resetFile, appendFile } from '../helpers';
|
2020-10-06 20:23:26 +02:00
|
|
|
|
2022-02-17 17:46:55 +01:00
|
|
|
export default function(inputEntry, outputDirectory, iconNodes, iconFileExtention = '') {
|
2020-10-06 20:23:26 +02:00
|
|
|
const fileName = path.basename(inputEntry);
|
|
|
|
|
|
|
|
|
|
// Reset file
|
|
|
|
|
resetFile(fileName, outputDirectory);
|
|
|
|
|
|
|
|
|
|
const icons = Object.keys(iconNodes);
|
|
|
|
|
|
2022-02-17 17:46:55 +01:00
|
|
|
const fileExtention = iconFileExtention === '.ts' || iconFileExtention === '.js' ? '' : iconFileExtention
|
|
|
|
|
|
2020-10-06 20:23:26 +02:00
|
|
|
// Generate Import for Icon VNodes
|
|
|
|
|
icons.forEach(iconName => {
|
2020-12-02 13:48:39 +01:00
|
|
|
const componentName = toPascalCase(iconName);
|
2022-02-17 17:46:55 +01:00
|
|
|
const importString = `export { default as ${componentName} } from './${iconName}${fileExtention}';\n`;
|
2020-10-06 20:23:26 +02:00
|
|
|
appendFile(importString, fileName, outputDirectory);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
appendFile('\n', fileName, outputDirectory);
|
|
|
|
|
|
|
|
|
|
console.log(`Successfully generated ${fileName} file`);
|
|
|
|
|
}
|