Implement category validation for new icons and consolidate helper imports in icon generation scripts.

This commit is contained in:
codecalm 2025-12-23 01:43:28 +01:00
parent 9737c82ee4
commit 92ea3a7d1d
4 changed files with 59 additions and 7 deletions

View File

@ -1,8 +1,6 @@
import { execSync } from 'child_process'
import { readFileSync } from 'fs'
import { basename, join } from 'path'
import { ICONS_SRC_DIR } from './helpers.mjs'
import { parseMatter } from './helpers.mjs'
import { ICONS_SRC_DIR, parseMatter } from './helpers.mjs'
// Check icon files added relative to main branch (for PR)
function getAddedIconsFromMain() {

View File

@ -20,6 +20,50 @@ export const strokes = {
400: 2,
}
export const categories = [
'Animals',
'Arrows',
'Badges',
'Brand',
'Buildings',
'Charts',
'Communication',
'Computers',
'Currencies',
'Database',
'Design',
'Development',
'Devices',
'Document',
'E-commerce',
'Electrical',
'Extensions',
'Food',
'Games',
'Gender',
'Gestures',
'Health',
'Laundry',
'Letters',
'Logic',
'Map',
'Math',
'Media',
'Mood',
'Nature',
'Numbers',
'Photography',
'Shapes',
'Sport',
'Symbols',
'System',
'Text',
'Vehicles',
'Version control',
'Weather',
'Zodiac'
]
export const iconTemplate = (type) =>
type === 'outline'
? `<svg

View File

@ -1,7 +1,7 @@
import { globSync } from 'glob'
import fs from 'fs'
import { basename } from 'path'
import { HOME_DIR, ICONS_SRC_DIR, iconTemplate, parseMatter, types, getArgvs } from './helpers.mjs'
import { HOME_DIR, ICONS_SRC_DIR, iconTemplate, parseMatter, types, getArgvs, categories } from './helpers.mjs'
import { join } from 'path'
import { execSync } from 'child_process'
@ -216,6 +216,17 @@ for (const icon of addedIcons) {
error = true
}
// check if outline icon has category
if (icon.match(/^outline\//) && !data.category) {
console.log(`⛔️ New icon \`${icon}\` has no category`)
error = true
} else {
if (!categories.includes(data.category)) {
console.log(`⛔️ New icon \`${icon}\` has invalid category \`${data.category}\`. Valid categories are: ${categories.join(', ')}`)
error = true
}
}
// check if filled icon hasnt category
if (icon.match(/^filled\//) && data.category) {
console.log(`⛔️ New icon \`${icon}\` has category, but should not have it`)

View File

@ -1,8 +1,7 @@
<!--
category: Text
tags: [test, visual, user, design, a, b, 2]
category: Blabla
version: "1.76"
unicode: "f25f"
unicode: "34f25f"
-->
<svg
xmlns="http://www.w3.org/2000/svg"

Before

Width:  |  Height:  |  Size: 620 B

After

Width:  |  Height:  |  Size: 580 B