Skip to content

Commit

Permalink
feat(figma-plugin): 서비스 아이콘, Fat 태그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyeonsu committed Nov 12, 2024
1 parent 301d2d2 commit f21a858
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
11 changes: 11 additions & 0 deletions figma-plugin/plugin-src/constants.ts
Original file line number Diff line number Diff line change
@@ -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: ".",
};
20 changes: 16 additions & 4 deletions figma-plugin/plugin-src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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("[", "]");
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions figma-plugin/plugin-src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f21a858

Please sign in to comment.