2022-11-07 11:34:40 +01:00
|
|
|
import path from 'path';
|
2023-02-16 08:26:29 +01:00
|
|
|
import { writeFile, getCurrentDirPath, readAllMetadata } from './helpers.mjs';
|
2022-11-07 11:34:40 +01:00
|
|
|
|
|
|
|
|
const currentDir = getCurrentDirPath(import.meta.url)
|
2023-02-16 08:26:29 +01:00
|
|
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
|
|
|
|
const icons = readAllMetadata(ICONS_DIR);
|
2022-11-07 11:34:40 +01:00
|
|
|
|
|
|
|
|
const newCategories = {};
|
2023-02-16 08:26:29 +01:00
|
|
|
Object.keys(icons).forEach(iconName => {
|
|
|
|
|
icons[iconName].categories.forEach(categoryName => {
|
2022-11-07 11:34:40 +01:00
|
|
|
newCategories[categoryName] = newCategories[categoryName] || [];
|
|
|
|
|
newCategories[categoryName].push(iconName);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const ordered = Object.keys(newCategories).sort().reduce(
|
|
|
|
|
(obj, key) => {
|
|
|
|
|
obj[key] = newCategories[key];
|
|
|
|
|
return obj;
|
|
|
|
|
},
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const categoriesContent = JSON.stringify(ordered, null, 2);
|
|
|
|
|
|
|
|
|
|
writeFile(categoriesContent, 'categories.json', path.resolve(currentDir, '..'));
|