Added git pre commit hook for checking the contents of icons.json

This commit is contained in:
Karsa
2022-05-30 18:40:10 +02:00
parent 6ecf908ded
commit b924c0a70b
4 changed files with 56 additions and 2 deletions
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
yarn checkIcons
exit $?
+1 -1
View File
@@ -4882,4 +4882,4 @@
"icon": "cloud-sun"
}
}
}
}
+2 -1
View File
@@ -39,7 +39,8 @@
"addtags": "babel-node ./scripts/addMissingKeysToTags.js --presets @babel/env",
"tags2icons": "babel-node ./scripts/migrateTagsToIcons.js --presets @babel/env",
"icons2tags": "babel-node ./scripts/migrateIconsToTags.js --presets @babel/env",
"generate:changelog": "babel-node ./scripts/generateChangelog.js --presets @babel/env"
"generate:changelog": "babel-node ./scripts/generateChangelog.js --presets @babel/env",
"checkIcons": "babel-node ./scripts/checkIconsAndCategories.js --presets @babel/env"
},
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.25.2",
+49
View File
@@ -0,0 +1,49 @@
import path from 'path';
import icons from '../icons.json';
import {readSvgDirectory} from './helpers';
const ICONS_DIR = path.resolve(__dirname, '../icons');
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.');
}