2022-05-30 18:38:47 +02:00
|
|
|
import path from 'path';
|
2023-02-16 08:26:29 +01:00
|
|
|
import { readSvgDirectory, getCurrentDirPath, readAllMetadata } from './helpers.mjs';
|
2022-05-30 18:38:47 +02:00
|
|
|
|
2022-11-07 11:34:40 +01:00
|
|
|
const currentDir = getCurrentDirPath(import.meta.url)
|
|
|
|
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
2023-02-16 08:26:29 +01:00
|
|
|
const icons = readAllMetadata(ICONS_DIR);
|
|
|
|
|
const CATEGORIES_DIR = path.resolve(currentDir, '../categories');
|
|
|
|
|
const categories = readAllMetadata(CATEGORIES_DIR);
|
2022-05-30 18:38:47 +02:00
|
|
|
|
|
|
|
|
console.log(`Read all icons`);
|
|
|
|
|
|
|
|
|
|
const svgFiles = readSvgDirectory(ICONS_DIR);
|
|
|
|
|
const iconNames = svgFiles.map(icon => icon.split('.')[0]);
|
|
|
|
|
|
|
|
|
|
let error = false;
|
|
|
|
|
|
|
|
|
|
iconNames.forEach(iconName => {
|
2023-02-16 08:26:29 +01:00
|
|
|
if (typeof icons[iconName] === 'undefined') {
|
|
|
|
|
console.error(`'${iconName}.svg' does not have a matching JSON file.`);
|
2022-05-30 18:38:47 +02:00
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-16 08:26:29 +01:00
|
|
|
Object.keys(icons).forEach(iconName => {
|
|
|
|
|
const icon = icons[iconName];
|
2022-05-30 18:38:47 +02:00
|
|
|
if (iconNames.indexOf(iconName) === -1) {
|
|
|
|
|
console.error(`'${iconName}.svg' does not exist.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
icon.categories.forEach(categoryName => {
|
2023-02-16 08:26:29 +01:00
|
|
|
if (typeof categories[categoryName] === 'undefined') {
|
2022-05-30 18:38:47 +02:00
|
|
|
console.error(`Icon '${iconName}' refers to the non-existing category '${categoryName}'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-16 08:26:29 +01:00
|
|
|
Object.keys(categories).forEach(categoryName => {
|
|
|
|
|
const category = categories[categoryName];
|
2022-05-30 18:38:47 +02:00
|
|
|
if (!category.icon) {
|
|
|
|
|
console.error(`Category '${categoryName}' does not use an icon '${category.icon}'.`);
|
|
|
|
|
error = true;
|
2023-02-16 08:26:29 +01:00
|
|
|
} else if (typeof icons[category.icon] === 'undefined') {
|
2022-05-30 18:38:47 +02:00
|
|
|
console.error(`Category '${categoryName}' uses the non-existing icon '${category.icon}'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2023-02-16 08:26:29 +01:00
|
|
|
throw new Error('At least one error in icon JSONs prevents from committing changes.');
|
2022-05-30 18:38:47 +02:00
|
|
|
}
|