2022-05-30 18:38:47 +02:00
|
|
|
import path from 'path';
|
2024-07-07 21:32:32 +02:00
|
|
|
import {
|
|
|
|
|
readSvgDirectory,
|
|
|
|
|
getCurrentDirPath,
|
|
|
|
|
readAllMetadata,
|
|
|
|
|
} from '../tools/build-helpers/helpers.mjs';
|
2022-05-30 18:38:47 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
const currentDir = getCurrentDirPath(import.meta.url);
|
2022-11-07 11:34:40 +01:00
|
|
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
2025-02-19 11:19:53 +01:00
|
|
|
const icons = await readAllMetadata(ICONS_DIR);
|
2023-02-16 08:26:29 +01:00
|
|
|
const CATEGORIES_DIR = path.resolve(currentDir, '../categories');
|
2025-02-19 11:19:53 +01:00
|
|
|
const categories = await readAllMetadata(CATEGORIES_DIR);
|
2022-05-30 18:38:47 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
console.log('Reading all icons');
|
2022-05-30 18:38:47 +02:00
|
|
|
|
2025-02-19 11:19:53 +01:00
|
|
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
2024-02-01 22:38:21 +09:00
|
|
|
const iconNames = svgFiles.map((icon) => icon.split('.')[0]);
|
2022-05-30 18:38:47 +02:00
|
|
|
|
|
|
|
|
let error = false;
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
Object.keys(icons).forEach((iconName) => {
|
2023-02-16 08:26:29 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2024-02-01 22:38:21 +09:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
Object.keys(categories).forEach((categoryName) => {
|
2023-02-16 08:26:29 +01:00
|
|
|
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-28 17:24:17 +01:00
|
|
|
console.error('At least one error in icon JSONs prevents from committing changes.');
|
|
|
|
|
process.exit(1);
|
2022-05-30 18:38:47 +02:00
|
|
|
}
|