@su-record/vibe 2.9.1 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +1 -0
- package/agents/teams/debug-team.md +70 -0
- package/agents/teams/dev-team.md +88 -0
- package/agents/teams/docs-team.md +80 -0
- package/agents/teams/figma/figma-analyst.md +52 -0
- package/agents/teams/figma/figma-architect.md +112 -0
- package/agents/teams/figma/figma-auditor.md +82 -0
- package/agents/teams/figma/figma-builder.md +72 -0
- package/agents/teams/figma-team.md +85 -0
- package/agents/teams/fullstack-team.md +83 -0
- package/agents/teams/lite-team.md +69 -0
- package/agents/teams/migration-team.md +78 -0
- package/agents/teams/refactor-team.md +94 -0
- package/agents/teams/research-team.md +86 -0
- package/agents/teams/review-debate-team.md +125 -0
- package/agents/teams/security-team.md +81 -0
- package/commands/vibe.review.md +1 -63
- package/commands/vibe.run.md +8 -376
- package/commands/vibe.spec.md +1 -59
- package/commands/vibe.spec.review.md +1 -45
- package/hooks/scripts/figma-refine.js +315 -0
- package/hooks/scripts/figma-to-scss.js +394 -0
- package/hooks/scripts/figma-validate.js +353 -0
- package/package.json +1 -1
- package/skills/vibe.figma/SKILL.md +92 -24
- package/skills/vibe.figma/templates/component-spec.md +168 -0
- package/skills/vibe.figma.convert/SKILL.md +39 -3
- package/skills/vibe.figma.convert/rubrics/conversion-rules.md +12 -0
- package/skills/vibe.figma.extract/SKILL.md +29 -1
- package/skills/vibe.figma.extract/rubrics/image-rules.md +15 -3
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* figma-refine.js — tree.json → sections.json 정제
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node figma-refine.js <tree.json> --out=<sections.json> --design-width=<px> [--bp=<breakpoint>]
|
|
8
|
+
*
|
|
9
|
+
* 정제 규칙:
|
|
10
|
+
* 1. 1depth 자식을 섹션으로 분할
|
|
11
|
+
* 2. 크기 0px, 장식선 (≤2px), isMask 노드 제거
|
|
12
|
+
* 3. BG 프레임 → images.bg로 분리
|
|
13
|
+
* 4. 벡터 글자 GROUP → images.content로 분리
|
|
14
|
+
* 5. 디자인 텍스트 (multi-fill, gradient, effects) → images.content로 분리
|
|
15
|
+
* 6. 전체 children 재귀 포함 — 잎 노드까지
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from 'fs';
|
|
19
|
+
import path from 'path';
|
|
20
|
+
|
|
21
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
function nameToKebab(name) {
|
|
24
|
+
return name
|
|
25
|
+
.replace(/[^a-zA-Z0-9\s_-]/g, '')
|
|
26
|
+
.replace(/[\s_]+/g, '-')
|
|
27
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/-+/g, '-')
|
|
30
|
+
.replace(/^-|-$/g, '') || 'unnamed';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ─── Node Classification ────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
function isZeroSize(node) {
|
|
36
|
+
const w = node.size?.width || 0;
|
|
37
|
+
const h = node.size?.height || 0;
|
|
38
|
+
return w === 0 && h === 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isDecorationLine(node) {
|
|
42
|
+
// VECTOR 장식선: w ≤ 2 or h ≤ 2
|
|
43
|
+
if (node.type !== 'VECTOR') return false;
|
|
44
|
+
const w = node.size?.width || 0;
|
|
45
|
+
const h = node.size?.height || 0;
|
|
46
|
+
return (w <= 2 || h <= 2) && (w > 0 || h > 0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isBGFrame(node) {
|
|
50
|
+
const name = (node.name || '').toLowerCase();
|
|
51
|
+
return name === 'bg' || name.endsWith('-bg') || name.startsWith('bg-') || name.startsWith('bg ');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isVectorTextGroup(node) {
|
|
55
|
+
// 부모 GROUP/FRAME 아래 VECTOR 3개 이상, 각 <60px
|
|
56
|
+
if (node.type !== 'GROUP' && node.type !== 'FRAME') return false;
|
|
57
|
+
const children = node.children || [];
|
|
58
|
+
const vectors = children.filter(c => c.type === 'VECTOR');
|
|
59
|
+
if (vectors.length < 3) return false;
|
|
60
|
+
return vectors.every(v => {
|
|
61
|
+
const w = v.size?.width || 0;
|
|
62
|
+
const h = v.size?.height || 0;
|
|
63
|
+
return w < 60 && h < 60;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isDesignText(node) {
|
|
68
|
+
if (node.type !== 'TEXT') return false;
|
|
69
|
+
const fills = node.fills || [];
|
|
70
|
+
const css = node.css || {};
|
|
71
|
+
|
|
72
|
+
// Multi-fill (2개 이상)
|
|
73
|
+
if (fills.length > 1) return true;
|
|
74
|
+
|
|
75
|
+
// Gradient fill
|
|
76
|
+
if (fills.some(f => (f.type || '').includes('GRADIENT'))) return true;
|
|
77
|
+
|
|
78
|
+
// Effects (box-shadow from effects indicates design text with effects)
|
|
79
|
+
// Check if has complex visual effects beyond simple color
|
|
80
|
+
if (css.boxShadow || css.filter || css.backdropFilter) return true;
|
|
81
|
+
|
|
82
|
+
// outline on text = stroke effect
|
|
83
|
+
if (css.outline) return true;
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── Node Refinement ────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
function refineNode(node, sectionName, images) {
|
|
91
|
+
// 필터: 제거 대상
|
|
92
|
+
if (isZeroSize(node)) return null;
|
|
93
|
+
if (isDecorationLine(node)) return null;
|
|
94
|
+
if (node.isMask) return null;
|
|
95
|
+
|
|
96
|
+
// BG 프레임 → images로 분리
|
|
97
|
+
if (isBGFrame(node)) {
|
|
98
|
+
const bgName = `${nameToKebab(sectionName)}-bg`;
|
|
99
|
+
images.bg = `bg/${bgName}.webp`;
|
|
100
|
+
return null; // children에서 제거
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 벡터 글자 GROUP → images로 분리
|
|
104
|
+
if (isVectorTextGroup(node)) {
|
|
105
|
+
const contentName = `${nameToKebab(sectionName)}-${nameToKebab(node.name || 'text')}`;
|
|
106
|
+
images.content.push({
|
|
107
|
+
name: contentName,
|
|
108
|
+
path: `content/${contentName}.webp`,
|
|
109
|
+
nodeId: node.nodeId,
|
|
110
|
+
originalName: node.name,
|
|
111
|
+
type: 'vector-text'
|
|
112
|
+
});
|
|
113
|
+
// 렌더링 이미지로 대체: type을 IMAGE_PLACEHOLDER로 마킹
|
|
114
|
+
return {
|
|
115
|
+
nodeId: node.nodeId,
|
|
116
|
+
name: node.name,
|
|
117
|
+
type: 'RENDERED_IMAGE',
|
|
118
|
+
size: node.size,
|
|
119
|
+
css: node.css || {},
|
|
120
|
+
imagePath: `content/${contentName}.webp`,
|
|
121
|
+
children: []
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 디자인 텍스트 → images로 분리
|
|
126
|
+
if (isDesignText(node)) {
|
|
127
|
+
const contentName = `${nameToKebab(sectionName)}-${nameToKebab(node.name || 'design-text')}`;
|
|
128
|
+
images.content.push({
|
|
129
|
+
name: contentName,
|
|
130
|
+
path: `content/${contentName}.webp`,
|
|
131
|
+
nodeId: node.nodeId,
|
|
132
|
+
originalName: node.name,
|
|
133
|
+
text: node.text,
|
|
134
|
+
type: 'design-text'
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
nodeId: node.nodeId,
|
|
138
|
+
name: node.name,
|
|
139
|
+
type: 'RENDERED_IMAGE',
|
|
140
|
+
size: node.size,
|
|
141
|
+
css: node.css || {},
|
|
142
|
+
imagePath: `content/${contentName}.webp`,
|
|
143
|
+
text: node.text,
|
|
144
|
+
children: []
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 일반 노드 → 재귀 정제
|
|
149
|
+
const refined = {
|
|
150
|
+
nodeId: node.nodeId,
|
|
151
|
+
name: node.name,
|
|
152
|
+
type: node.type,
|
|
153
|
+
size: node.size,
|
|
154
|
+
css: node.css || {}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 메타데이터 보존
|
|
158
|
+
if (node.text) refined.text = node.text;
|
|
159
|
+
if (node.imageRef) refined.imageRef = node.imageRef;
|
|
160
|
+
if (node.imageScaleMode) refined.imageScaleMode = node.imageScaleMode;
|
|
161
|
+
if (node.fills) refined.fills = node.fills;
|
|
162
|
+
if (node.layoutSizingH) refined.layoutSizingH = node.layoutSizingH;
|
|
163
|
+
if (node.layoutSizingV) refined.layoutSizingV = node.layoutSizingV;
|
|
164
|
+
|
|
165
|
+
// children 재귀 정제
|
|
166
|
+
refined.children = [];
|
|
167
|
+
for (const child of (node.children || [])) {
|
|
168
|
+
const refinedChild = refineNode(child, sectionName, images);
|
|
169
|
+
if (refinedChild) refined.children.push(refinedChild);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return refined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ─── Section Splitting ──────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
function findMainFrame(tree) {
|
|
178
|
+
// 루트가 직접 섹션을 가지고 있으면 그대로 반환
|
|
179
|
+
const children = tree.children || [];
|
|
180
|
+
|
|
181
|
+
// 1depth에서 섹션 후보 찾기 (GNB/Footer 제외)
|
|
182
|
+
const sectionCandidates = children.filter(c => {
|
|
183
|
+
const name = (c.name || '').toLowerCase();
|
|
184
|
+
const isNav = name.includes('gnb') || name.includes('footer') || name.includes('nav');
|
|
185
|
+
return !isNav;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 1depth 자식이 1개고 FRAME이면 → 래퍼 프레임, 그 안의 children이 진짜 섹션
|
|
189
|
+
if (sectionCandidates.length === 1 && sectionCandidates[0].type === 'FRAME') {
|
|
190
|
+
const inner = sectionCandidates[0];
|
|
191
|
+
const innerChildren = inner.children || [];
|
|
192
|
+
// 내부에 2개 이상 자식이 있으면 래퍼로 판단
|
|
193
|
+
if (innerChildren.length >= 2) {
|
|
194
|
+
return inner;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return tree;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function splitIntoSections(tree, designWidth) {
|
|
202
|
+
const mainFrame = findMainFrame(tree);
|
|
203
|
+
const children = mainFrame.children || [];
|
|
204
|
+
const sections = [];
|
|
205
|
+
|
|
206
|
+
for (const child of children) {
|
|
207
|
+
const name = child.name || `Section_${sections.length}`;
|
|
208
|
+
|
|
209
|
+
// GNB/Footer 스킵
|
|
210
|
+
const nameLower = name.toLowerCase();
|
|
211
|
+
if (nameLower.includes('gnb') || nameLower.includes('footer')) continue;
|
|
212
|
+
|
|
213
|
+
// 래퍼 프레임 (이름이 "Frame NNN" 패턴이고 children이 있으면 풀어서 처리)
|
|
214
|
+
const isWrapper = /^Frame\s+\d+$/.test(name) && (child.children || []).length > 0;
|
|
215
|
+
if (isWrapper) {
|
|
216
|
+
// 래퍼 안의 자식을 섹션으로
|
|
217
|
+
for (const inner of (child.children || [])) {
|
|
218
|
+
const innerName = inner.name || `Section_${sections.length}`;
|
|
219
|
+
const images = { bg: null, content: [] };
|
|
220
|
+
const refined = refineNode(inner, innerName, images);
|
|
221
|
+
if (refined) {
|
|
222
|
+
refined.images = images;
|
|
223
|
+
sections.push(refined);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
const images = { bg: null, content: [] };
|
|
228
|
+
const refined = refineNode(child, name, images);
|
|
229
|
+
if (refined) {
|
|
230
|
+
refined.images = images;
|
|
231
|
+
sections.push(refined);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return sections;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ─── Stats ──────────────────────────────────────────────────────────
|
|
240
|
+
|
|
241
|
+
function countNodes(node) {
|
|
242
|
+
let count = 1;
|
|
243
|
+
for (const c of (node.children || [])) {
|
|
244
|
+
count += countNodes(c);
|
|
245
|
+
}
|
|
246
|
+
return count;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ─── Main ───────────────────────────────────────────────────────────
|
|
250
|
+
|
|
251
|
+
function main() {
|
|
252
|
+
const args = process.argv.slice(2);
|
|
253
|
+
if (args.length < 1) {
|
|
254
|
+
console.error('Usage: node figma-refine.js <tree.json> --out=<sections.json> --design-width=<px>');
|
|
255
|
+
process.exit(1);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const inputFile = args[0];
|
|
259
|
+
let outFile = '';
|
|
260
|
+
let designWidth = 720;
|
|
261
|
+
let breakpoint = '';
|
|
262
|
+
|
|
263
|
+
for (const arg of args.slice(1)) {
|
|
264
|
+
if (arg.startsWith('--out=')) outFile = arg.slice(6);
|
|
265
|
+
if (arg.startsWith('--design-width=')) designWidth = parseInt(arg.slice(15));
|
|
266
|
+
if (arg.startsWith('--bp=')) breakpoint = arg.slice(5);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (!outFile) {
|
|
270
|
+
console.error('--out=<sections.json> required');
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 입력 읽기
|
|
275
|
+
const tree = JSON.parse(fs.readFileSync(inputFile, 'utf-8'));
|
|
276
|
+
|
|
277
|
+
// 섹션 분할 + 정제
|
|
278
|
+
const sections = splitIntoSections(tree, designWidth);
|
|
279
|
+
|
|
280
|
+
// 결과
|
|
281
|
+
const result = {
|
|
282
|
+
meta: {
|
|
283
|
+
feature: nameToKebab(tree.name || 'feature'),
|
|
284
|
+
designWidth,
|
|
285
|
+
...(breakpoint ? { breakpoint } : {})
|
|
286
|
+
},
|
|
287
|
+
sections
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// 출력
|
|
291
|
+
const outDir = path.dirname(outFile);
|
|
292
|
+
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
293
|
+
fs.writeFileSync(outFile, JSON.stringify(result, null, 2));
|
|
294
|
+
|
|
295
|
+
// 통계 출력
|
|
296
|
+
const totalNodes = sections.reduce((sum, s) => sum + countNodes(s), 0);
|
|
297
|
+
const totalImages = sections.reduce((sum, s) => {
|
|
298
|
+
const imgs = s.images || {};
|
|
299
|
+
return sum + (imgs.bg ? 1 : 0) + (imgs.content || []).length;
|
|
300
|
+
}, 0);
|
|
301
|
+
|
|
302
|
+
const stats = {
|
|
303
|
+
sections: sections.map(s => ({
|
|
304
|
+
name: s.name,
|
|
305
|
+
nodes: countNodes(s),
|
|
306
|
+
bg: s.images?.bg || null,
|
|
307
|
+
contentImages: (s.images?.content || []).length
|
|
308
|
+
})),
|
|
309
|
+
total: { sections: sections.length, nodes: totalNodes, images: totalImages }
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
console.log(JSON.stringify(stats, null, 2));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
main();
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* figma-to-scss.js — sections.json → SCSS 기계적 생성
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node figma-to-scss.js <sections.json> --out=<dir> [--section=<name>]
|
|
8
|
+
*
|
|
9
|
+
* 입력: sections.json (Phase 3 정제 결과)
|
|
10
|
+
* 출력: 섹션별 SCSS 파일 (px 그대로, vw 변환 없음)
|
|
11
|
+
*
|
|
12
|
+
* 원칙:
|
|
13
|
+
* ⛔ CSS 값은 sections.json에서 1:1 직접 매핑
|
|
14
|
+
* ⛔ 자체 함수/믹스인 생성 금지
|
|
15
|
+
* ⛔ vw 변환, clamp, aspect-ratio 등 추가 속성 금지
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from 'fs';
|
|
19
|
+
import path from 'path';
|
|
20
|
+
|
|
21
|
+
// ─── Config ─────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
const CSS_LAYOUT_PROPS = new Set([
|
|
24
|
+
'display', 'flexDirection', 'justifyContent', 'alignItems', 'flexWrap',
|
|
25
|
+
'gap', 'padding', 'width', 'height', 'minWidth', 'minHeight',
|
|
26
|
+
'maxWidth', 'maxHeight', 'position', 'top', 'right', 'bottom', 'left',
|
|
27
|
+
'overflow', 'zIndex', 'flex', 'flexGrow', 'flexShrink', 'flexBasis',
|
|
28
|
+
'alignSelf', 'boxSizing', 'transform'
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const CSS_VISUAL_PROPS = new Set([
|
|
32
|
+
'backgroundColor', 'backgroundImage', 'backgroundSize', 'backgroundPosition',
|
|
33
|
+
'backgroundRepeat', 'backgroundBlendMode', 'color', 'fontFamily', 'fontSize',
|
|
34
|
+
'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign', 'textTransform',
|
|
35
|
+
'textOverflow', 'whiteSpace', 'borderRadius', 'border', 'borderTop',
|
|
36
|
+
'borderRight', 'borderBottom', 'borderLeft', 'borderStyle', 'outline',
|
|
37
|
+
'boxShadow', 'opacity', 'mixBlendMode', 'filter', 'backdropFilter',
|
|
38
|
+
'marginBottom'
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
function camelToKebab(str) {
|
|
44
|
+
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function nameToClass(name) {
|
|
48
|
+
// 한글/특수문자 제거, 영문+숫자만 유지
|
|
49
|
+
return name
|
|
50
|
+
.replace(/[^a-zA-Z0-9\s_-]/g, '')
|
|
51
|
+
.replace(/[\s_]+/g, '-')
|
|
52
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/-+/g, '-')
|
|
55
|
+
.replace(/^-|-$/g, '')
|
|
56
|
+
|| null; // 영문이 없으면 null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function nodeToClassName(node, index) {
|
|
60
|
+
const name = node.name || '';
|
|
61
|
+
const type = node.type || '';
|
|
62
|
+
|
|
63
|
+
// 1. Figma name에서 영문 클래스명 추출
|
|
64
|
+
let cls = nameToClass(name);
|
|
65
|
+
|
|
66
|
+
// 2. 영문이 없으면 (한글 TEXT 등) → 타입+인덱스로 대체
|
|
67
|
+
if (!cls) {
|
|
68
|
+
if (type === 'TEXT') cls = `text-${index}`;
|
|
69
|
+
else if (type === 'VECTOR') cls = `vector-${index}`;
|
|
70
|
+
else if (type === 'RECTANGLE') cls = `rect-${index}`;
|
|
71
|
+
else if (type === 'ELLIPSE') cls = `ellipse-${index}`;
|
|
72
|
+
else if (type === 'GROUP') cls = `group-${index}`;
|
|
73
|
+
else cls = `el-${index}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return cls;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isBGFrame(node) {
|
|
80
|
+
const name = (node.name || '').toLowerCase();
|
|
81
|
+
return name === 'bg' || name.endsWith('-bg') || name.startsWith('bg-');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function indent(level) {
|
|
85
|
+
return ' '.repeat(level);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── CSS Generation ─────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
function cssValue(prop, value) {
|
|
91
|
+
// 값 그대로 출력 — 변환 없음
|
|
92
|
+
return `${camelToKebab(prop)}: ${value};`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function generateCSSBlock(css, indentLevel) {
|
|
96
|
+
if (!css || Object.keys(css).length === 0) return '';
|
|
97
|
+
const lines = [];
|
|
98
|
+
for (const [prop, value] of Object.entries(css)) {
|
|
99
|
+
if (value === undefined || value === null || value === '') continue;
|
|
100
|
+
// 내부 메타 필드 스킵
|
|
101
|
+
if (prop.startsWith('_')) continue;
|
|
102
|
+
lines.push(`${indent(indentLevel)}${cssValue(prop, value)}`);
|
|
103
|
+
}
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ─── BG 처리 ────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
function generateBGStyles(sectionClass, images, indentLevel) {
|
|
110
|
+
if (!images?.bg) return '';
|
|
111
|
+
const lines = [];
|
|
112
|
+
lines.push(`${indent(indentLevel)}background-image: url('${images.bg}');`);
|
|
113
|
+
lines.push(`${indent(indentLevel)}background-size: cover;`);
|
|
114
|
+
lines.push(`${indent(indentLevel)}background-position: center top;`);
|
|
115
|
+
lines.push(`${indent(indentLevel)}background-repeat: no-repeat;`);
|
|
116
|
+
return lines.join('\n');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ─── Node → SCSS 재귀 ──────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Flat BEM 방식: .section, .section__parent-child 형태
|
|
123
|
+
* 부모 경로를 포함하여 중복 클래스명 방지.
|
|
124
|
+
* SCSS nesting 없이 모든 클래스를 루트 레벨로 출력.
|
|
125
|
+
*/
|
|
126
|
+
function collectNodeBlocks(node, sectionClass, isRoot, childIndex, blocks, parentPath) {
|
|
127
|
+
const css = node.css || {};
|
|
128
|
+
const children = node.children || [];
|
|
129
|
+
|
|
130
|
+
// 클래스명 결정: 부모 경로 포함으로 유니크하게
|
|
131
|
+
const nodeCls = isRoot ? null : nodeToClassName(node, childIndex || 0);
|
|
132
|
+
|
|
133
|
+
// 현재 노드의 경로 (부모-자식 체인)
|
|
134
|
+
let currentPath;
|
|
135
|
+
if (isRoot) {
|
|
136
|
+
currentPath = '';
|
|
137
|
+
} else if (parentPath) {
|
|
138
|
+
currentPath = `${parentPath}-${nodeCls}`;
|
|
139
|
+
} else {
|
|
140
|
+
currentPath = nodeCls;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const selector = isRoot ? `.${sectionClass}` : `.${sectionClass}__${currentPath}`;
|
|
144
|
+
|
|
145
|
+
// BG 프레임 → 스킵 (이미지로 렌더링됨)
|
|
146
|
+
if (!isRoot && isBGFrame(node)) {
|
|
147
|
+
blocks.push({ selector: null, comment: `// BG frame "${node.name}" → background-image on .${sectionClass}` });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const hasCSS = Object.keys(css).length > 0;
|
|
152
|
+
const hasImages = node.images?.bg;
|
|
153
|
+
const hasImageRef = node.imageRef && node.imageScaleMode;
|
|
154
|
+
|
|
155
|
+
if (hasCSS || hasImages || hasImageRef) {
|
|
156
|
+
const block = { selector, lines: [], nodeId: node.nodeId, name: node.name };
|
|
157
|
+
|
|
158
|
+
// BG 이미지
|
|
159
|
+
if (hasImages) {
|
|
160
|
+
block.lines.push(`background-image: url('${node.images.bg}');`);
|
|
161
|
+
block.lines.push(`background-size: cover;`);
|
|
162
|
+
block.lines.push(`background-position: center top;`);
|
|
163
|
+
block.lines.push(`background-repeat: no-repeat;`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// CSS 속성
|
|
167
|
+
for (const [prop, value] of Object.entries(css)) {
|
|
168
|
+
if (value === undefined || value === null || value === '') continue;
|
|
169
|
+
if (prop.startsWith('_')) continue;
|
|
170
|
+
block.lines.push(`${camelToKebab(prop)}: ${value};`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// imageRef
|
|
174
|
+
if (hasImageRef && !hasImages) {
|
|
175
|
+
const sizeMap = { 'FILL': 'cover', 'FIT': 'contain', 'CROP': 'cover', 'TILE': 'auto' };
|
|
176
|
+
block.lines.push(`// imageRef: ${node.imageRef}`);
|
|
177
|
+
block.lines.push(`background-size: ${sizeMap[node.imageScaleMode] || 'cover'};`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
blocks.push(block);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 자식 재귀 (BG 프레임 제외, 중복 클래스 첫 번째만)
|
|
184
|
+
const seenClasses = new Set();
|
|
185
|
+
let idx = 0;
|
|
186
|
+
for (const child of children) {
|
|
187
|
+
const childCls = nodeToClassName(child, idx);
|
|
188
|
+
if (seenClasses.has(childCls)) { idx++; continue; }
|
|
189
|
+
seenClasses.add(childCls);
|
|
190
|
+
collectNodeBlocks(child, sectionClass, false, idx, blocks, currentPath);
|
|
191
|
+
idx++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ─── Section → SCSS 파일 ───────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
function generateSectionSCSS(section) {
|
|
198
|
+
const sectionClass = nameToClass(section.name);
|
|
199
|
+
const lines = [];
|
|
200
|
+
|
|
201
|
+
// 헤더 코멘트
|
|
202
|
+
lines.push(`// ${section.name} — Auto-generated from sections.json`);
|
|
203
|
+
lines.push(`// ⛔ 이 파일의 CSS 값을 수동 수정하지 마세요.`);
|
|
204
|
+
lines.push('');
|
|
205
|
+
|
|
206
|
+
// Flat BEM 블록 수집
|
|
207
|
+
const blocks = [];
|
|
208
|
+
collectNodeBlocks(section, sectionClass, true, 0, blocks, '');
|
|
209
|
+
|
|
210
|
+
// 블록 → SCSS 텍스트
|
|
211
|
+
for (const block of blocks) {
|
|
212
|
+
if (block.comment) {
|
|
213
|
+
lines.push(block.comment);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (!block.selector || block.lines.length === 0) continue;
|
|
217
|
+
lines.push(`${block.selector} {`);
|
|
218
|
+
for (const line of block.lines) {
|
|
219
|
+
lines.push(` ${line}`);
|
|
220
|
+
}
|
|
221
|
+
lines.push('}');
|
|
222
|
+
lines.push('');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return lines.join('\n') + '\n';
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ─── _tokens.scss 생성 ─────────────────────────────────────────────
|
|
229
|
+
|
|
230
|
+
function generateTokens(meta, sections) {
|
|
231
|
+
const lines = [];
|
|
232
|
+
lines.push(`// Design Tokens — Auto-generated from sections.json`);
|
|
233
|
+
lines.push(`// Feature: ${meta.feature}`);
|
|
234
|
+
lines.push(`// Design Width: ${meta.designWidth}px`);
|
|
235
|
+
lines.push('');
|
|
236
|
+
lines.push(`$design-width: ${meta.designWidth}px;`);
|
|
237
|
+
if (meta.breakpoint) {
|
|
238
|
+
lines.push(`$bp-desktop: ${meta.breakpoint};`);
|
|
239
|
+
}
|
|
240
|
+
lines.push('');
|
|
241
|
+
|
|
242
|
+
// 색상 토큰 추출 (모든 섹션에서 사용된 색상)
|
|
243
|
+
const colors = new Map();
|
|
244
|
+
const fonts = new Set();
|
|
245
|
+
|
|
246
|
+
function extractTokens(node) {
|
|
247
|
+
const css = node.css || {};
|
|
248
|
+
for (const [prop, value] of Object.entries(css)) {
|
|
249
|
+
if (typeof value !== 'string') continue;
|
|
250
|
+
// 색상 추출
|
|
251
|
+
if (prop === 'backgroundColor' || prop === 'color' || prop === 'border') {
|
|
252
|
+
const hexMatch = value.match(/#[0-9a-fA-F]{3,8}/g);
|
|
253
|
+
if (hexMatch) hexMatch.forEach(c => colors.set(c.toLowerCase(), (colors.get(c.toLowerCase()) || 0) + 1));
|
|
254
|
+
const rgbaMatch = value.match(/rgba?\([^)]+\)/g);
|
|
255
|
+
if (rgbaMatch) rgbaMatch.forEach(c => colors.set(c, (colors.get(c) || 0) + 1));
|
|
256
|
+
}
|
|
257
|
+
// 폰트 추출
|
|
258
|
+
if (prop === 'fontFamily') {
|
|
259
|
+
const font = value.replace(/['"]/g, '').split(',')[0].trim();
|
|
260
|
+
fonts.add(font);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
(node.children || []).forEach(extractTokens);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
sections.forEach(s => extractTokens(s));
|
|
267
|
+
|
|
268
|
+
// 폰트 토큰
|
|
269
|
+
if (fonts.size > 0) {
|
|
270
|
+
lines.push('// Fonts');
|
|
271
|
+
let i = 0;
|
|
272
|
+
for (const font of fonts) {
|
|
273
|
+
const varName = `$font-${nameToClass(font) ?? `family-${i}`}`;
|
|
274
|
+
lines.push(`${varName}: '${font}', sans-serif;`);
|
|
275
|
+
i++;
|
|
276
|
+
}
|
|
277
|
+
lines.push('');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// 자주 사용되는 색상만 토큰화 (2회 이상)
|
|
281
|
+
const frequentColors = [...colors.entries()].filter(([, count]) => count >= 2).sort((a, b) => b[1] - a[1]);
|
|
282
|
+
if (frequentColors.length > 0) {
|
|
283
|
+
lines.push('// Colors (used 2+ times)');
|
|
284
|
+
frequentColors.forEach(([color], i) => {
|
|
285
|
+
lines.push(`$color-${i + 1}: ${color};`);
|
|
286
|
+
});
|
|
287
|
+
lines.push('');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return lines.join('\n') + '\n';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ─── _base.scss 생성 ────────────────────────────────────────────────
|
|
294
|
+
|
|
295
|
+
function generateBase(meta) {
|
|
296
|
+
return `// Base — Auto-generated
|
|
297
|
+
// ⛔ 이 파일의 CSS 값을 수동 수정하지 마세요.
|
|
298
|
+
|
|
299
|
+
.${nameToClass(meta.feature)} {
|
|
300
|
+
width: ${meta.designWidth}px;
|
|
301
|
+
margin: 0 auto;
|
|
302
|
+
overflow-x: hidden;
|
|
303
|
+
}
|
|
304
|
+
`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ─── index.scss 생성 ────────────────────────────────────────────────
|
|
308
|
+
|
|
309
|
+
function generateIndex(meta, sections) {
|
|
310
|
+
const lines = [];
|
|
311
|
+
lines.push(`// Index — Auto-generated`);
|
|
312
|
+
lines.push(`@use 'tokens';`);
|
|
313
|
+
lines.push(`@use 'base';`);
|
|
314
|
+
lines.push('');
|
|
315
|
+
for (const s of sections) {
|
|
316
|
+
const name = nameToClass(s.name);
|
|
317
|
+
lines.push(`@use '${name}';`);
|
|
318
|
+
}
|
|
319
|
+
return lines.join('\n') + '\n';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ─── Main ───────────────────────────────────────────────────────────
|
|
323
|
+
|
|
324
|
+
function main() {
|
|
325
|
+
const args = process.argv.slice(2);
|
|
326
|
+
if (args.length < 1) {
|
|
327
|
+
console.error('Usage: node figma-to-scss.js <sections.json> --out=<dir> [--section=<name>]');
|
|
328
|
+
process.exit(1);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const inputFile = args[0];
|
|
332
|
+
let outDir = '';
|
|
333
|
+
let sectionFilter = '';
|
|
334
|
+
|
|
335
|
+
for (const arg of args.slice(1)) {
|
|
336
|
+
if (arg.startsWith('--out=')) outDir = arg.slice(6);
|
|
337
|
+
if (arg.startsWith('--section=')) sectionFilter = arg.slice(10);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!outDir) {
|
|
341
|
+
console.error('--out=<dir> required');
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 입력 읽기
|
|
346
|
+
const data = JSON.parse(fs.readFileSync(inputFile, 'utf-8'));
|
|
347
|
+
const meta = data.meta || {};
|
|
348
|
+
let sections = data.sections || [];
|
|
349
|
+
|
|
350
|
+
if (sectionFilter) {
|
|
351
|
+
sections = sections.filter(s => s.name === sectionFilter);
|
|
352
|
+
if (sections.length === 0) {
|
|
353
|
+
console.error(`Section "${sectionFilter}" not found`);
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 출력 디렉토리 생성
|
|
359
|
+
if (!fs.existsSync(outDir)) {
|
|
360
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const results = { files: [], sections: [] };
|
|
364
|
+
|
|
365
|
+
// _tokens.scss
|
|
366
|
+
const tokensFile = path.join(outDir, '_tokens.scss');
|
|
367
|
+
fs.writeFileSync(tokensFile, generateTokens(meta, sections));
|
|
368
|
+
results.files.push(tokensFile);
|
|
369
|
+
|
|
370
|
+
// _base.scss
|
|
371
|
+
const baseFile = path.join(outDir, '_base.scss');
|
|
372
|
+
fs.writeFileSync(baseFile, generateBase(meta));
|
|
373
|
+
results.files.push(baseFile);
|
|
374
|
+
|
|
375
|
+
// 섹션별 SCSS
|
|
376
|
+
for (const section of sections) {
|
|
377
|
+
const name = nameToClass(section.name);
|
|
378
|
+
const scssFile = path.join(outDir, `_${name}.scss`);
|
|
379
|
+
const scss = generateSectionSCSS(section);
|
|
380
|
+
fs.writeFileSync(scssFile, scss);
|
|
381
|
+
results.files.push(scssFile);
|
|
382
|
+
results.sections.push({ name: section.name, file: scssFile, classes: name });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// index.scss
|
|
386
|
+
const indexFile = path.join(outDir, 'index.scss');
|
|
387
|
+
fs.writeFileSync(indexFile, generateIndex(meta, sections));
|
|
388
|
+
results.files.push(indexFile);
|
|
389
|
+
|
|
390
|
+
// 결과 출력
|
|
391
|
+
console.log(JSON.stringify(results, null, 2));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
main();
|