2023-04-23 20:33:41 +02:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { readSvgDirectory, toCamelCase } from './helpers.mjs';
|
|
|
|
|
|
|
|
|
|
const currentDir = process.cwd();
|
|
|
|
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
|
|
|
|
const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json');
|
|
|
|
|
|
2023-05-03 22:11:49 +02:00
|
|
|
const location = path.resolve(currentDir, '.vitepress/data', 'iconMetaData.ts');
|
2023-04-23 20:33:41 +02:00
|
|
|
|
2023-05-03 22:11:49 +02:00
|
|
|
if (fs.existsSync(location)) {
|
|
|
|
|
fs.unlinkSync(location);
|
|
|
|
|
}
|
2023-04-23 20:33:41 +02:00
|
|
|
|
|
|
|
|
let outputString = '';
|
|
|
|
|
|
|
|
|
|
iconJsonFiles.forEach((iconJsonFile) => {
|
|
|
|
|
const iconName = path.basename(iconJsonFile, '.json');
|
|
|
|
|
outputString += `export { default as ${toCamelCase(
|
|
|
|
|
iconName,
|
2023-05-03 22:11:49 +02:00
|
|
|
)} } from '../../../icons/${iconName}.json';\n`;
|
2023-04-23 20:33:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fs.promises
|
|
|
|
|
.writeFile(location, outputString, 'utf-8')
|
|
|
|
|
.then(() => {
|
|
|
|
|
console.log('Successfully write icon json file index');
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw new Error(`Something went wrong generating icon json file index file,\n ${error}`);
|
|
|
|
|
});
|