2022-05-30 18:38:47 +02:00
|
|
|
import path from 'path';
|
2022-11-07 11:34:40 +01:00
|
|
|
import icons from '../icons.json' assert { type: 'json' };
|
|
|
|
|
import { readSvgDirectory, getCurrentDirPath } 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');
|
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 => {
|
|
|
|
|
if (typeof icons.icons[iconName] === 'undefined') {
|
|
|
|
|
console.error(`'${iconName}.svg' is not present in 'icons.json'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.keys(icons.icons).forEach(iconName => {
|
|
|
|
|
const icon = icons.icons[iconName];
|
|
|
|
|
if (iconNames.indexOf(iconName) === -1) {
|
|
|
|
|
console.error(`'${iconName}.svg' does not exist.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
icon.categories.forEach(categoryName => {
|
|
|
|
|
if (typeof icons.categories[categoryName] === 'undefined') {
|
|
|
|
|
console.error(`Icon '${iconName}' refers to the non-existing category '${categoryName}'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.keys(icons.categories).forEach(categoryName => {
|
|
|
|
|
const category = icons.categories[categoryName];
|
|
|
|
|
if (!category.icon) {
|
|
|
|
|
console.error(`Category '${categoryName}' does not use an icon '${category.icon}'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
} else if (typeof icons.icons[category.icon] === 'undefined') {
|
|
|
|
|
console.error(`Category '${categoryName}' uses the non-existing icon '${category.icon}'.`);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw new Error('At least one error in icons.json prevents from committing changes.');
|
|
|
|
|
}
|