Enhance icon validation in 'validate-pr' script to check for invalid metadata, naming conventions, and improper attributes in added icons.
This commit is contained in:
parent
d15fb80beb
commit
3fc6d1aa14
|
|
@ -1,5 +1,7 @@
|
|||
import { execSync } from 'child_process'
|
||||
import { basename } from 'path'
|
||||
import { parseMatter, ICONS_SRC_DIR } from './helpers.mjs'
|
||||
import { join } from 'path'
|
||||
|
||||
// Check icon files added relative to main branch (for PR)
|
||||
function getAddedIconsFromMain() {
|
||||
|
|
@ -11,9 +13,9 @@ function getAddedIconsFromMain() {
|
|||
if (line.startsWith('A\t')) {
|
||||
const filePath = line.substring(2)
|
||||
// Filter only SVG files from icons/outline/ or icons/filled/ directories
|
||||
if (filePath.match(/^icons\/(outline|filled)\/.+\.svg$/)) {
|
||||
const iconName = basename(filePath, '.svg')
|
||||
addedIcons.push(iconName)
|
||||
if (filePath.match(/^icons\/((outline|filled)\/.+\.svg)$/)) {
|
||||
// add icon without icons/ prefix
|
||||
addedIcons.push(filePath.replace(/^icons\//, ''))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -24,10 +26,46 @@ function getAddedIconsFromMain() {
|
|||
}
|
||||
}
|
||||
|
||||
function validateIcons(icons) {
|
||||
|
||||
for (const icon of icons) {
|
||||
const iconPath = join(ICONS_SRC_DIR, icon)
|
||||
|
||||
try {
|
||||
const { data, content } = parseMatter(iconPath)
|
||||
|
||||
if (data.unicode) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has unicode, but should not have it`)
|
||||
}
|
||||
|
||||
if (data.version) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has version, but should not have it`)
|
||||
}
|
||||
|
||||
if (!icon.match(/^[a-z0-9-]+$/)) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has invalid name`)
|
||||
}
|
||||
|
||||
// check if filled icon hasnt category
|
||||
if (icon.match(/^filled\//) && data.category) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has category, but should not have it`)
|
||||
}
|
||||
|
||||
// check if filled icon has tags
|
||||
if (icon.match(/^filled\//) && data.tags) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has tags, but should not have it`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`⛔️ Icon \`${icon}\` has invalid metadata`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const addedIcons = getAddedIconsFromMain()
|
||||
|
||||
if (addedIcons.length > 0) {
|
||||
console.log('Added icons:', addedIcons)
|
||||
validateIcons(addedIcons)
|
||||
process.exit(0)
|
||||
} else {
|
||||
process.exit(0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue