From a3c58d6286bb9949ff5b6c59ab5106b7f745b249 Mon Sep 17 00:00:00 2001 From: junghyeonsu Date: Mon, 25 Nov 2024 17:40:18 +0900 Subject: [PATCH] feat: change react index file import ext --- figma-plugin/plugin-src/constants.ts | 1 + figma-plugin/plugin-src/service.ts | 79 ++++++++++++++++------------ packages/generator/CHANGELOG.md | 8 +++ packages/generator/package.json | 4 +- packages/generator/src/core/react.ts | 2 +- packages/types/CHANGELOG.md | 6 +++ packages/types/package.json | 2 +- yarn.lock | 4 +- 8 files changed, 67 insertions(+), 39 deletions(-) diff --git a/figma-plugin/plugin-src/constants.ts b/figma-plugin/plugin-src/constants.ts index 217ddb3..bdaf5eb 100644 --- a/figma-plugin/plugin-src/constants.ts +++ b/figma-plugin/plugin-src/constants.ts @@ -1,3 +1,4 @@ +// TODO: Tag System with icona, seed-design export const Tag = { service: "tag:service", figmaNotPublished: "tag:figma-not-published", diff --git a/figma-plugin/plugin-src/service.ts b/figma-plugin/plugin-src/service.ts index 14cd8ad..e66c419 100644 --- a/figma-plugin/plugin-src/service.ts +++ b/figma-plugin/plugin-src/service.ts @@ -63,12 +63,20 @@ const findComponentInNode = ( separator: "_", }); - return { id: node.id, name: svgName, description }; + return { + id: node.id, + name: svgName, + description: description || node.description, + }; } case "COMPONENT_SET": { return node.children.flatMap((child: any) => { - return findComponentInNode(child, node.name, node.description); + return findComponentInNode( + child, + node.name, + description || node.description, + ); }); } @@ -107,44 +115,49 @@ function createRegexWithDelimiters( return new RegExp(`${start}(.*?)${end}`); } +function extractMetadataFromDescription(description: string) { + const regex = createRegexWithDelimiters("[", "]"); + const metadatasRegexResult = regex.exec(description); + + if (metadatasRegexResult && metadatasRegexResult.length === 2) { + return metadatasRegexResult[1].split(","); + } + + return []; +} + +function getMetadatasFromName(name: string) { + const metadatas = []; + + // 피그마에서 node name 앞에 `.`이 붙어있는 경우에는 `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); + } + + return metadatas; +} + 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("[", "]"); - const metadatasRegexResult = regex.exec(description || ""); - - const metadatas = []; - - // 피그마에서 node name 앞에 `.`이 붙어있는 경우에는 `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(name), - svg: await node.exportAsync({ - format: "SVG_STRING", - svgIdAttribute: true, - }), - metadatas, - }; - } + const metadatas = [ + ...extractMetadataFromDescription(description || ""), + ...getMetadatasFromName(name), + ]; return { name: stripBeforeIcon(name), diff --git a/packages/generator/CHANGELOG.md b/packages/generator/CHANGELOG.md index 3bea3b3..d4aaeee 100644 --- a/packages/generator/CHANGELOG.md +++ b/packages/generator/CHANGELOG.md @@ -1,5 +1,13 @@ # @icona/generator +## 0.9.2 + +### Patch Changes + +- react index ext +- Updated dependencies + - @icona/types@0.9.2 + ## 0.9.1 ### Patch Changes diff --git a/packages/generator/package.json b/packages/generator/package.json index e74fb9a..656784f 100644 --- a/packages/generator/package.json +++ b/packages/generator/package.json @@ -1,6 +1,6 @@ { "name": "@icona/generator", - "version": "0.9.1", + "version": "0.9.2", "repository": { "type": "git", "url": "git+https://github.com/daangn/icona.git", @@ -25,7 +25,7 @@ "prepack": "yarn build" }, "dependencies": { - "@icona/types": "^0.9.1", + "@icona/types": "^0.9.2", "@svgr/core": "^8.0.0", "@types/cli-progress": "^3.11.5", "cli-progress": "^3.12.0", diff --git a/packages/generator/src/core/react.ts b/packages/generator/src/core/react.ts index 648a2fa..ff9f9f0 100644 --- a/packages/generator/src/core/react.ts +++ b/packages/generator/src/core/react.ts @@ -107,7 +107,7 @@ export const generateReact = async (props: Props) => { if (genIndexFile) { const index = generateIndexFileTemplate({ componentNames, - ext: null, + ext: "js", }); const content = `${ignores}\n${index}`; await writeFile(resolve(targetPath, "index.ts"), content, "utf-8"); diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index cf564c8..e893f5f 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,5 +1,11 @@ # @icona/types +## 0.9.2 + +### Patch Changes + +- react index ext + ## 0.9.1 ### Patch Changes diff --git a/packages/types/package.json b/packages/types/package.json index 2c9371b..bc453a4 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@icona/types", - "version": "0.9.1", + "version": "0.9.2", "repository": { "type": "git", "url": "git+https://github.com/daangn/icona.git", diff --git a/yarn.lock b/yarn.lock index 4904c1b..32a516b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3869,7 +3869,7 @@ __metadata: version: 0.0.0-use.local resolution: "@icona/generator@workspace:packages/generator" dependencies: - "@icona/types": ^0.9.0 + "@icona/types": ^0.9.2 "@svgr/core": ^8.0.0 "@types/cli-progress": ^3.11.5 "@types/findup-sync": ^4.0.5 @@ -3913,7 +3913,7 @@ __metadata: languageName: unknown linkType: soft -"@icona/types@^0.9.0, @icona/types@workspace:^, @icona/types@workspace:packages/types": +"@icona/types@^0.9.2, @icona/types@workspace:^, @icona/types@workspace:packages/types": version: 0.0.0-use.local resolution: "@icona/types@workspace:packages/types" dependencies: