-
Notifications
You must be signed in to change notification settings - Fork 0
feat: design-to-code user tool (#35) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b303e68
65e50ba
14c81ac
f6413d3
09c6c54
aa1aca0
be6df3a
d65a4f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| name: canicode-implement | ||
| description: Prepare a design-to-code implementation package from a Figma URL or fixture | ||
| --- | ||
|
|
||
| # CanICode Implement -- Design-to-Code Package | ||
|
|
||
| Prepare everything an AI needs to implement a Figma design as code: analysis report, design tree with image assets, and a code generation prompt. | ||
|
|
||
| This skill does NOT auto-generate code. It assembles a package that you then feed to an AI coding assistant. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| One of: | ||
| - **FIGMA_TOKEN** environment variable for REST API access | ||
| - **Local fixture** directory (no token needed) | ||
|
|
||
| ## Usage | ||
|
|
||
| ### From a local fixture (simplest) | ||
|
|
||
| ```bash | ||
| npx canicode implement ./fixtures/my-design | ||
| ``` | ||
|
|
||
| ### From a Figma URL | ||
|
|
||
| ```bash | ||
| npx canicode implement "https://www.figma.com/design/ABC/File?node-id=1-234" | ||
| ``` | ||
|
|
||
| ### With a custom prompt (for your stack) | ||
|
|
||
| ```bash | ||
| npx canicode implement ./fixtures/my-design --prompt ./my-react-prompt.md | ||
| ``` | ||
|
|
||
| The default prompt generates HTML+CSS. Write your own prompt for React, Vue, or any other stack. | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | Default | | ||
| |--------|-------------|---------| | ||
| | `--prompt <path>` | Custom prompt file for your stack | Built-in HTML+CSS | | ||
| | `--output <dir>` | Output directory | `./canicode-implement/` | | ||
| | `--token <token>` | Figma API token | `FIGMA_TOKEN` env var | | ||
| | `--image-scale <n>` | Image export scale (1-4) | `2` (PC), use `3` for mobile | | ||
|
|
||
| ## Output Structure | ||
|
|
||
| ```text | ||
| canicode-implement/ | ||
| analysis.json # Full analysis with issues and scores | ||
| design-tree.txt # DOM-like tree with styles, structure, embedded SVGs | ||
| PROMPT.md # Code generation prompt (default or custom) | ||
| screenshot.png # Figma screenshot (if available) | ||
| vectors/ # SVG assets for VECTOR nodes | ||
| images/ # PNG assets for IMAGE fill nodes (hero-banner@2x.png) | ||
| ``` | ||
|
Comment on lines
+49
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show The CLI writes/copies that file when image assets are present, and the design tree uses it for 🤖 Prompt for AI Agents |
||
|
|
||
| ## Next Steps | ||
|
|
||
| After running `canicode implement`: | ||
|
|
||
| 1. Open `design-tree.txt` -- this is the primary input for the AI | ||
| 2. Open `PROMPT.md` -- this contains the coding conventions | ||
| 3. Feed both to your AI coding assistant along with any images from `images/` and `vectors/` | ||
| 4. Review `analysis.json` for known design issues that may affect implementation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,10 @@ export function printDocsIndex(): void { | |
| console.log(` | ||
| CANICODE DOCUMENTATION (v${pkg.version}) | ||
|
|
||
| canicode docs setup Full setup guide (CLI, MCP, Skills) | ||
| canicode docs rules Custom rules guide + example | ||
| canicode docs config Config override guide + example | ||
| canicode docs setup Full setup guide (CLI, MCP, Skills) | ||
| canicode docs rules Custom rules guide + example | ||
| canicode docs config Config override guide + example | ||
| canicode docs implement Design-to-code package guide | ||
|
|
||
| Full documentation: github.com/let-sunny/canicode#readme | ||
| `.trimStart()); | ||
|
|
@@ -271,11 +272,56 @@ USE CASES | |
| `.trimStart()); | ||
| } | ||
|
|
||
| /** Print the implement command guide. */ | ||
| export function printDocsImplement(): void { | ||
| console.log(` | ||
| DESIGN-TO-CODE IMPLEMENTATION GUIDE | ||
|
|
||
| Prepare everything an AI needs to implement a Figma design as code. | ||
|
|
||
| USAGE | ||
| canicode implement <figma-url-or-fixture> [options] | ||
|
|
||
| OPTIONS | ||
| --prompt <path> Custom prompt file (default: built-in HTML+CSS) | ||
| --image-scale <n> Image export scale: 2 for PC (default), 3 for mobile | ||
| --output <dir> Output directory (default: ./canicode-implement/) | ||
| --token <token> Figma API token (for live URLs) | ||
|
|
||
| OUTPUT | ||
| canicode-implement/ | ||
| analysis.json Analysis report with issues and scores | ||
| design-tree.txt DOM-like tree with CSS styles (~N tokens) | ||
| images/ PNG assets with human-readable names (hero-banner@2x.png) | ||
| vectors/ SVG assets for vector nodes | ||
| PROMPT.md Stack-specific code generation prompt | ||
|
|
||
|
Comment on lines
+291
to
+298
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document
As per coding guidelines, " 🤖 Prompt for AI Agents |
||
| WORKFLOW | ||
| 1. Run: canicode implement ./my-fixture --prompt ./my-react-prompt.md | ||
| 2. Feed design-tree.txt + PROMPT.md to your AI assistant | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 3. AI generates code matching the design pixel-perfectly | ||
| 4. Verify with: canicode visual-compare ./output.html --figma-url <url> | ||
|
|
||
| CUSTOM PROMPT | ||
| Default prompt generates HTML+CSS. For your own stack: | ||
| 1. Write a prompt file (e.g. my-react-prompt.md) | ||
| 2. Pass it: canicode implement ./fixture --prompt ./my-react-prompt.md | ||
| The design-tree.txt format is stack-agnostic — your prompt just needs | ||
| to describe how to convert it to your target framework. | ||
|
|
||
| IMAGE SCALE | ||
| --image-scale 2 PC/desktop (default) — @2x retina | ||
| --image-scale 3 Mobile — @3x retina | ||
| SVG vectors are scale-independent and always included. | ||
| `.trimStart()); | ||
| } | ||
|
|
||
| const DOCS_TOPICS: Record<string, () => void> = { | ||
| setup: printDocsSetup, | ||
| install: printDocsSetup, // alias | ||
| rules: printDocsRules, | ||
| config: printDocsConfig, | ||
| implement: printDocsImplement, | ||
| "visual-compare": printDocsVisualCompare, | ||
|
Comment on lines
319
to
325
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the invalid-topic hint for the new topic. Adding 🤖 Prompt for AI Agents |
||
| "design-tree": printDocsDesignTree, | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.