Files

30 lines
882 B
TypeScript
Raw Permalink Normal View History

2023-06-04 16:59:38 +02:00
import fs from 'fs';
import path from 'path';
import { readAllMetadata } from '@lucide/helpers';
2023-06-04 16:59:38 +02:00
const currentDir = process.cwd();
const ICONS_DIR = path.resolve(currentDir, '../icons');
const location = path.resolve(currentDir, '.vitepress/data', 'iconMetaData.ts');
if (fs.existsSync(location)) {
fs.unlinkSync(location);
}
// The docs read this index raw and never re-resolve, so resolve the
// `$extends:<icon-name>` markers here and bake the inherited
// tags/categories/contributors into the generated file.
const iconMetaData = await readAllMetadata(ICONS_DIR);
2023-06-04 16:59:38 +02:00
try {
await fs.promises.writeFile(
location,
`export default ${JSON.stringify(iconMetaData, null, 2)};\n`,
2023-06-04 16:59:38 +02:00
'utf-8',
);
console.log('Successfully write icon json file index');
} catch (error) {
throw new Error(`Something went wrong generating icon json file index file,\n ${error}`);
}