2020-10-06 20:23:26 +02:00
|
|
|
import path from 'path';
|
|
|
|
|
|
2022-08-10 09:10:53 +02:00
|
|
|
import { toPascalCase, resetFile, appendFile } from '../helpers.mjs';
|
2020-10-06 20:23:26 +02:00
|
|
|
|
2022-11-07 22:29:19 +01:00
|
|
|
export default (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-08-10 09:10:53 +02:00
|
|
|
const fileExtention =
|
|
|
|
|
iconFileExtention === '.ts' || iconFileExtention === '.js' ? '' : iconFileExtention;
|
2022-02-17 17:46:55 +01:00
|
|
|
|
2020-10-06 20:23:26 +02:00
|
|
|
// Generate Import for Icon VNodes
|
2022-11-07 22:29:19 +01:00
|
|
|
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`);
|
2022-11-07 22:29:19 +01:00
|
|
|
};
|