import * as fs from 'fs'; import * as path from 'path'; const inputFile: string = 'icon-list'; const outputFile: string = 'src/components/icons.rs'; const svgDir: string = 'heroicons/optimized'; function toComponentName(filePath: string): string { const parts = filePath.split('/'); const size = parts[0]; const style = parts[1]; const fileName = parts[2].replace('.svg', ''); return fileName .split('-') .map(part => part.charAt(0).toUpperCase() + part.slice(1)) .join('') + size.charAt(0).toUpperCase() + size.slice(1) + style.charAt(0).toUpperCase() + style.slice(1); } function getSizeClass(size: string): string { switch (size) { case '16': return 'size-4'; case '20': return 'size-5'; case '24': return 'size-6'; default: return ''; } } function addClassToSvg(svgContent: string, sizeClass: string): string { // Add the size class svgContent = svgContent.replace(' { const svgPath = `${file}.svg`; const parts = file.split('/'); const size = parts[0]; let svgContent: string = fs.readFileSync(path.join(svgDir, svgPath), 'utf8'); const componentName: string = toComponentName(svgPath); const sizeClass = getSizeClass(size); svgContent = addClassToSvg(svgContent, sizeClass); output += `#[component]\npub fn ${componentName}() -> impl IntoView {\n`; output += ` view! { ${svgContent} }\n}\n\n`; }); fs.writeFileSync(outputFile, output); console.log('Components generated successfully.'); } generateComponents();