2023-01-11 19:08:14 +01:00
|
|
|
import csv from 'csvtojson';
|
2022-08-28 20:12:09 +02:00
|
|
|
import * as AllIcons from 'iconoir-react';
|
2023-10-29 00:33:17 +02:00
|
|
|
import { kebabCase, pascalCase } from 'scule';
|
2023-01-11 19:08:14 +01:00
|
|
|
import { Icon } from '../components/IconList';
|
2022-08-28 20:12:09 +02:00
|
|
|
|
|
|
|
const ICONS_PATH = 'icons.csv';
|
|
|
|
const TAG_SEPARATOR = '|';
|
|
|
|
|
|
|
|
export async function getAllIcons(): Promise<Icon[]> {
|
|
|
|
const rows = await csv().fromFile(ICONS_PATH);
|
2023-10-29 00:33:17 +02:00
|
|
|
|
|
|
|
const icons: Icon[] = [];
|
|
|
|
|
|
|
|
for (const row of rows) {
|
|
|
|
const iconComponentName = pascalCase(row.filename);
|
|
|
|
const iconComponentSolidName = pascalCase(`${row.filename}-solid`);
|
|
|
|
|
|
|
|
const iconComponents = Object.keys(AllIcons).filter(
|
|
|
|
(icon) => icon === iconComponentName || icon === iconComponentSolidName,
|
2022-08-28 20:12:09 +02:00
|
|
|
);
|
2023-10-29 00:33:17 +02:00
|
|
|
|
|
|
|
if (iconComponents.length === 0)
|
2022-08-28 20:12:09 +02:00
|
|
|
throw new Error(
|
2023-10-29 00:33:17 +02:00
|
|
|
`Couldn't find icons for ${row.filename} (${iconComponentName}) in 'iconoir-react'.`,
|
2022-08-28 20:12:09 +02:00
|
|
|
);
|
2023-10-29 00:33:17 +02:00
|
|
|
|
|
|
|
for (const iconComponent of iconComponents) {
|
|
|
|
icons.push({
|
|
|
|
filename: kebabCase(iconComponent),
|
|
|
|
category: row.category,
|
|
|
|
tags:
|
|
|
|
row.tags?.split(TAG_SEPARATOR).map((item: string) => item.trim()) ||
|
|
|
|
[],
|
|
|
|
iconComponentName: iconComponent,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return icons;
|
2022-08-28 20:12:09 +02:00
|
|
|
}
|