Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 35 additions & 1 deletion figma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Web(React)은 `wanteddev/montage-web`의 `figma/`, Android(Compose)는 `wantedde
| `figma.config.json` | 라벨(`SwiftUI`), 대상 파일, Figma URL 치환표(`<FIGMA_BUTTON>` 등) |
| `package.json`, `package-lock.json`, `tsconfig.json` | Code Connect CLI 버전 고정(`@figma/code-connect` 2.1.1, 하위 의존성은 lock)과 템플릿 타입 체크 설정 |
| `swiftui/*.figma.ts` | 컴포넌트별 템플릿 (Figma variant → `Montage.*` 뷰 호출) |
| `swiftui/icons.figma.batch.*` | 아이콘 일괄 매핑 |
| `swiftui/icons.figma.batch.*` | 아이콘 일괄 매핑. `.json`은 아이콘 동기화가 만든다([아이콘 batch](#아이콘-batch) 참고) |
| `shared/` | 템플릿 공통 헬퍼 |

`.figma.ts`는 SwiftPM 빌드 대상이 아니므로 라이브러리 빌드에 영향이 없습니다.
Expand Down Expand Up @@ -39,6 +39,40 @@ FIGMA_ACCESS_TOKEN=<개인 토큰> npx figma connect publish -c figma.config.jso
- Figma main 파일 편집 권한, Dev 또는 Full seat
- `Code Connect: Write` 범위의 개인 access token. 토큰은 커밋하지 않습니다.

## 아이콘 batch

`swiftui/icons.figma.batch.json`은 아이콘 노드와 `Icon` case를 잇는 목록입니다. **손으로 고치지 않습니다.** 아이콘 동기화가 `Icon.xcassets`, `Icon` enum과 함께 다시 만듭니다.

### 갱신 흐름

1. `/montage-icon-sync`(또는 Actions의 `Figma Icon Sync` 수동 실행)로 아이콘을 동기화합니다.
2. sync job(montage-web 재사용 워크플로)이 Figma API로 아이콘 SVG와 `output/result.json`을 받습니다.
3. `scripts/icon_sync.js`가 SVG로 에셋과 enum을 갱신하고, `result.json`으로 batch를 다시 만듭니다. 결과는 한 커밋에 같이 들어갑니다.
4. 동기화 PR이 머지되면 [게시](#수정--확인--게시)합니다. **게시는 자동이 아닙니다.** 게시 전에는 새 아이콘에 Dev Mode 스니펫이 나오지 않습니다.

### 노드 ID 출처

`result.json`의 `id`는 0-Component 파일 `Icon` 섹션(Normal, Color/Logo, Color/Normal, Navigation)의 **컴포넌트 세트** 노드 ID입니다. 탐색 경로는 montage-web `.github/workflows/figma-icon-sync.yml`의 `ROOT_TRAVERSE_*_IDS`에 있습니다. Figma에서 컴포넌트 세트를 선택하고 링크를 복사하면 URL의 `node-id`와 같습니다.

- 세트 하나에 아이콘이 여러 개면 노드 하나에 variant가 여러 개 붙습니다(예: `arrowDown`, `arrowDownThick`).
- 같은 아이콘이 세트 두 곳에 있으면 노드마다 항목이 생깁니다(예: `blankColor`).
- variant `name`은 Figma `Name` 속성 값이라 `Color` 접미사를 뗍니다. `component`는 `Icon` + 파스칼 케이스입니다.

`result.json`이 없거나 SVG 목록과 어긋나면 `icon_sync.js`는 파일을 하나도 바꾸지 않고 실패합니다.

### 검증

```bash
# 레포 루트에서: batch가 생성기 출력과 같은지, 이름이 Icon enum case와 1:1인지
npm test

# figma/에서: 템플릿 타입 체크와 parse (icons.figma.batch.json은 노드 수가 나옵니다. 아이콘 수와 다릅니다)
npm run typecheck
npm run parse
```

`npm test`는 CI에서 돌지 않습니다. batch나 `Icon` enum을 건드린 PR은 올리기 전에 로컬에서 직접 돌립니다. `Icon` enum에만 case를 손으로 넣으면 1:1 테스트가 실패합니다. 아이콘은 Figma에 올린 뒤 동기화로 추가합니다.

## 주의
- **`label`(`SwiftUI`)을 바꾸지 않습니다.** 바꾸면 같은 컴포넌트에 SwiftUI 스니펫이 두 벌 게시되고, Figma MCP가 `clientFrameworks: "swiftui"`로 스니펫을 고르지 못합니다.
- **내릴 때는 `--node`와 `--label`을 함께 씁니다.** 빼면 React·Compose 스니펫까지 지워질 수 있습니다.
Expand Down
2 changes: 1 addition & 1 deletion figma/shared/icon-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 입력은 Web 아이콘 컴포넌트명에서 'Icon'을 뗀 이름(예: IconAgentColor → agentColor)
// 또는 Figma 아이콘 인스턴스의 Name variant(예: heart).

/** iOS `Icon` enum case. 360/360 이름이 그대로 일치한다. */
/** iOS `Icon` enum case. 이름이 그대로 일치한다(scripts/tests/icon_code_connect_batch.test.js에서 확인). */
export const iosIcon = (name: string): string => `.${name}`;

/** Web 아이콘 컴포넌트명(IconHeartFill) → 이름(heartFill) */
Expand Down
42 changes: 21 additions & 21 deletions figma/swiftui/icons.figma.batch.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=8-731",
"component": "IconBlankColor",
"variants": [
{
"name": "blank",
"component": "IconBlankColor"
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=13090-23582",
"component": "IconBold",
Expand Down Expand Up @@ -1654,6 +1664,16 @@
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=40167-141755",
"component": "IconLogoInstagramColor",
"variants": [
{
"name": "logoInstagram",
"component": "IconLogoInstagramColor"
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=9258-18856",
"component": "IconLogoKakao",
Expand Down Expand Up @@ -2805,27 +2825,7 @@
"component": "IconZepFastFill"
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=40167-141755",
"component": "IconLogoInstagramColor",
"variants": [
{
"name": "logoInstagram",
"component": "IconLogoInstagramColor"
}
]
},
{
"url": "<FIGMA_ICONS_BASE>?node-id=8-731",
"component": "IconBlankColor",
"variants": [
{
"name": "blank",
"component": "IconBlankColor"
}
]
}
]
}
]
]
3 changes: 2 additions & 1 deletion figma/swiftui/icons.figma.batch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// [2026-11-16] 아이콘 노드 → iOS `Icon` case. 노드 목록은 montage-web figma/icons/icons.figma.batch.json과 같다.
// [2026-11-16] 아이콘 노드 → iOS `Icon` case.
// 노드 목록(icons.figma.batch.json)은 scripts/icon_sync.js가 아이콘 동기화 때 다시 만든다. 손으로 고치지 않는다.
import figma from 'figma';

import { iosIcon, nameFromComponent } from '../shared/icon-name';
Expand Down
105 changes: 105 additions & 0 deletions scripts/icon_code_connect_batch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Figma 아이콘 sync 결과 → SwiftUI Code Connect 아이콘 batch(figma/swiftui/icons.figma.batch.json)
//
// figma-icon-sync 워크플로의 sync job(montage-web 재사용 워크플로)이 output/result.json에
// 아이콘마다 { id: 컴포넌트 세트 노드 ID('40167-141864'), name: SVG 파일명('agentColor') }를 남긴다.
// icon_sync.js가 이 파일로 batch를 다시 만들어, 아이콘이 추가·삭제되면 batch도 같은 커밋에 반영된다.
//
// 출력 규칙(montage-web scripts/figma-icon.mjs와 같은 구조)
// - 노드(url) 하나에 아이콘 variant 여러 개가 묶일 수 있다(예: arrowDown, arrowDownThick).
// - 같은 아이콘이 노드 두 곳에 있으면 노드마다 항목을 둔다(예: blankColor).
// - variant name은 Figma Name variant 값이라 'Color' 접미사를 뗀다. component는 'Icon' + 파스칼 케이스.
// - 순서는 이름 → 노드 ID 순으로 정렬해 result.json 순서와 무관하게 같은 결과가 나오게 한다.
//
// montage-web과 다른 점: 웹은 중복 노드를 노드 ID로만 걸러, 아이콘 X가 노드 A·B에 있고 B에 다른 아이콘도 있으면
// B의 X를 빠뜨린다(그 인스턴스는 템플릿 fallback으로 다른 아이콘 스니펫이 나온다). 여기서는 (노드 ID, 이름) 쌍을
// 모두 넣는다. 웹 로직으로 되돌리지 않는다.

const BATCH_PATH = 'figma/swiftui/icons.figma.batch.json';
const NODE_ID_PATTERN = /^\d+-\d+$/;

const componentName = (name) => `Icon${name.charAt(0).toUpperCase()}${name.slice(1)}`;

const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);

/**
* @param {Array<{ id: string; name: string }>} entries output/result.json 항목
* @returns {string} icons.figma.batch.json 내용(끝 줄바꿈 포함)
*/
const buildIconBatch = (entries) => {
if (!Array.isArray(entries) || entries.length === 0) {
throw new Error('result.json에 아이콘 항목이 없습니다.');
}

const seen = new Set();
const unique = [];
for (const entry of entries) {
const { id, name } = entry ?? {};
if (typeof name !== 'string' || !/^[a-z][A-Za-z0-9]*$/.test(name)) {
throw new Error(`아이콘 이름 형식이 아닙니다: ${JSON.stringify(entry)}`);
}
if (typeof id !== 'string' || !NODE_ID_PATTERN.test(id)) {
throw new Error(`노드 ID 형식이 아닙니다: ${JSON.stringify(entry)}`);
}
const key = `${id} ${name}`;
if (!seen.has(key)) {
seen.add(key);
unique.push({ id, name });
}
}

unique.sort((a, b) => compare(a.name, b.name) || compare(a.id, b.id));

const variantsByUrl = new Map();
for (const { id, name } of unique) {
const url = `<FIGMA_ICONS_BASE>?node-id=${id}`;
const variants = variantsByUrl.get(url) ?? [];
variants.push({ name: name.replace(/Color$/, ''), component: componentName(name) });
variantsByUrl.set(url, variants);
}

const batch = [
{
templateFile: './icons.figma.batch.ts',
components: [...variantsByUrl].map(([url, variants]) => ({
url,
component: variants[0].component,
variants,
})),
},
];

return `${JSON.stringify(batch, null, 2)}\n`;
};

/** batch에 들어간 아이콘 이름(= SVG 파일명 = Icon enum case) 목록 */
const iconNamesInBatch = (batchJson) => {
const names = new Set();
for (const group of JSON.parse(batchJson)) {
for (const component of group.components) {
for (const { component: c } of component.variants) {
const n = c.replace(/^Icon/, '');
names.add(n.charAt(0).toLowerCase() + n.slice(1));
}
}
}
return [...names].sort(compare);
};

/** 두 이름 목록이 다르면 차이를 담아 throw */
const assertSameNames = (expected, actual, expectedLabel, actualLabel) => {
const a = new Set(expected);
const b = new Set(actual);
const onlyExpected = [...a].filter((n) => !b.has(n)).sort(compare);
const onlyActual = [...b].filter((n) => !a.has(n)).sort(compare);
if (onlyExpected.length || onlyActual.length) {
throw new Error(
[
`${expectedLabel}와 ${actualLabel}의 아이콘 이름이 다릅니다.`,
`${expectedLabel}에만 있음: ${onlyExpected.join(', ') || '(없음)'}`,
`${actualLabel}에만 있음: ${onlyActual.join(', ') || '(없음)'}`,
].join('\n'),
);
}
};

module.exports = { BATCH_PATH, buildIconBatch, iconNamesInBatch, assertSameNames };
Loading