2026-07-24 15:05:40 +02:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
2026-12-02 09:15:55 +01:00
|
|
|
import { readAllMetadata } from '@lucide/helpers';
|
2026-07-24 15:05:40 +02:00
|
|
|
|
|
|
|
|
const currentDir = process.cwd();
|
2026-12-02 09:15:55 +01:00
|
|
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
|
|
|
|
const LAB_DIR = path.resolve(currentDir, '../lab');
|
2026-07-24 15:05:40 +02:00
|
|
|
|
|
|
|
|
const labDirectory = path.resolve(currentDir, '.vitepress/data/lab');
|
|
|
|
|
const location = path.resolve(currentDir, labDirectory, 'iconMetaData.ts');
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(location)) {
|
|
|
|
|
fs.unlinkSync(location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(labDirectory)) {
|
|
|
|
|
fs.mkdirSync(labDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-02 09:15:55 +01:00
|
|
|
// Bake resolved markers into the index; lab icons may extend core icons.
|
|
|
|
|
const iconMetaData = await readAllMetadata(LAB_DIR, { baseDirectory: ICONS_DIR });
|
2026-07-24 15:05:40 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await fs.promises.writeFile(
|
|
|
|
|
location,
|
2026-12-02 09:15:55 +01:00
|
|
|
`export default ${JSON.stringify(iconMetaData, null, 2)};\n`,
|
2026-07-24 15:05:40 +02:00
|
|
|
'utf-8',
|
|
|
|
|
);
|
|
|
|
|
|
2026-12-02 09:15:55 +01:00
|
|
|
console.log('Successfully write lab icon json file index');
|
2026-07-24 15:05:40 +02:00
|
|
|
} catch (error) {
|
2026-12-02 09:15:55 +01:00
|
|
|
throw new Error(`Something went wrong generating lab icon json file index file,\n ${error}`);
|
2026-07-24 15:05:40 +02:00
|
|
|
}
|