Skip to content

Commit

Permalink
chore: Updated icon validator package (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber authored Jan 16, 2025
1 parent 1e6fb9f commit eab0d8c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 53 deletions.
52 changes: 29 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"webfont": "^11.2.26",
"zeta-icon-name-checker": "^0.0.15"
"@zebra-fed/zeta-icon-validator": "^0.1.5"
},
"keywords": [
"zeta",
Expand Down Expand Up @@ -81,4 +81,4 @@
"url": "https://github.com/zebratechnologies/zeta-icons/issues"
},
"homepage": "https://github.com/zebratechnologies/zeta-icons#readme"
}
}
68 changes: 43 additions & 25 deletions scripts/fetch-icons/generators/generateIconManifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { checkIconName, checkCategoryName, ErrorSeverity } from "zeta-icon-name-checker";
import {
ErrorSeverity,
RenameErrorType,
validateCategoryName,
validateIcon,
ZetaIconNameError,
} from "@zebra-fed/zeta-icon-validator";
import { extractIconSets, getSearchTerms } from "../../utils/figmaUtils.js";
import { IconManifest } from "../../../types.js";
import { getIconFileName, toSnakeCase } from "../../utils/fileUtils.js";
Expand Down Expand Up @@ -32,7 +38,7 @@ export function generateIconManifest(
console.log(`---------------- Current category: ${formattedCategoryName} ----------------`);
}

const categoryNameError = checkCategoryName(formattedCategoryName);
const categoryNameError = validateCategoryName(formattedCategoryName);

if (categoryNameError.severity == ErrorSeverity.high) {
console.log(categoryNameError.message);
Expand All @@ -47,33 +53,45 @@ export function generateIconManifest(
console.log(`Current Icon: ${name}`);
}

const nameError = checkIconName(name, category.name, usedIconNames);
const validationErrors = validateIcon(icon, category.name, usedIconNames);

if (nameError.severity == ErrorSeverity.high) {
console.log(nameError.message);
} else {
if (nameError.severity == ErrorSeverity.medium) console.log(nameError.message);
if (nameError.newName != undefined) {
name = nameError.newName;
let highestSeverity = ErrorSeverity.none;

for (const error of validationErrors) {
if (error.severity == ErrorSeverity.high) {
console.log(`❌ ${name}`, error.message);
highestSeverity = ErrorSeverity.high;
break;
} else if (error instanceof ZetaIconNameError && error.type == RenameErrorType.iconRenamed && error.newName) {
console.log(`✅ ${name} Renamed to: ${error.newName}`);
name = error.newName;
} else if (error.severity == ErrorSeverity.medium) {
highestSeverity = ErrorSeverity.medium;
console.log(`${name}`, error.message);
}
}

usedIconNames.push(name);
try {
const sharpId = icon.children.filter((n) => n.name.toLowerCase().includes("sharp"))[0].id;
const roundId = icon.children.filter((n) => n.name.toLowerCase().includes("round"))[0].id;
// If the highest severity is high, skip the icon
if (highestSeverity == ErrorSeverity.high) {
continue;
}

iconMap.set(icon.id, {
name: name,
searchTerms: getSearchTerms(icon.id, componentSets),
roundPath: `${iconOutputDir}/${formattedCategoryName}/${getIconFileName(name, "round")}.svg`,
sharpPath: `${iconOutputDir}/${formattedCategoryName}/${getIconFileName(name, "sharp")}.svg`,
category: formattedCategoryName,
roundId: roundId,
sharpId: sharpId,
});
} catch (e) {
throw new Error(`❌ Error finding styles for ${name}`);
}
usedIconNames.push(name);
try {
const sharpId = icon.children.filter((n) => n.name.toLowerCase().includes("sharp"))[0].id;
const roundId = icon.children.filter((n) => n.name.toLowerCase().includes("round"))[0].id;

iconMap.set(icon.id, {
name: name,
searchTerms: getSearchTerms(icon.id, componentSets),
roundPath: `${iconOutputDir}/${formattedCategoryName}/${getIconFileName(name, "round")}.svg`,
sharpPath: `${iconOutputDir}/${formattedCategoryName}/${getIconFileName(name, "sharp")}.svg`,
category: formattedCategoryName,
roundId: roundId,
sharpId: sharpId,
});
} catch (e) {
throw new Error(` Error finding styles for ${name}`);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/types/figmaTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ComponentPropertyDefinitions } from "@zebra-fed/zeta-icon-validator/dist/src/figma-types";

export type ComponentSets = Map<string, Component>;

export interface DocumentResponse {
Expand All @@ -11,6 +13,7 @@ export interface FigmaNode {
id: string;
type: string;
children: FigmaNode[];
componentPropertyDefinitions: ComponentPropertyDefinitions;
}

export interface Component {
Expand Down
2 changes: 1 addition & 1 deletion test/data/categoryNodes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/documentResponse.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/iconsPage.json

Large diffs are not rendered by default.

0 comments on commit eab0d8c

Please sign in to comment.