Skip to content

Commit

Permalink
build(scripts): make some assertions warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rektdeckard committed Feb 1, 2024
1 parent f62dad6 commit d42782b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assets/bold/gear-fine-bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/duotone/gear-fine-duotone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/light/gear-fine-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/regular/gear-fine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/thin/gear-fine-thin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 22 additions & 9 deletions scripts/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from "node:fs/promises";
import path from "node:path";
import chalk from "chalk";
import { parse, type INode } from "svgson";

import {
ASSETS_PATH,
CATEGORY_MAP,
Expand All @@ -14,6 +13,9 @@ import {
type IconMetadata,
} from ".";

const PUA_START = 57344;
const PUA_END = 63743;

const WEIGHTS = new Set([
"regular",
"thin",
Expand All @@ -22,12 +24,13 @@ const WEIGHTS = new Set([
"fill",
"duotone",
]);
const PUA_START = 57344;
const PUA_END = 63743;

const INODE_CHECKS: Record<string, (i: INode) => boolean> = {
"does not use currentColor": (i) => i.attributes["fill"] !== "currentColor",
"has incorrect viewBox": (i) => i.attributes["viewBox"] !== "0 0 256 256",
} as const;

const INODE_WARNINGS: Record<string, (i: INode) => boolean> = {
"has non-path elements": (i) => i.children.some((c) => c.name !== "path"),
} as const;

Expand All @@ -52,8 +55,8 @@ const API_CHECKS: Record<string, (r: IconAPIResponse) => boolean> = {
function verifyINode(i: INode, name: string, weight: string): boolean {
let valid = true;

for (const [err, check] of Object.entries(INODE_CHECKS)) {
if (!check(i)) {
for (const [err, assertion] of Object.entries(INODE_CHECKS)) {
if (assertion(i)) {
valid = false;
console.error(
`${chalk.inverse.red(" FAIL ")} ${name}${
Expand All @@ -63,14 +66,24 @@ function verifyINode(i: INode, name: string, weight: string): boolean {
}
}

for (const [err, assertion] of Object.entries(INODE_WARNINGS)) {
if (assertion(i)) {
console.error(
`${chalk.inverse.yellow(" WARN ")} ${name}${
weight === "regular" ? "" : `-${weight}`
} ${err}`
);
}
}

return valid;
}

function verifyIconMetadata(m: IconMetadata): boolean {
let valid = true;

for (const [err, check] of Object.entries(METADATA_CHECKS)) {
if (!check(m)) {
for (const [err, assertion] of Object.entries(METADATA_CHECKS)) {
if (assertion(m)) {
valid = false;
console.error(`${chalk.inverse.red(" FAIL ")} ${m.name} ${err}`);
}
Expand Down Expand Up @@ -137,8 +150,8 @@ export async function assertValidAssets(): Promise<void> {
export function assertValidApiResponse(r: IconAPIResponse) {
let valid = true;

for (const [err, check] of Object.entries(API_CHECKS)) {
if (!check(r)) {
for (const [err, assertion] of Object.entries(API_CHECKS)) {
if (assertion(r)) {
valid = false;
console.error(`${chalk.inverse.red(" FAIL ")} ${err}`);
}
Expand Down

0 comments on commit d42782b

Please sign in to comment.