at main 1.2 kB view raw
1import fs from 'fs'; 2import path from 'path'; 3import { readSvgDirectory, toCamelCase } from '@lucide/helpers'; 4 5const currentDir = process.cwd(); 6const ICONS_DIR = path.resolve(currentDir, '../icons'); 7const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json'); 8 9const location = path.resolve(currentDir, '.vitepress/data', 'iconMetaData.ts'); 10 11if (fs.existsSync(location)) { 12 fs.unlinkSync(location); 13} 14 15const iconMetaIndexFileImports = []; 16const iconMetaIndexFileExports = []; 17 18iconJsonFiles.forEach((iconJsonFile) => { 19 const iconName = path.basename(iconJsonFile, '.json'); 20 21 iconMetaIndexFileImports.push( 22 `import ${toCamelCase(iconName)}Metadata from '../../../icons/${iconName}.json';`, 23 ); 24 iconMetaIndexFileExports.push(` '${iconName}': ${toCamelCase(iconName)}Metadata,`); 25}); 26 27try { 28 await fs.promises.writeFile( 29 location, 30 `\ 31${iconMetaIndexFileImports.join('\n')} 32 33 34 export default { 35${iconMetaIndexFileExports.join('\n')} 36 } 37 `, 38 'utf-8', 39 ); 40 41 console.log('Successfully write icon json file index'); 42} catch (error) { 43 throw new Error(`Something went wrong generating icon json file index file,\n ${error}`); 44}