Add normalizeSvgIconName utility
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
export function normalizeSvgIconName(iconName?: string): string | undefined {
|
||||||
|
if (!iconName || iconName.startsWith("octicon")) {
|
||||||
|
return iconName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconName.startsWith("lucide ")) {
|
||||||
|
const lucideName = iconName.slice("lucide ".length).split(".")[0].trim();
|
||||||
|
return lucideName ? `lucide-${lucideName}` : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return iconName;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { promises as fs } from "fs";
|
|||||||
import { safeLoad } from "js-yaml";
|
import { safeLoad } from "js-yaml";
|
||||||
import { basename, extname, join } from "path";
|
import { basename, extname, join } from "path";
|
||||||
import { exec } from "./exec";
|
import { exec } from "./exec";
|
||||||
|
import { normalizeSvgIconName } from "../shared/icon-utils";
|
||||||
|
|
||||||
interface WorkflowDesc {
|
interface WorkflowDesc {
|
||||||
folder: string;
|
folder: string;
|
||||||
@@ -30,19 +31,6 @@ interface WorkflowsCheckResult {
|
|||||||
incompatibleWorkflows: WorkflowDesc[];
|
incompatibleWorkflows: WorkflowDesc[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeSvgIconName(iconName?: string): string | undefined {
|
|
||||||
if (!iconName || iconName.startsWith("octicon")) {
|
|
||||||
return iconName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iconName.startsWith("lucide ")) {
|
|
||||||
const lucideName = iconName.slice("lucide ".length).split(".")[0].trim();
|
|
||||||
return lucideName ? `lucide-${lucideName}` : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iconName;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkWorkflows(
|
async function checkWorkflows(
|
||||||
folders: string[],
|
folders: string[],
|
||||||
enabledActions: string[],
|
enabledActions: string[],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { safeLoad } from "js-yaml";
|
|||||||
import { basename, extname, join, dirname } from "path";
|
import { basename, extname, join, dirname } from "path";
|
||||||
import { Validator as validator } from "jsonschema";
|
import { Validator as validator } from "jsonschema";
|
||||||
import { endGroup, error, info, setFailed, startGroup } from '@actions/core';
|
import { endGroup, error, info, setFailed, startGroup } from '@actions/core';
|
||||||
|
import { normalizeSvgIconName } from '../shared/icon-utils';
|
||||||
|
|
||||||
interface WorkflowWithErrors {
|
interface WorkflowWithErrors {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -128,15 +129,7 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string, allow
|
|||||||
|
|
||||||
if (properties.iconName) {
|
if (properties.iconName) {
|
||||||
if(! /^octicon\s+/.test(properties.iconName)) {
|
if(! /^octicon\s+/.test(properties.iconName)) {
|
||||||
let svgIconName: string | undefined = properties.iconName
|
const svgIconName = normalizeSvgIconName(properties.iconName);
|
||||||
if (properties.iconName.startsWith("lucide ")) {
|
|
||||||
const lucideName = properties.iconName.slice("lucide ".length).split(".")[0].trim()
|
|
||||||
if(!lucideName) {
|
|
||||||
svgIconName = undefined
|
|
||||||
} else {
|
|
||||||
svgIconName = `lucide-${lucideName}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!svgIconName) {
|
if(!svgIconName) {
|
||||||
workflowErrors.errors.push(`No icon named ${properties.iconName} found`)
|
workflowErrors.errors.push(`No icon named ${properties.iconName} found`)
|
||||||
|
|||||||
Reference in New Issue
Block a user