Skip to content

Commit

Permalink
Add error message to generate-icons.ts (#1352)
Browse files Browse the repository at this point in the history
Show an error message if a file in the /icons directory doesn't contain
valid SVG code.
  • Loading branch information
thomasdax98 authored Oct 31, 2023
1 parent b4ec2c6 commit a8c7405
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/admin/admin-icons/generate-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { ESLint } from "eslint";
import { XMLParser } from "fast-xml-parser";
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import { pascalCase, pascalCaseTransformMerge } from "pascal-case";
import * as path from "path";
const eslint = new ESLint({ fix: true });

const main = async () => {
const files = readdirSync("icons");
const files = readdirSync("icons").filter((file) => {
return path.extname(file).toLowerCase() === ".svg";
});

const bar = new SingleBar(
{
Expand Down Expand Up @@ -43,6 +46,10 @@ const getPathData = (fileName: string) => {
const fileContents = readFileSync(`icons/${fileName}`);
const parsedXml = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "" }).parse(fileContents.toString());

if (parsedXml?.svg?.path?.d === undefined) {
throw new Error(`The file ${fileName} must contain a <path> element with a d attribute`);
}

return parsedXml.svg.path.d;
};

Expand Down

0 comments on commit a8c7405

Please sign in to comment.