Skip to content

Commit c9af68d

Browse files
authored
feat: add docker support (#59)
1 parent ad3a7e5 commit c9af68d

File tree

4 files changed

+258
-2
lines changed

4 files changed

+258
-2
lines changed

.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output (will be rebuilt in container)
5+
dist/
6+
7+
# Git
8+
.git/
9+
.gitignore
10+
11+
# IDE
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.swo
16+
17+
# Test and coverage
18+
coverage/
19+
.nyc_output/
20+
21+
# Logs
22+
*.log
23+
npm-debug.log*
24+
pnpm-debug.log*
25+
26+
# OS files
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Environment files
31+
.env
32+
.env.*
33+
34+
# Docker
35+
Dockerfile
36+
.dockerignore

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM node:22
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update \
6+
&& apt-get install -y vim git build-essential \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Copy dependency files for version extraction
10+
COPY package.json pnpm-lock.yaml ./
11+
12+
# Parse peerDependenciesMeta and install corresponding versions
13+
RUN node -e " \
14+
const fs = require('fs'); \
15+
const { execSync } = require('child_process'); \
16+
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); \
17+
const lock = fs.readFileSync('./pnpm-lock.yaml', 'utf8'); \
18+
const peers = Object.keys(pkg.peerDependenciesMeta || {}); \
19+
const packages = peers.map(name => { \
20+
const regex = new RegExp('[/\\\\s]' + name + '@([0-9.]+)[:\\\\)]'); \
21+
const match = lock.match(regex); \
22+
if (!match) throw new Error('Version not found in lockfile for: ' + name); \
23+
return name + '@' + match[1]; \
24+
}); \
25+
console.log('Installing peerDependencies:', packages.join(' ')); \
26+
if (packages.length > 0) { \
27+
execSync('npm install -g ' + packages.join(' '), { stdio: 'inherit' }); \
28+
} \
29+
"
30+
31+
# Set environment variables
32+
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright-browsers
33+
ENV NODE_PATH=/usr/local/lib/node_modules
34+
35+
# Install Playwright browsers and system dependencies
36+
RUN npx playwright install --with-deps chromium \
37+
&& chmod -R 755 $PLAYWRIGHT_BROWSERS_PATH
38+
39+
RUN npm install -g pnpm
40+
41+
# Install coderio
42+
RUN npm install -g coderio
43+
44+
45+
# Clean up temporary files
46+
RUN rm -f package.json pnpm-lock.yaml

README.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,94 @@ report path: coderio/<design-name_node-id>/process/validation/index.html
147147
| `validate` | `val` | Run validation on generated code |
148148
| `images` | - | Download and process Figma assets |
149149

150-
### Option 2: Skill (Portable Embedded Workflow)
150+
### Option 2: Docker
151+
152+
Best for portable environments without Node.js installation.
153+
154+
#### 1. Prerequisites
155+
156+
- [Docker](https://docs.docker.com/get-docker/)
157+
- [Figma Personal Access Token](https://www.figma.com/developers/api#access-tokens)
158+
- LLM API Key ([Anthropic](https://console.anthropic.com/) | [OpenAI](https://platform.openai.com/) | [Google](https://aistudio.google.com/))
159+
160+
> **For Windows Users:** The commands below use bash syntax (heredoc, `${PWD}`, `--network=host`, etc.) which are not compatible with CMD or PowerShell. Please use **WSL2** to run them:
161+
>
162+
> 1. Install [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install) and a Linux distribution (e.g. Ubuntu)
163+
> 2. Install [Docker Desktop](https://docs.docker.com/desktop/install/windows-install/) and enable **WSL2 integration** in Settings → Resources → WSL Integration
164+
> 3. Open a WSL2 terminal (run `wsl` in CMD/PowerShell, or open Ubuntu from the Start menu)
165+
> 4. Run all the following commands inside the WSL2 terminal
166+
167+
#### 2. Installation
168+
169+
```bash
170+
docker pull crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio
171+
```
172+
173+
#### 3. Configuration
174+
175+
Create a working directory and `config.yaml`:
176+
177+
```bash
178+
mkdir -p ./coderio-app && cd ./coderio-app
179+
cat > config.yaml << 'EOF'
180+
model:
181+
provider: openai # anthropic | openai | google
182+
model: gemini-3-pro-preview
183+
baseUrl: https://api.anthropic.com
184+
apiKey: your-api-key-here
185+
186+
figma:
187+
token: your-figma-token-here
188+
189+
debug:
190+
enabled: false
191+
EOF
192+
```
193+
194+
#### 4. Usage
195+
196+
```bash
197+
docker run -ti --rm \
198+
--network=host \
199+
-v ${PWD}:/app \
200+
-v ./config.yaml:/root/.coderio/config.yaml \
201+
crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio bash
202+
```
203+
204+
Once inside the container, use CodeRio commands:
205+
206+
```bash
207+
# Convert Figma design to code (default mode: code only)
208+
coderio d2c -s 'https://www.figma.com/design/your-file-id/...'
209+
210+
# Full mode: Generate code + visual validation + auto-refinement
211+
coderio d2c -s 'https://www.figma.com/design/your-file-id/...' -m full
212+
```
213+
214+
#### 5. Run Your Project
215+
216+
```bash
217+
# Navigate to generated project
218+
cd coderio/<design-name_node-id>/my-app
219+
220+
# Install dependencies
221+
pnpm install
222+
223+
# Start dev server
224+
pnpm dev
225+
226+
# 🎉 Open http://localhost:5173
227+
```
228+
229+
#### 6. View Validation Report
230+
231+
Generated files are mounted to your host machine. Open the validation report in your browser:
232+
233+
```
234+
./coderio/<design-name_node-id>/process/validation/index.html
235+
```
236+
237+
### Option 3: Skill (Portable Embedded Workflow)
151238

152239
Best for control and precision using AI Agents.
153240

README_zh-CN.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,94 @@ pnpm dev
146146
| `validate` | `val` | 对生成的代码运行验证 |
147147
| `images` | - | 下载和处理 Figma 资源 |
148148

149-
### 方式 2:Skill(便携式嵌入工作流)
149+
### 方式 2:Docker
150+
151+
基于 Docker 提供了完整运行时环境,适用于未安装 Node.js 的场景。
152+
153+
#### 1. 前置要求
154+
155+
- [Docker](https://docs.docker.com/get-docker/)
156+
- [Figma 个人访问令牌](https://www.figma.com/developers/api#access-tokens)
157+
- LLM API 密钥([Anthropic](https://console.anthropic.com/) | [OpenAI](https://platform.openai.com/) | [Google](https://aistudio.google.com/)
158+
159+
> **Windows 用户指南:** 以下命令使用了 bash 语法(heredoc、`${PWD}``--network=host` 等),无法在 CMD 或 PowerShell 中直接运行。请通过 **WSL2** 执行:
160+
>
161+
> 1. 安装 [WSL2](https://learn.microsoft.com/zh-cn/windows/wsl/install) 和 Linux 发行版(如 Ubuntu)
162+
> 2. 安装 [Docker Desktop](https://docs.docker.com/desktop/install/windows-install/),并在 Settings → Resources → WSL Integration 中开启 **WSL2 集成**
163+
> 3. 打开 WSL2 终端(在 CMD/PowerShell 中运行 `wsl`,或从开始菜单打开 Ubuntu)
164+
> 4. 在 WSL2 终端中执行以下所有命令
165+
166+
#### 2. 安装
167+
168+
```bash
169+
docker pull crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio
170+
```
171+
172+
#### 3. 配置
173+
174+
创建工作目录和 `config.yaml` 配置文件:
175+
176+
```bash
177+
mkdir -p ./coderio-app && cd ./coderio-app
178+
cat > config.yaml << 'EOF'
179+
model:
180+
provider: openai # anthropic | openai | google
181+
model: gemini-3-pro-preview
182+
baseUrl: https://api.anthropic.com
183+
apiKey: your-api-key-here
184+
185+
figma:
186+
token: your-figma-token-here
187+
188+
debug:
189+
enabled: false
190+
EOF
191+
```
192+
193+
#### 4. 使用
194+
195+
```bash
196+
docker run -ti --rm \
197+
--network=host \
198+
-v ${PWD}:/app \
199+
-v ./config.yaml:/root/.coderio/config.yaml \
200+
crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio bash
201+
```
202+
203+
进入容器后,使用 CodeRio 命令:
204+
205+
```bash
206+
# 将 Figma 设计转换为代码(默认模式:仅代码)
207+
coderio d2c -s 'https://www.figma.com/design/your-file-id/...'
208+
209+
# 完整模式:生成代码 + 视觉验证 + 自动优化
210+
coderio d2c -s 'https://www.figma.com/design/your-file-id/...' -m full
211+
```
212+
213+
#### 5. 运行项目
214+
215+
```bash
216+
# 进入生成的项目目录
217+
cd coderio/<设计文件名-页面节点编号>/my-app
218+
219+
# 安装依赖
220+
pnpm install
221+
222+
# 启动开发服务器
223+
pnpm dev
224+
225+
# 🎉 打开 http://localhost:5173
226+
```
227+
228+
#### 6. 查看验证报告
229+
230+
生成的文件会挂载到宿主机。在浏览器中打开验证报告:
231+
232+
```
233+
./coderio/<设计文件名-页面节点编号>/process/validation/index.html
234+
```
235+
236+
### 方式 3:Skill(便携式嵌入工作流)
150237

151238
适用于需要 AI 辅助和更精准控制的场景。
152239

0 commit comments

Comments
 (0)