2023-06-04 16:59:38 +02:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
2026-10-29 17:29:58 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-29 17:29:58 +01:00
|
|
|
// 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,
|
2026-10-29 17:29:58 +01:00
|
|
|
`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}`);
|
|
|
|
|
}
|