Skip to content

Commit

Permalink
feat: change react index file import ext
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyeonsu committed Nov 25, 2024
1 parent f21a858 commit a3c58d6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 39 deletions.
1 change: 1 addition & 0 deletions figma-plugin/plugin-src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Tag System with icona, seed-design
export const Tag = {
service: "tag:service",
figmaNotPublished: "tag:figma-not-published",
Expand Down
79 changes: 46 additions & 33 deletions figma-plugin/plugin-src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
}

Expand Down Expand Up @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions packages/generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/core/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @icona/types

## 0.9.2

### Patch Changes

- react index ext

## 0.9.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a3c58d6

Please sign in to comment.