@pedroab0/skills 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +194 -2
- package/bin/cli.js +748 -0
- package/figma-extractor/README.md +180 -0
- package/figma-extractor/SKILL.md +199 -0
- package/figma-extractor/demo/desktop_home.json +2434 -0
- package/figma-extractor/demo/dt_money_desktop_home.png +0 -0
- package/figma-extractor/demo/dt_money_preview.png +0 -0
- package/figma-extractor/demo/dt_money_selection.json +472 -0
- package/figma-extractor/demo/index.html +188 -0
- package/figma-extractor/demo/style.css +360 -0
- package/figma-extractor/figma-plugin/README.md +81 -0
- package/figma-extractor/figma-plugin/assets/cover-1920.png +0 -0
- package/figma-extractor/figma-plugin/assets/cover.jpg +0 -0
- package/figma-extractor/figma-plugin/assets/cover.png +0 -0
- package/figma-extractor/figma-plugin/assets/icon-128.png +0 -0
- package/figma-extractor/figma-plugin/assets/icon.png +0 -0
- package/figma-extractor/figma-plugin/code.js +407 -0
- package/figma-extractor/figma-plugin/manifest.json +16 -0
- package/figma-extractor/figma-plugin/ui.html +470 -0
- package/figma-extractor/scripts/fetch_figma.js +1314 -0
- package/figma-extractor/scripts/test_fetch_figma.js +601 -0
- package/figma-node-builder/README.md +107 -0
- package/figma-node-builder/SKILL.md +113 -0
- package/figma-node-builder/scripts/inspect_spec.js +514 -0
- package/figma-node-builder/scripts/test_inspect_spec.js +148 -0
- package/figma-to-code/README.md +160 -0
- package/figma-to-code/SKILL.md +211 -0
- package/figma-to-code/scripts/fetch_figma.js +1251 -0
- package/figma-to-code/scripts/test_fetch_figma.js +581 -0
- package/package.json +40 -4
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Figma Extractor
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.figma.com/community/plugin/1691244420692136789/figma-node-json-extractor"><img src="https://img.shields.io/badge/Figma_Community-Plugin-000000?style=flat&logo=figma&logoColor=white" alt="Figma Community Plugin" /></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@pedroab0/skills"><img src="https://img.shields.io/npm/v/@pedroab0/skills.svg?label=@pedroab0/skills" alt="npm package" /></a>
|
|
6
|
+
<a href="../LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT" /></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
A lightweight, zero-dependency Node.js CLI tool and agent skill that extracts design node metadata, component hierarchies, design tokens, and rendered preview images from Figma via the Figma REST API into `./.specs/`.
|
|
10
|
+
|
|
11
|
+
This skill serves as the **Specification Ingestion Layer** in a **Spec-Driven Development (SDD)** workflow.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Why Replace Figma MCP?
|
|
16
|
+
|
|
17
|
+
Standard Figma MCP (Model Context Protocol) servers are often too heavy for coding tasks. They flood your model with massive, unpruned design files and lack awareness of your design system.
|
|
18
|
+
|
|
19
|
+
### Comparison Table
|
|
20
|
+
|
|
21
|
+
| Feature | Standard Figma MCP | Figma Extractor Skill |
|
|
22
|
+
| :--- | :--- | :--- |
|
|
23
|
+
| **Token Usage** | Very heavy (50k to 150k+ tokens). Dumps raw vector points, animation curves, and internal metadata. | Ultra-compact (2k to 8k tokens). Strips out 90% of noise, keeping only layout and styles. |
|
|
24
|
+
| **Design System** | Returns raw values (hex color codes, exact pixel sizes). | Resolves Figma Variables into semantic tokens (primary colors, spacing scale, corner radii). |
|
|
25
|
+
| **Component Reuse** | Dumps every internal layer of a component, causing the AI to recreate it as generic divs. | Collapses component layers into clean props, encouraging the AI to reuse your existing components. |
|
|
26
|
+
| **Visual Previews** | Requires multiple slow round-trips to find and download images. | Single step: extracts the layout and downloads a rendered image preview at the same time. |
|
|
27
|
+
| **Reliability** | Requires a persistent background daemon that can crash, hang, or disconnect. | Zero background processes. Runs on-demand as a lightweight script with zero dependencies. |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## When to Still Use Figma MCP
|
|
32
|
+
|
|
33
|
+
A standard MCP server is only better if:
|
|
34
|
+
- You need to **write** to Figma (create layers, post comments).
|
|
35
|
+
- Your AI environment completely blocks command-line tools.
|
|
36
|
+
- Your organization enforces interactive browser-based OAuth logins instead of access tokens.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## How It Works in SDD
|
|
41
|
+
|
|
42
|
+
The extraction happens in a simple 5-step pipeline:
|
|
43
|
+
|
|
44
|
+
1. **Authentication & Link Parsing**
|
|
45
|
+
Reads your Figma access token and automatically parses any Figma link (file, frame, or specific component).
|
|
46
|
+
|
|
47
|
+
2. **Design Token Collection**
|
|
48
|
+
Queries Figma's local variables first to build a clean dictionary of your design tokens (colors, spacing scale, border radii, and typography).
|
|
49
|
+
|
|
50
|
+
3. **Targeted Retrieval**
|
|
51
|
+
Fetches only the specific frame or component from the Figma API instead of downloading the entire canvas.
|
|
52
|
+
|
|
53
|
+
4. **Smart Cleanup & Pruning**
|
|
54
|
+
- **Removes noise**: Discards vector bezier paths, render matrices, and prototyping data.
|
|
55
|
+
- **Preserves layout**: Keeps flex direction, alignment, gap, padding, dimensions, and typography.
|
|
56
|
+
- **Maps tokens**: Pairs raw values with their corresponding design token names.
|
|
57
|
+
- **Simplifies components**: Replaces complex internal sub-layers with a clean component name and ready-to-use props.
|
|
58
|
+
|
|
59
|
+
5. **Specification Delivery (`.specs/`)**
|
|
60
|
+
Saves the compact JSON specification (`.specs/<name>.json`) and optional rendered PNG preview (`.specs/<name>.png`).
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## How to Use the Skill
|
|
65
|
+
|
|
66
|
+
### 1. Prerequisites: Create & Set Your Figma Token
|
|
67
|
+
|
|
68
|
+
#### How to Create the Token:
|
|
69
|
+
1. In Figma, click your profile avatar and select **Settings**.
|
|
70
|
+
2. Select the **Security** tab and scroll to **Personal access tokens**.
|
|
71
|
+
3. Click **Generate new token**, enter a description (e.g., `ai-extractor`), and ensure read access is enabled (`File content: Read`, `Variables: Read`).
|
|
72
|
+
4. Copy the generated token (starts with `figd_`).
|
|
73
|
+
|
|
74
|
+
#### How to Set the Token in Terminal:
|
|
75
|
+
Choose one of the following terminal commands:
|
|
76
|
+
|
|
77
|
+
- **Add to your project `.env` file (Recommended)**:
|
|
78
|
+
```bash
|
|
79
|
+
echo 'FIGMA_ACCESS_TOKEN="figd_your_token_here"' >> .env
|
|
80
|
+
```
|
|
81
|
+
- **Set for current terminal session only**:
|
|
82
|
+
```bash
|
|
83
|
+
export FIGMA_ACCESS_TOKEN="figd_your_token_here"
|
|
84
|
+
```
|
|
85
|
+
- **Persist globally across all terminal sessions (`~/.zshrc`)**:
|
|
86
|
+
```bash
|
|
87
|
+
echo 'export FIGMA_ACCESS_TOKEN="figd_your_token_here"' >> ~/.zshrc && source ~/.zshrc
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
*(Optional: If behind a corporate proxy with self-signed SSL certificates, run `echo 'FIGMA_IGNORE_SSL=true' >> .env`).*
|
|
91
|
+
|
|
92
|
+
### 2. Invoking via AI Coding Agent (Planning / Spec Phase)
|
|
93
|
+
|
|
94
|
+
In an SDD workflow, prompt the agent during the planning phase:
|
|
95
|
+
> *"Extract the design specification for this Figma frame into `.specs/`: `<FigmaURL>`"*
|
|
96
|
+
|
|
97
|
+
The agent runs `fetch_figma.js`, generates the `.specs/` artifacts, and reports the extracted tokens and components without modifying any application code.
|
|
98
|
+
|
|
99
|
+
### 3. Manual Command Formats
|
|
100
|
+
|
|
101
|
+
You can also run the script directly from your terminal:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Recommended: Atomic extraction (writes ./.specs/card.json - 1 Tier 1 call)
|
|
105
|
+
node figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec card
|
|
106
|
+
|
|
107
|
+
# Optional: With companion preview image (writes .json & .png - 2 Tier 1 calls)
|
|
108
|
+
node figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec card -i
|
|
109
|
+
|
|
110
|
+
# Atomic extraction with shallow instances (collapses component internals into props)
|
|
111
|
+
node figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec card --shallow-instances
|
|
112
|
+
|
|
113
|
+
# Extract only design tokens dictionary (colors, spacing, radii)
|
|
114
|
+
node figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --tokens > ./.specs/tokens.json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Available Flags
|
|
120
|
+
|
|
121
|
+
| Flag | Shorthand | Description |
|
|
122
|
+
| :--- | :--- | :--- |
|
|
123
|
+
| `--spec <name>` | | **Atomic SDD mode**: Saves `./.specs/<name>.json` (add `-i` to also download preview PNG). |
|
|
124
|
+
| `--image`, `--download-image` | `-i` | Download and save rendered preview image from Figma (Tier 1 call; optional). |
|
|
125
|
+
| `--image-path <path>` | `-o <path>` | Custom destination path for saved preview image (e.g., `./.specs/card.png`). |
|
|
126
|
+
| `--tokens`, `--variables` | | Export only the file's design token dictionary (colors, spacing, radii). |
|
|
127
|
+
| `--shallow-instances` | | Collapse internal layers of component instances into clean props. |
|
|
128
|
+
| `--include-tokens` | | Bundle complete design tokens dictionary alongside the node tree. |
|
|
129
|
+
| `--include-ids` | | Retain Figma internal node IDs in the returned output. |
|
|
130
|
+
| `--pretty` | | Format output with readable 2-space indentation (default is compact single-line JSON). |
|
|
131
|
+
| `--raw` | | Return full unpruned Figma API response without filtering. |
|
|
132
|
+
| `--depth <number>` | | Limit node tree traversal depth (e.g., `--depth 2` for top-level layout only). |
|
|
133
|
+
| `--scale <1\|2\|3\|4>` | | Multiplier for rendered image resolution (default: `2`). |
|
|
134
|
+
| `--format <png\|svg\|jpg>` | | Image format for downloaded preview (default: `png`). |
|
|
135
|
+
| `--no-variables` | | Skip querying local variables to speed up extraction. |
|
|
136
|
+
| `--help` | `-h` | Display command usage and available flags. |
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Zero-API Companion: Figma Node JSON Extractor (Figma Plugin)
|
|
141
|
+
|
|
142
|
+
<p align="center">
|
|
143
|
+
<img src="./figma-plugin/assets/icon.png" alt="Figma Node JSON Extractor" width="200" />
|
|
144
|
+
</p>
|
|
145
|
+
|
|
146
|
+
For developers who prefer exporting specifications directly from Figma Desktop without configuring API access tokens or consuming REST API quotas:
|
|
147
|
+
|
|
148
|
+
* **Published Figma Plugin (Recommended)**: Install [**Figma Node JSON Extractor** on Figma Community](https://www.figma.com/community/plugin/1691244420692136789/figma-node-json-extractor) directly, or search for it under Figma Plugins.
|
|
149
|
+
* **Manual Local Installation (Local / Offline Backup)**: In Figma Desktop, go to **Plugins** $\rightarrow$ **Development** $\rightarrow$ **Import plugin from manifest...** and select `manifest.json` from your installed skills directory:
|
|
150
|
+
* **Claude Code**: `~/.claude/skills/figma-extractor/figma-plugin/manifest.json`
|
|
151
|
+
* **Google Antigravity**: `~/.gemini/config/skills/figma-extractor/figma-plugin/manifest.json`
|
|
152
|
+
* **OpenCode**: `~/.config/opencode/skills/figma-extractor/figma-plugin/manifest.json`
|
|
153
|
+
* **Cloned Git Repo**: `<repo-root>/figma-extractor/figma-plugin/manifest.json`
|
|
154
|
+
* **Export Options**: Select any frame or component, then click:
|
|
155
|
+
* **📋 Copy Node JSON**: Copies the clean AST specification to your clipboard.
|
|
156
|
+
* **💾 .json**: Downloads `<name>.json`.
|
|
157
|
+
* **🖼 .png**: Downloads `<name>.png` (2x preview).
|
|
158
|
+
* **📦 Both (.zip)**: Downloads `<name>.specs.zip` containing both files.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Available Resources
|
|
163
|
+
|
|
164
|
+
The skill includes the following resources:
|
|
165
|
+
|
|
166
|
+
- **Agent Instruction Guide (`SKILL.md`)**: The core skill definition read by AI agents containing workflow triggers and operational boundaries (spec ingestion only).
|
|
167
|
+
- **Core Extraction Script (`scripts/fetch_figma.js`)**: The standalone, zero-dependency Node.js script that interfaces with the Figma REST API, resolves tokens, prunes the AST, and downloads preview images.
|
|
168
|
+
- **Unit Test Suite (`scripts/test_fetch_figma.js`)**: A suite of 40 automated unit tests verifying URL parsing, token formatting, component prop cleaning, rate-limit gates, and node pruning without requiring network access.
|
|
169
|
+
- **Companion Figma Plugin (`figma-plugin/`)**: Zero-API desktop exporter for extracting AST and previews directly inside Figma Desktop.
|
|
170
|
+
- **Reference Documentation (`README.md`)**: This guide explaining architecture, comparison, and operational flags.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## The SDD Specification Contract (`.specs/`)
|
|
175
|
+
|
|
176
|
+
`figma-extractor` strictly separates **Specification** from **Implementation**:
|
|
177
|
+
* **`.specs/<name>.json`**: The structural AST specification containing bounds, layout directions, paddings, gaps, resolved token names, and component variant props.
|
|
178
|
+
* **`.specs/<name>.png`**: The visual raster reference rendered directly by Figma (optional).
|
|
179
|
+
|
|
180
|
+
This contract is subsequently consumed during the implementation phase by human developers or specialized builder skills like [`figma-node-builder`](../figma-node-builder).
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: figma-extractor
|
|
3
|
+
description: 'Extract compact JSON node hierarchies, design tokens, component instance props, and automated preview images from Figma using the Figma REST API. Trigger this skill during the planning or specification phase whenever a Figma link is provided or when the user asks to inspect, extract, or sync design specifications and tokens from Figma into .specs/. This skill strictly produces specification artifacts and does not modify application code.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Figma Extractor Skill (SDD Spec Ingest)
|
|
7
|
+
|
|
8
|
+
Extract design node metadata, component hierarchies, design tokens/variables, and rendered preview images directly from Figma via the Figma REST API into structured specification artifacts (`.specs/`).
|
|
9
|
+
|
|
10
|
+
This skill serves as the **Specification Ingestion Layer** in a **Spec-Driven Development (SDD)** workflow. It is **Design-System Aware**, high-performance, token-efficient, and has zero external dependencies.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Operational Boundary: Spec Ingestion Only
|
|
15
|
+
|
|
16
|
+
* **Specification Artifacts Only**: This skill strictly outputs machine-readable design specifications (`.specs/<name>.json`) and visual references (`.specs/<name>.png`).
|
|
17
|
+
* **Zero Application Code Changes**: Do **NOT** create, edit, or modify application source code (`.tsx`, `.vue`, `.html`, `.css`, etc.) while executing this skill.
|
|
18
|
+
* **Hand-off to Implementation**: Once specifications are generated in `./.specs/`, present a summary of the extracted tokens, components, and layout bounds. The implementation phase is handled separately by the developer or a downstream builder skill (such as `figma-node-builder`).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Strict Guardrails: No Browser Scraping / Automation
|
|
23
|
+
|
|
24
|
+
> [!CAUTION]
|
|
25
|
+
> **NEVER use browser tools (Playwright, Puppeteer, Chrome DevTools, `browser_navigate`, `read_browser_page`) on Figma URLs.**
|
|
26
|
+
>
|
|
27
|
+
> 1. **Figma Canvas is WebGL/Wasm**: Figma renders design canvas elements inside an HTML5 `<canvas>` via WebAssembly. There are NO inspectable HTML DOM elements for frames, layers, texts, or styles. Browser automation cannot extract Figma nodes or properties.
|
|
28
|
+
> 2. **Never search `/Applications` for browsers**: Do not search for installed browser binaries or run browser automation scripts.
|
|
29
|
+
> 3. **API Errors Are Final**: If `fetch_figma.js` returns an API error (e.g., 401 Unauthorized, 403 Forbidden, or 429 Rate Limited), **report the error directly to the user**. Guide them to check their `FIGMA_ACCESS_TOKEN`, permissions, or wait out rate limits. Do NOT attempt browser scraping fallbacks.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Built-in Rate-Limit Gate & Circuit Breaker
|
|
34
|
+
|
|
35
|
+
To protect your Figma file quota and prevent lockout penalties, `fetch_figma.js` enforces an automatic safety gate:
|
|
36
|
+
* **Max 5 requests per minute** per file key (sliding window limit).
|
|
37
|
+
* **2.5s inter-request pacing** between consecutive requests.
|
|
38
|
+
* **Persistent Circuit Breaker**: If Figma returns HTTP 429, the script records the lockout time locally in `~/.figma_ratelimit.json`. All future calls to that file key are **immediately blocked with zero network traffic**, preventing Figma from extending the lockout penalty.
|
|
39
|
+
|
|
40
|
+
### Agent Behavioral Rules (Zero-Hammer Protocol)
|
|
41
|
+
1. **Single-Shot Execution**: Run `fetch_figma.js` **once** per target frame or component.
|
|
42
|
+
2. **Never Retry on Failure**: If `fetch_figma.js` returns an error, **DO NOT retry in a loop**. Report the error directly to the user.
|
|
43
|
+
3. **Handling `FIGMA_CIRCUIT_BREAKER_ACTIVE`**: If the circuit breaker trips, inform the user that the file key is on cooldown, and suggest duplicating the file in Figma Drafts (Right-click $\rightarrow$ **Duplicate**) to get a fresh URL.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Prerequisites
|
|
48
|
+
|
|
49
|
+
A Figma Access Token (Personal Access Token or OAuth Token) is required.
|
|
50
|
+
|
|
51
|
+
Configure it using either:
|
|
52
|
+
1. **Environment Variable**: `export FIGMA_ACCESS_TOKEN="figd_your_token_here"` or `export FIGMA_TOKEN="..."`
|
|
53
|
+
2. **Workspace `.env` File**:
|
|
54
|
+
```env
|
|
55
|
+
FIGMA_ACCESS_TOKEN=figd_your_token_here
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Corporate Proxy & SSL Certificates
|
|
59
|
+
If you are behind a corporate proxy or firewall with self-signed SSL certificates, enable SSL verification bypass:
|
|
60
|
+
```env
|
|
61
|
+
FIGMA_IGNORE_SSL=true
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Tier 1 Quota Conservation: AST-Only by Default
|
|
67
|
+
|
|
68
|
+
> [!IMPORTANT]
|
|
69
|
+
> **Figma Starter plans enforce a strict limit of 20 Tier 1 requests/month.**
|
|
70
|
+
> Both `GET /v1/files/:key/nodes` and `GET /v1/images/:key` count as Tier 1 endpoints.
|
|
71
|
+
>
|
|
72
|
+
> 1. **Default to AST-only extraction**: Running `--spec <name>` without `-i` consumes **only 1 Tier 1 call**. The JSON AST contains 100% of layout rules (flexbox, padding, gap), dimensions, hex colors, corner radii, and text content needed for code generation.
|
|
73
|
+
> 2. **DO NOT pass `-i` / `--image` by default**: Only add `-i` if the user explicitly requests downloading a visual preview screenshot.
|
|
74
|
+
> 3. **Reuse existing specs**: If `.specs/<name>.json` exists, reuse it with **0 API calls**.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Agent Execution Instructions
|
|
79
|
+
|
|
80
|
+
To extract a Figma frame or component as a specification artifact, run `fetch_figma.js` from the skill's scripts directory:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Recommended: Atomic extraction (writes ./.specs/<name>.json - 1 Tier 1 call)
|
|
84
|
+
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>" --spec <name>
|
|
85
|
+
|
|
86
|
+
# Optional: With companion preview image (writes .json and .png - 2 Tier 1 calls)
|
|
87
|
+
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>" --spec <name> -i
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Script Path Resolution**:
|
|
91
|
+
- **Global Antigravity install**: `node ~/.gemini/config/skills/figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec <name>`
|
|
92
|
+
- **Global Claude Code install**: `node ~/.claude/skills/figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec <name>`
|
|
93
|
+
- **Project local install**: `node figma-extractor/scripts/fetch_figma.js "<FigmaURL>" --spec <name>`
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Usage & Command Formats
|
|
98
|
+
|
|
99
|
+
### 1. Atomic Spec Extraction (Recommended SDD Workflow)
|
|
100
|
+
|
|
101
|
+
Extract node metadata directly into `./.specs/`:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Atomic AST extraction (1 Tier 1 call - recommended)
|
|
105
|
+
node figma-extractor/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" --spec card
|
|
106
|
+
|
|
107
|
+
# Optional: With rendered preview image (2 Tier 1 calls)
|
|
108
|
+
node figma-extractor/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" --spec card -i
|
|
109
|
+
|
|
110
|
+
# Shallow instances mode (collapses internal component layers into clean props)
|
|
111
|
+
node figma-extractor/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" --spec card --shallow-instances
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 2. Design Tokens Dictionary Mode
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Export only the file's design token dictionary (colors, spacing, radii)
|
|
118
|
+
node figma-extractor/scripts/fetch_figma.js "https://www.figma.com/design/:fileKey/:name" --tokens > ./.specs/tokens.json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 3. CLI Flags Reference
|
|
122
|
+
|
|
123
|
+
| Flag | Shorthand | Description |
|
|
124
|
+
| :--- | :--- | :--- |
|
|
125
|
+
| `--spec <name>` | | **Atomic SDD mode**: Saves `./.specs/<name>.json` (add `-i` to also download preview PNG). |
|
|
126
|
+
| `--image`, `--download-image` | `-i` | Download and save rendered preview image from Figma (Tier 1 call; optional). |
|
|
127
|
+
| `--image-path <path>` | `-o <path>` | Destination path for saved preview image (e.g. `./.specs/preview.png`). |
|
|
128
|
+
| `--tokens`, `--variables` | | Output only the design token dictionary (colors, spacing, radii). |
|
|
129
|
+
| `--shallow-instances` | | Collapse internal sub-layers of component instances into clean props. |
|
|
130
|
+
| `--pretty` | | Pretty-print JSON with 2-space indentation (default is compact single-line JSON). |
|
|
131
|
+
| `--include-tokens` | | Include full design tokens dictionary alongside node AST. |
|
|
132
|
+
| `--include-ids` | | Retain internal Figma node IDs on each node in the tree. |
|
|
133
|
+
| `--raw` | | Return full, unpruned raw Figma API AST. |
|
|
134
|
+
| `--depth <number>` | | Limit node tree traversal depth (e.g. `--depth 2` for top-level overview). |
|
|
135
|
+
| `--scale <1\|2\|3\|4>` | | Render resolution multiplier for preview images (default: `2`). |
|
|
136
|
+
| `--format <png\|svg\|jpg>` | | Rendered image file format (default: `png`). |
|
|
137
|
+
| `--no-variables` | | Skip querying `/variables/local`. |
|
|
138
|
+
| `--help` | `-h` | Show help message. |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Output Spec Structure
|
|
143
|
+
|
|
144
|
+
### 1. Resolved Design Tokens
|
|
145
|
+
When a layer uses Figma variables (design tokens), the extractor attaches semantic token names alongside computed fallback values:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"name": "Card Container",
|
|
150
|
+
"type": "FRAME",
|
|
151
|
+
"layoutMode": "VERTICAL",
|
|
152
|
+
"padding": { "top": 16, "right": 16, "bottom": 16, "left": 16 },
|
|
153
|
+
"paddingToken": "spacing/md",
|
|
154
|
+
"itemSpacing": 12,
|
|
155
|
+
"itemSpacingToken": "spacing/sm",
|
|
156
|
+
"cornerRadius": 8,
|
|
157
|
+
"cornerRadiusToken": "radii/lg",
|
|
158
|
+
"fills": [
|
|
159
|
+
{
|
|
160
|
+
"type": "SOLID",
|
|
161
|
+
"color": "#1877F2",
|
|
162
|
+
"token": "colors/brand/primary"
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 2. Normalized Component Instances & Props
|
|
169
|
+
When an `INSTANCE` node is present, internal property hashes are converted into clean JavaScript props and linked to the master component name:
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"name": "Submit Button",
|
|
174
|
+
"type": "INSTANCE",
|
|
175
|
+
"component": {
|
|
176
|
+
"name": "Button",
|
|
177
|
+
"variant": "Variant=Primary, Size=Large"
|
|
178
|
+
},
|
|
179
|
+
"props": {
|
|
180
|
+
"variant": "Primary",
|
|
181
|
+
"size": "Large",
|
|
182
|
+
"hasIcon": true,
|
|
183
|
+
"label": "Confirm Order"
|
|
184
|
+
},
|
|
185
|
+
"bounds": { "width": 140, "height": 44 }
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Error Handling & Troubleshooting
|
|
192
|
+
|
|
193
|
+
- **Token Expired / Missing (`FIGMA_TOKEN_EXPIRED_OR_INVALID` / `isTokenExpiredOrInvalid`)**:
|
|
194
|
+
- Alert the user that their Figma access token is missing, invalid, or expired.
|
|
195
|
+
- Instruct the user to create a token in **Figma Settings → Personal Access Tokens** and export `FIGMA_ACCESS_TOKEN=your_token` or update `.env`.
|
|
196
|
+
- **Node Not Found**:
|
|
197
|
+
- Alert the user that the node ID could not be found in the specified file.
|
|
198
|
+
- **Rate Limited (`FIGMA_RATE_LIMIT_EXCEEDED` / `FIGMA_CIRCUIT_BREAKER_ACTIVE`)**:
|
|
199
|
+
- Figma REST API has per-minute and monthly rate limits on Starter plans. If quota is exhausted or circuit breaker trips, inform the user they can export the specification directly via the companion **Figma Node JSON Extractor** desktop plugin (available on [Figma Community](https://www.figma.com/community/plugin/1691244420692136789/figma-node-json-extractor)) into `./.specs/<name>.json`.
|