diff --git a/figma-plugin/plugin-src/constants.ts b/figma-plugin/plugin-src/constants.ts new file mode 100644 index 0000000..217ddb3 --- /dev/null +++ b/figma-plugin/plugin-src/constants.ts @@ -0,0 +1,11 @@ +export const Tag = { + service: "tag:service", + figmaNotPublished: "tag:figma-not-published", + fat: "tag:fat", +}; + +export const Meta = { + service: "[서비스아이콘]", + fat: "_fat", + figmaNotPublished: ".", +}; diff --git a/figma-plugin/plugin-src/service.ts b/figma-plugin/plugin-src/service.ts index 4b70503..14cd8ad 100644 --- a/figma-plugin/plugin-src/service.ts +++ b/figma-plugin/plugin-src/service.ts @@ -3,6 +3,7 @@ import type { IconaIconData } from "@icona/types"; import { Base64 } from "js-base64"; import type { PngOptionPayload } from "../common/types"; +import { Meta, Tag } from "./constants"; import { stripBeforeIcon } from "./utils"; type TargetNode = @@ -109,6 +110,7 @@ function createRegexWithDelimiters( export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { const datas = await Promise.allSettled( nodes.map(async (component) => { + const name = component.name; const node = figma.getNodeById(component.id) as ComponentNode; const description = component.description; const regex = createRegexWithDelimiters("[", "]"); @@ -117,15 +119,25 @@ export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { const metadatas = []; // 피그마에서 node name 앞에 `.`이 붙어있는 경우에는 `tag:figma-not-published`로 처리 - if (node.name.startsWith(".")) { - metadatas.push("tag:figma-not-published"); + if (name.startsWith(Meta.figmaNotPublished)) { + metadatas.push(Tag.figmaNotPublished); + } + + // 피그마에서 node name에 `[서비스아이콘]`이 포함되어 있는 경우에는 `tag:service`로 처리 + if (name.includes(Meta.service)) { + metadatas.push(Tag.service); + } + + // 피그마에서 node name에 `_fat`이 포함되어 있는 경우에는 `tag:fat`로 처리 + if (name.includes(Meta.fat)) { + metadatas.push(Tag.fat); } if (metadatasRegexResult && metadatasRegexResult.length === 2) { metadatas.push(...metadatasRegexResult[1].split(",")); return { - name: stripBeforeIcon(component.name), + name: stripBeforeIcon(name), svg: await node.exportAsync({ format: "SVG_STRING", svgIdAttribute: true, @@ -135,7 +147,7 @@ export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { } return { - name: stripBeforeIcon(component.name), + name: stripBeforeIcon(name), svg: await node.exportAsync({ format: "SVG_STRING", svgIdAttribute: true, diff --git a/figma-plugin/plugin-src/utils.ts b/figma-plugin/plugin-src/utils.ts index 1a9c19a..23c2bee 100644 --- a/figma-plugin/plugin-src/utils.ts +++ b/figma-plugin/plugin-src/utils.ts @@ -25,11 +25,11 @@ export function getIconaFrame(): FrameNode { /** * @param name .icon_name or ❌icon_name * @returns icon_name - * @description `icon` 앞에 있는 내용들은 전부 제거 후 반환 + * @description `icon_` 앞에 있는 내용들은 전부 제거 후 반환 */ export function stripBeforeIcon(name: string) { if (name.includes("icon")) { - return name.replace(/.*icon/, "icon"); + return name.replace(/.*icon_/, "icon_"); } return name;