2020-10-06 20:23:26 +02:00
|
|
|
import path from 'path';
|
|
|
|
|
|
2024-06-28 11:24:37 +02:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
|
import { toPascalCase, toCamelCase, resetFile, appendFile } from '@lucide/helpers';
|
2025-06-18 15:47:24 +02:00
|
|
|
import type { IconNode } from '../types.ts';
|
2020-10-06 20:23:26 +02:00
|
|
|
|
2025-02-10 14:13:52 +01:00
|
|
|
export default async function generateExportFile(
|
2025-06-18 15:47:24 +02:00
|
|
|
inputEntry: string,
|
|
|
|
|
outputDirectory: string,
|
|
|
|
|
iconNodes: IconNode,
|
|
|
|
|
exportModuleNameCasing: 'camel' | 'pascal',
|
2024-06-28 11:24:37 +02:00
|
|
|
iconFileExtension = '',
|
2025-02-10 14:13:52 +01:00
|
|
|
) {
|
2020-10-06 20:23:26 +02:00
|
|
|
const fileName = path.basename(inputEntry);
|
|
|
|
|
|
|
|
|
|
// Reset file
|
2025-02-10 14:13:52 +01:00
|
|
|
await resetFile(fileName, outputDirectory);
|
2020-10-06 20:23:26 +02:00
|
|
|
|
|
|
|
|
const icons = Object.keys(iconNodes);
|
|
|
|
|
|
|
|
|
|
// Generate Import for Icon VNodes
|
2025-02-10 14:13:52 +01:00
|
|
|
const iconImportNodesPromises = icons.map(async (iconName) => {
|
2024-06-28 11:24:37 +02:00
|
|
|
let componentName;
|
|
|
|
|
|
|
|
|
|
if (exportModuleNameCasing === 'camel') {
|
|
|
|
|
componentName = toCamelCase(iconName);
|
|
|
|
|
} else if (exportModuleNameCasing === 'pascal') {
|
|
|
|
|
componentName = toPascalCase(iconName);
|
|
|
|
|
}
|
2023-01-17 08:04:34 +01:00
|
|
|
const importString = `export { default as ${componentName} } from './${iconName}${iconFileExtension}';\n`;
|
2025-02-10 14:13:52 +01:00
|
|
|
return appendFile(importString, fileName, outputDirectory);
|
2020-10-06 20:23:26 +02:00
|
|
|
});
|
|
|
|
|
|
2025-02-10 14:13:52 +01:00
|
|
|
await Promise.all(iconImportNodesPromises);
|
|
|
|
|
|
|
|
|
|
await appendFile('\n', fileName, outputDirectory);
|
2020-10-06 20:23:26 +02:00
|
|
|
|
|
|
|
|
console.log(`Successfully generated ${fileName} file`);
|
2025-02-10 14:13:52 +01:00
|
|
|
}
|