design-to-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDesign to Code
设计转代码
High-fidelity UI restoration from Figma designs to production-ready React + TypeScript components.
This SKILL uses a robust helper script to minimize manual errors and ensure pixel-perfect results.
将Figma设计高保真还原为生产就绪的React + TypeScript组件。
本SKILL借助强大的辅助脚本减少手动错误,确保像素级精准的结果。
Prerequisites
前置条件
- Figma API Token: Get from Figma → Settings → Personal Access Tokens
- Node.js: Version 18+
- coderio: Installed in folder (handled by Setup phase)
scripts/
- Figma API令牌:从Figma → 设置 → 个人访问令牌获取
- Node.js:版本18+
- coderio:已安装在目录下(由设置阶段处理)
scripts/
Workflow Overview
工作流概述
Phase 0: SETUP → Create helper script and script environment
Phase 1: PROTOCOL → Generate design protocol (Structure & Props)
Phase 2: CODE → Generate components and assetsPhase 0: SETUP → Create helper script and script environment
Phase 1: PROTOCOL → Generate design protocol (Structure & Props)
Phase 2: CODE → Generate components and assetsPhase 0: Setup
阶段0:设置
Step 0.1: Initialize Helper Script
步骤0.1:初始化辅助脚本
User Action: Run these commands to create the execution helper and isolate its dependencies.
bash
mkdir -p scripts用户操作:运行以下命令创建执行辅助工具并隔离其依赖项。
bash
mkdir -p scripts1. Copy script files
1. 复制脚本文件
Note: Ensure you have the 'skills/design-to-code/scripts' directory available
注意:确保你拥有'skills/design-to-code/scripts'目录
cp skills/design-to-code/scripts/package.json scripts/package.json
cp skills/design-to-code/scripts/coderio-skill.mjs scripts/coderio-skill.mjs
cp skills/design-to-code/scripts/package.json scripts/package.json
cp skills/design-to-code/scripts/coderio-skill.mjs scripts/coderio-skill.mjs
2. Install coderio in scripts directory (adjust version if needed)
2. 在scripts目录中安装coderio(如有需要可调整版本)
cd scripts && pnpm install && cd ..
undefinedcd scripts && pnpm install && cd ..
undefinedStep 0.2: Scaffold Project (Optional)
步骤0.2:搭建项目(可选)
If starting a new project:
- Run:
node scripts/coderio-skill.mjs scaffold-prompt "MyApp" - AI Task: Follow the instructions output by the command to create files.
如果是启动新项目:
- 运行:
node scripts/coderio-skill.mjs scaffold-prompt "MyApp" - AI任务:按照命令输出的说明创建文件。
Phase 1: Protocol Generation
阶段1:协议生成
Step 1.1: Fetch Data
步骤1.1:获取数据
bash
undefinedbash
undefinedReplace with your URL and Token
替换为你的URL和令牌
node scripts/coderio-skill.mjs fetch-figma "https://figma.com/file/..." "figd_..."
**Verify**: `process/thumbnail.png` should exist.node scripts/coderio-skill.mjs fetch-figma "https://figma.com/file/..." "figd_..."
**验证**:`process/thumbnail.png`应已生成。Step 1.2: Generate Structure
步骤1.2:生成结构
-
Generate Prompt:bash
node scripts/coderio-skill.mjs structure-prompt > scripts/structure-prompt.md -
AI Task (Structure):
- ATTACH: (MANDATORY)
process/thumbnail.png - READ:
scripts/structure-prompt.md - INSTRUCTION: "Generate the component structure JSON based on the prompt and the attached thumbnail. Focus on visual grouping. Use text content to name components accurately (e.g. 'SafeProducts', not 'FAQ')."
- SAVE: Paste the JSON result into .
scripts/structure-output.json
- ATTACH:
-
Process Result:bash
node scripts/coderio-skill.mjs save-structure
-
生成提示词:bash
node scripts/coderio-skill.mjs structure-prompt > scripts/structure-prompt.md -
AI任务(结构):
- 附加:(必填)
process/thumbnail.png - 阅读:
scripts/structure-prompt.md - 说明:“根据提示词和附加的缩略图生成组件结构JSON。重点关注视觉分组。使用文本内容准确命名组件(例如'SafeProducts',而非'FAQ')。”
- 保存:将JSON结果粘贴到中。
scripts/structure-output.json
- 附加:
-
处理结果:bash
node scripts/coderio-skill.mjs save-structure
Step 1.3: Extract Props (Iterative)
步骤1.3:提取Props(迭代式)
-
List Components:bash
node scripts/coderio-skill.mjs list-components -
For EACH component in the list:a. Generate Prompt:bash
node scripts/coderio-skill.mjs props-prompt "ComponentName" > scripts/current-props-prompt.mdb. AI Task (Props):- ATTACH: (MANDATORY)
process/thumbnail.png - READ:
scripts/current-props-prompt.md - INSTRUCTION: "Extract props and state data. Be pixel-perfect with text and image paths."
- SAVE: Paste the JSON result into .
scripts/ComponentName-props.json
c. Save & Validate:bashnode scripts/coderio-skill.mjs save-props "ComponentName" # If this fails, re-do step 'b' with better attention to the thumbnail - ATTACH:
-
列出组件:bash
node scripts/coderio-skill.mjs list-components -
针对列表中的每个组件:a. 生成提示词:bash
node scripts/coderio-skill.mjs props-prompt "ComponentName" > scripts/current-props-prompt.mdb. AI任务(Props):- 附加:(必填)
process/thumbnail.png - 阅读:
scripts/current-props-prompt.md - 说明:“提取Props和状态数据。在文本和图片路径上做到像素级精准。”
- 保存:将JSON结果粘贴到中。
scripts/ComponentName-props.json
c. 保存并验证:bashnode scripts/coderio-skill.mjs save-props "ComponentName" # 如果失败,请重新执行步骤'b',并更仔细地查看缩略图 - 附加:
Phase 2: Code Generation
阶段2:代码生成
Step 2.1: Plan Tasks
步骤2.1:规划任务
bash
node scripts/coderio-skill.mjs list-gen-tasksThis outputs a list of tasks with indices (0, 1, 2...).
bash
node scripts/coderio-skill.mjs list-gen-tasks此命令会输出带有序号(0、1、2...)的任务列表。
Step 2.2: Generate Components (Iterative)
步骤2.2:生成组件(迭代式)
For EACH task index (starting from 0):
-
Generate Prompt:bash
node scripts/coderio-skill.mjs code-prompt 0 > scripts/code-prompt.md # Replace '0' with current task index -
AI Task (Code):
- ATTACH: (MANDATORY)
process/thumbnail.png - READ:
scripts/code-prompt.md - INSTRUCTION: "Generate the React component code. Match the thumbnail EXACTLY. Use STRICT text content from input data, do not hallucinate."
- SAVE: Paste the code block into .
scripts/code-output.txt
- ATTACH:
-
Save Code:bash
node scripts/coderio-skill.mjs save-code 0 # Replace '0' with current task index
针对每个任务序号(从0开始):
-
生成提示词:bash
node scripts/coderio-skill.mjs code-prompt 0 > scripts/code-prompt.md # 将'0'替换为当前任务序号 -
AI任务(代码):
- 附加:(必填)
process/thumbnail.png - 阅读:
scripts/code-prompt.md - 说明:“生成React组件代码。完全匹配缩略图。使用输入数据中的严格文本内容,不要虚构信息。”
- 保存:将代码块粘贴到中。
scripts/code-output.txt
- 附加:
-
保存代码:bash
node scripts/coderio-skill.mjs save-code 0 # 将'0'替换为当前任务序号
Step 2.3: Final Integration
步骤2.3:最终集成
Inject the root component into . Use the path found in the last task of Phase 2.1.
App.tsx将根组件注入到中。使用阶段2.1最后一个任务中找到的路径。
App.tsxTroubleshooting
故障排除
- "Props validation failed": The AI generated empty props. Check if was attached and visible to the AI. Retry the props generation step.
process/thumbnail.png - "Module not found": Ensure was run for the child component before the parent component. Phase 2 must be done in order (0, 1, 2...).
node scripts/coderio-skill.mjs save-code - "Visuals don't match": Did you attach the thumbnail? The AI relies on it for spacing and layout nuances not present in the raw data.
- “Props验证失败”:AI生成了空Props。检查是否已附加并能被AI看到。重新执行Props生成步骤。
process/thumbnail.png - “模块未找到”:确保在父组件之前已为子组件执行。阶段2必须按顺序执行(0、1、2...)。
node scripts/coderio-skill.mjs save-code - “视觉效果不匹配”:你是否附加了缩略图?AI依赖它来获取原始数据中没有的间距和布局细节。