@createlex/figma-swiftui-mcp 1.0.0
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/README.md +384 -0
- package/bin/figma-swiftui-mcp.js +81 -0
- package/companion/bridge-server.cjs +599 -0
- package/companion/createlex-auth.cjs +364 -0
- package/companion/login.mjs +190 -0
- package/companion/mcp-server.mjs +788 -0
- package/companion/package.json +17 -0
- package/companion/server.js +64 -0
- package/companion/xcode-writer.cjs +429 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# Figma to SwiftUI
|
|
2
|
+
|
|
3
|
+
A Figma plugin and local MCP toolchain for generating SwiftUI code directly from Figma designs. You can export a ready-to-import Xcode package from the plugin UI, or run an MCP-first workflow that inspects the live Figma session and writes generated SwiftUI directly into Xcode. In production, the local MCP runtime is authenticated against CreateLex and only starts for paid subscribers.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This project consists of four main components:
|
|
8
|
+
|
|
9
|
+
- **Figma Plugin** (`code.ts`): Runs in Figma, converts selected design nodes to SwiftUI code, exports images, and can download an Xcode-ready package from the UI
|
|
10
|
+
- **Local Bridge Server** (`companion/bridge-server.cjs`): Runs locally on port 7765, powers the bridge used by both the plugin and agent clients, and writes generated files into a dedicated `FigmaGenerated` area inside your Xcode source folder
|
|
11
|
+
- **Bridge Relay** (`companion/bridge-server.cjs` WebSocket path `/bridge`): Relays structured Figma data between the live plugin UI and agent clients
|
|
12
|
+
- **MCP Server** (`companion/mcp-server.mjs`): The main runtime entrypoint. Starts the localhost bridge automatically, exposes stdio MCP tools, and writes directly into Xcode
|
|
13
|
+
|
|
14
|
+
## Architecture
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
┌──────────────────────────────┐
|
|
18
|
+
│ MCP / Agent Client │
|
|
19
|
+
│ npx @createlex/figma-swiftui-mcp start │
|
|
20
|
+
└──────────────┬───────────────┘
|
|
21
|
+
│ stdio MCP
|
|
22
|
+
▼
|
|
23
|
+
MCP server boots localhost bridge
|
|
24
|
+
│
|
|
25
|
+
▼
|
|
26
|
+
ws://localhost:7765/bridge
|
|
27
|
+
▲
|
|
28
|
+
│
|
|
29
|
+
Figma UI ── pluginMessage ──> Plugin Code ── HTTP POST ──> Bridge Server ──> Xcode Project
|
|
30
|
+
│ │
|
|
31
|
+
└──────── bridge events ───────┘
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Prerequisites
|
|
35
|
+
|
|
36
|
+
- Figma account
|
|
37
|
+
- Xcode project
|
|
38
|
+
- Node.js (v18 or later) and npm for the MCP server, localhost bridge, or local plugin development
|
|
39
|
+
|
|
40
|
+
## Setup & Installation
|
|
41
|
+
|
|
42
|
+
### Production Install
|
|
43
|
+
|
|
44
|
+
Users do not need this repo checked out locally. The production flow is:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx @createlex/figma-swiftui-mcp login
|
|
48
|
+
npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or install it once globally:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install -g @createlex/figma-swiftui-mcp
|
|
55
|
+
figma-swiftui-mcp login
|
|
56
|
+
figma-swiftui-mcp start --project /path/to/MyApp/MyApp
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- `login` opens the CreateLex browser flow and writes `~/.createlex/auth.json`
|
|
60
|
+
- `start` boots the local MCP runtime and localhost bridge together
|
|
61
|
+
- the Figma plugin UI must stay open while you use MCP tools
|
|
62
|
+
|
|
63
|
+
### Development Setup
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cd figma-plugin-swiftui
|
|
67
|
+
npm install
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`npm install` now installs both the plugin dependencies and the local MCP runtime dependencies.
|
|
71
|
+
|
|
72
|
+
## Building
|
|
73
|
+
|
|
74
|
+
Compile the TypeScript plugin code to JavaScript:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Watch for changes during development:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm run watch
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This will continuously compile `code.ts` → `code.js` as you edit.
|
|
87
|
+
|
|
88
|
+
## Production Access Model
|
|
89
|
+
|
|
90
|
+
`figma-swiftui` is a local runtime, but it is not an offline-only product. The MCP process validates the current user against the CreateLex backend before it starts, and revalidates the session while it is running.
|
|
91
|
+
|
|
92
|
+
Production expectations:
|
|
93
|
+
|
|
94
|
+
- the MCP runtime runs locally on the developer machine
|
|
95
|
+
- the user must already be authenticated with CreateLex
|
|
96
|
+
- the user must have an active paid subscription
|
|
97
|
+
- if the subscription becomes invalid, the local runtime stops accepting bridge and MCP requests
|
|
98
|
+
- Supabase auth configuration lives on the backend / DigitalOcean environment, not inside the local MCP package
|
|
99
|
+
|
|
100
|
+
Before starting the production runtime:
|
|
101
|
+
|
|
102
|
+
1. Run `npx @createlex/figma-swiftui-mcp login` once.
|
|
103
|
+
2. Ensure the account has an active paid subscription.
|
|
104
|
+
3. Start the local runtime with `npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp`.
|
|
105
|
+
|
|
106
|
+
Environment overrides for development:
|
|
107
|
+
|
|
108
|
+
- `FIGMA_SWIFTUI_BYPASS_AUTH=true` bypasses the CreateLex subscription gate
|
|
109
|
+
- `CREATELEX_API_BASE_URL=https://your-domain/api` points validation at a different backend
|
|
110
|
+
- `CREATELEX_ACCESS_TOKEN=...` or `FIGMA_SWIFTUI_ACCESS_TOKEN=...` provides a token directly instead of reading `~/.createlex/auth.json`
|
|
111
|
+
|
|
112
|
+
## Running MCP + Bridge
|
|
113
|
+
|
|
114
|
+
The MCP server is the only runtime command. It starts the localhost bridge automatically, validates the current CreateLex subscriber session, and that bridge powers both the plugin's **Send to Xcode** button and the MCP tools. You do not need any local runtime for **Download Package**.
|
|
115
|
+
|
|
116
|
+
### Option 1: With project path specified
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx @createlex/figma-swiftui-mcp start --project /path/to/MyApp/MyApp
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Replace `/path/to/MyApp/MyApp` with the actual path to your Xcode project's source folder (the one containing your Swift files and `Assets.xcassets`).
|
|
123
|
+
|
|
124
|
+
The companion writes generated files into:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
{ProjectSource}/FigmaGenerated/Screens/
|
|
128
|
+
{ProjectSource}/FigmaGenerated/Components/
|
|
129
|
+
{ProjectSource}/FigmaGenerated/Manifest/
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Image sets still go into the existing `Assets.xcassets` for build compatibility.
|
|
133
|
+
|
|
134
|
+
### Option 2: Without project path (set from plugin UI)
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npx @createlex/figma-swiftui-mcp start
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Then set the project path through MCP or the Figma plugin UI after connecting.
|
|
141
|
+
|
|
142
|
+
The MCP process will also boot the bridge at `http://localhost:7765`.
|
|
143
|
+
|
|
144
|
+
Example output:
|
|
145
|
+
```
|
|
146
|
+
🚀 Figma SwiftUI bridge running at http://localhost:7765
|
|
147
|
+
📂 Project path: /Users/you/Projects/MyApp/MyApp
|
|
148
|
+
🌉 Bridge ready at ws://localhost:7765/bridge
|
|
149
|
+
MCP server running on stdio
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## MCP-First Workflow
|
|
153
|
+
|
|
154
|
+
If you are using Cursor, Codex, Claude Code, or another MCP-compatible local tool, this is the preferred workflow:
|
|
155
|
+
|
|
156
|
+
1. Start the local bridge and MCP server:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npx @createlex/figma-swiftui-mcp start
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
2. Keep the Figma plugin UI open so the bridge remains attached to the live Figma session.
|
|
163
|
+
3. From the MCP client:
|
|
164
|
+
- inspect the design structure
|
|
165
|
+
- generate SwiftUI
|
|
166
|
+
- write directly into the Xcode project
|
|
167
|
+
|
|
168
|
+
The MCP server persists the chosen Xcode source folder in:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
~/Library/Application Support/FigmaSwiftUICompanion/config.json
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
You can set that path once through MCP and then write repeatedly from the MCP client.
|
|
175
|
+
|
|
176
|
+
## High-Fidelity Workflow
|
|
177
|
+
|
|
178
|
+
For `figma-swiftui`, the local MCP runtime should be the primary inspection and generation tool. The most effective pattern is:
|
|
179
|
+
|
|
180
|
+
1. inspect the design with `figma-swiftui`
|
|
181
|
+
2. generate the first SwiftUI scaffold with `figma-swiftui`
|
|
182
|
+
3. refine assets and visual details with normal code editing
|
|
183
|
+
|
|
184
|
+
In practice:
|
|
185
|
+
- use `figma-swiftui` for raw facts like SVG-backed icons, nested node structure, screenshots, export planning, and exact generation diagnostics
|
|
186
|
+
- use `figma-swiftui` for the initial native SwiftUI scaffold and Xcode export
|
|
187
|
+
- use your project/file tools for final polish and wiring
|
|
188
|
+
|
|
189
|
+
You only need Figma Dev MCP as a fallback if you want broader Figma platform features outside the `figma-swiftui` workflow.
|
|
190
|
+
|
|
191
|
+
Detailed guidance is in [docs/HIGH_FIDELITY_WORKFLOW.md](/Users/alexkissijr/dev/GitHub/AiWebplatform/figma-plugin-swiftui/docs/HIGH_FIDELITY_WORKFLOW.md).
|
|
192
|
+
|
|
193
|
+
## Hybrid Production Model
|
|
194
|
+
|
|
195
|
+
For production, the recommended architecture is hybrid:
|
|
196
|
+
|
|
197
|
+
- hosted CreateLex services own entitlement checks, signed execution plans, and the long-term home of premium generation logic
|
|
198
|
+
- the local `figma-swiftui` runtime stays thin and handles only live Figma access plus local Xcode writes
|
|
199
|
+
|
|
200
|
+
The current hybrid foundation and migration path are documented in [docs/HYBRID_ARCHITECTURE.md](/Users/alexkissijr/dev/GitHub/AiWebplatform/figma-plugin-swiftui/docs/HYBRID_ARCHITECTURE.md).
|
|
201
|
+
|
|
202
|
+
Today, the first hosted generation path covers recognized single-screen `editable` semantic scaffolds. If the hosted service cannot confidently handle a screen yet, the local runtime falls back to the existing local generator.
|
|
203
|
+
|
|
204
|
+
## Agent Bridge and MCP Mode
|
|
205
|
+
|
|
206
|
+
The MCP runtime exposes the bridge endpoints used for agentic tooling:
|
|
207
|
+
|
|
208
|
+
- Raw WebSocket bridge: `ws://localhost:7765/bridge`
|
|
209
|
+
- Bridge status endpoint: `GET http://localhost:7765/bridge/info`
|
|
210
|
+
- MCP runtime: `npx @createlex/figma-swiftui-mcp start`
|
|
211
|
+
- Build plugin bundle: `npm run build`
|
|
212
|
+
- Bridge smoke test: `npm run test:bridge-smoke`
|
|
213
|
+
- High-fidelity inspection smoke: `npm run test:high-fidelity-smoke`
|
|
214
|
+
- Auth status tool: `auth_status`
|
|
215
|
+
|
|
216
|
+
The bridge only works when the Figma plugin UI is open and connected to the local companion. Once connected, agent clients can inspect document/page/selection data or call the same SwiftUI generation path used by the plugin UI.
|
|
217
|
+
|
|
218
|
+
Available bridge-backed MCP tools:
|
|
219
|
+
|
|
220
|
+
- `bridge_status`
|
|
221
|
+
- `get_project_path`
|
|
222
|
+
- `set_project_path`
|
|
223
|
+
- `get_metadata`
|
|
224
|
+
- `get_design_context`
|
|
225
|
+
- `get_screenshot`
|
|
226
|
+
- `export_svg`
|
|
227
|
+
- `get_document_summary`
|
|
228
|
+
- `get_viewport_context`
|
|
229
|
+
- `get_selection_snapshot`
|
|
230
|
+
- `get_page_snapshot`
|
|
231
|
+
- `get_node_snapshot`
|
|
232
|
+
- `find_nodes`
|
|
233
|
+
- `dump_tree`
|
|
234
|
+
- `get_asset_export_plan`
|
|
235
|
+
- `extract_reusable_components`
|
|
236
|
+
- `write_svg_to_xcode`
|
|
237
|
+
- `generate_swiftui`
|
|
238
|
+
- `analyze_generation`
|
|
239
|
+
- `write_generated_swiftui_to_xcode`
|
|
240
|
+
- `write_selection_to_xcode`
|
|
241
|
+
|
|
242
|
+
## Using the Plugin
|
|
243
|
+
|
|
244
|
+
### Loading the Plugin in Figma
|
|
245
|
+
|
|
246
|
+
1. Open Figma
|
|
247
|
+
2. Go to **Plugins** → **Create new plugin**
|
|
248
|
+
3. Select **Link existing plugin** and point to `manifest.json` in this directory
|
|
249
|
+
4. Alternatively, use the Figma dashboard to import this directory as a plugin
|
|
250
|
+
|
|
251
|
+
### Using the Plugin
|
|
252
|
+
|
|
253
|
+
1. Select a component or frame in Figma
|
|
254
|
+
2. Run the plugin (Plugins menu → Figma to SwiftUI)
|
|
255
|
+
3. A UI panel opens with the SwiftUI export controls.
|
|
256
|
+
4. Pick one export path:
|
|
257
|
+
- **Download Package** exports a zip containing `{StructName}.swift` plus an `Assets.xcassets` payload. This path does not require any local server.
|
|
258
|
+
- **Copy** copies the generated SwiftUI if you only want the code.
|
|
259
|
+
5. In the Xcode sync panel:
|
|
260
|
+
- **Choose Folder** opens a native folder picker so you can select the Xcode project source folder
|
|
261
|
+
- **Send to Xcode** writes the generated Swift file into `FigmaGenerated/Screens`, updates `FigmaGenerated/Manifest`, and writes exported images into the project's existing `Assets.xcassets`
|
|
262
|
+
6. If the local runtime is running and authorized, the generated code and images can be written directly into your Xcode project
|
|
263
|
+
|
|
264
|
+
### MCP-Only Xcode Sync
|
|
265
|
+
|
|
266
|
+
If you want to drive the whole sync from MCP:
|
|
267
|
+
|
|
268
|
+
1. Start the MCP runtime.
|
|
269
|
+
2. Keep the plugin UI open in Figma.
|
|
270
|
+
3. Call `set_project_path` once.
|
|
271
|
+
4. Call `write_selection_to_xcode` to generate from the live selection and write directly into Xcode.
|
|
272
|
+
|
|
273
|
+
### Environment Setup
|
|
274
|
+
|
|
275
|
+
The plugin looks for the local bridge at `http://localhost:7765`. Ensure:
|
|
276
|
+
- `npx @createlex/figma-swiftui-mcp start` is running before using **Send to Xcode**
|
|
277
|
+
- Your Xcode project path is set (either via `--project` flag or the plugin UI)
|
|
278
|
+
- If you are using **Download Package**, no local runtime is required
|
|
279
|
+
- If you want to use MCP or a raw WebSocket client, keep the plugin UI open so the bridge stays attached to a live Figma session
|
|
280
|
+
|
|
281
|
+
## Project Structure
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
figma-plugin-swiftui/
|
|
285
|
+
├── README.md # This file
|
|
286
|
+
├── package.json # Plugin dependencies (TypeScript)
|
|
287
|
+
├── tsconfig.json # TypeScript configuration
|
|
288
|
+
├── manifest.json # Figma plugin manifest
|
|
289
|
+
├── code.ts # Plugin source code (TypeScript)
|
|
290
|
+
├── code.js # Compiled plugin code (generated)
|
|
291
|
+
├── ui.html # Plugin UI (HTML/CSS/JS)
|
|
292
|
+
│
|
|
293
|
+
└── companion/
|
|
294
|
+
├── package.json # Companion + MCP dependencies
|
|
295
|
+
├── bridge-server.cjs # HTTP server + WebSocket bridge relay
|
|
296
|
+
├── server.js # Thin bridge-only wrapper (debug/legacy)
|
|
297
|
+
├── mcp-server.mjs # stdio MCP entrypoint that boots the bridge
|
|
298
|
+
├── xcode-writer.cjs # Shared Xcode write/layout logic
|
|
299
|
+
└── node_modules/ # Dependencies
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Development
|
|
303
|
+
|
|
304
|
+
### Editing the Plugin
|
|
305
|
+
|
|
306
|
+
1. Edit `code.ts` (the main plugin logic)
|
|
307
|
+
2. Run `npm run watch` to auto-compile on save
|
|
308
|
+
3. The compiled `code.js` is what Figma actually runs
|
|
309
|
+
|
|
310
|
+
### Editing the UI
|
|
311
|
+
|
|
312
|
+
Edit `ui.html` directly. It's loaded by the plugin via `figma.showUI()`.
|
|
313
|
+
|
|
314
|
+
### Testing the Runtime
|
|
315
|
+
|
|
316
|
+
The server has two main endpoints:
|
|
317
|
+
|
|
318
|
+
- `GET /ping` – Health check, returns project path status
|
|
319
|
+
- `GET /bridge/info` – Bridge health/status, reports whether a live plugin session is attached
|
|
320
|
+
- `POST /set-project` – Saves a manually entered project path after validating it exists
|
|
321
|
+
- `POST /choose-project` – Opens a native macOS folder picker and saves the selected path
|
|
322
|
+
- `POST /write` – Receives `{ code, structName, images, customPath }`, writes `FigmaGenerated/Screens/{StructName}.swift`, updates `FigmaGenerated/Manifest`, and writes images into `Assets.xcassets`
|
|
323
|
+
- `WS /bridge` – Relays structured Figma requests/responses/events between the plugin UI and external clients
|
|
324
|
+
|
|
325
|
+
Example POST to test:
|
|
326
|
+
```bash
|
|
327
|
+
curl -X POST http://localhost:7765/write \
|
|
328
|
+
-H "Content-Type: application/json" \
|
|
329
|
+
-d '{
|
|
330
|
+
"code": "struct MyView: View { var body: some View { Text(\"Hello\") } }",
|
|
331
|
+
"structName": "MyView"
|
|
332
|
+
}'
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Troubleshooting
|
|
336
|
+
|
|
337
|
+
### Server not reachable from plugin
|
|
338
|
+
|
|
339
|
+
- This only affects **Send to Xcode**. The **Download Package** flow still works without the MCP runtime.
|
|
340
|
+
- Ensure the MCP runtime is running: `npx @createlex/figma-swiftui-mcp start`
|
|
341
|
+
- Check that it's listening on `http://localhost:7765`
|
|
342
|
+
- Check the plugin's `manifest.json` `allowedDomains` includes both `http://localhost:7765` and `ws://localhost:7765`
|
|
343
|
+
|
|
344
|
+
### Bridge or MCP shows no live Figma data
|
|
345
|
+
|
|
346
|
+
- The MCP runtime can be running while the bridge is still disconnected from Figma. Open the plugin UI and leave it open.
|
|
347
|
+
- Check `http://localhost:7765/bridge/info` and confirm `pluginConnected: true`
|
|
348
|
+
- Restart the plugin UI if the bridge stays in `bridge waiting`
|
|
349
|
+
- Start the MCP runtime with `npx @createlex/figma-swiftui-mcp start`
|
|
350
|
+
|
|
351
|
+
### MCP runtime exits immediately
|
|
352
|
+
|
|
353
|
+
- Run `npx @createlex/figma-swiftui-mcp login` first so `~/.createlex/auth.json` exists
|
|
354
|
+
- Confirm the account has an active paid subscription
|
|
355
|
+
- If needed, check `auth_status` from the MCP client after startup
|
|
356
|
+
- In local development only, use `FIGMA_SWIFTUI_BYPASS_AUTH=true` to bypass the subscription gate
|
|
357
|
+
|
|
358
|
+
### Project path not recognized
|
|
359
|
+
|
|
360
|
+
- Verify the path points to the folder containing `.swift` files and `Assets.xcassets`
|
|
361
|
+
- The server will create `FigmaGenerated/` and `Assets.xcassets` if they don't exist
|
|
362
|
+
- Check filesystem permissions
|
|
363
|
+
|
|
364
|
+
### TypeScript compilation errors
|
|
365
|
+
|
|
366
|
+
- Run `npm install` to ensure all dependencies are installed
|
|
367
|
+
- Delete `node_modules` and reinstall if issues persist: `rm -rf node_modules && npm install`
|
|
368
|
+
|
|
369
|
+
## Dependencies
|
|
370
|
+
|
|
371
|
+
### Plugin
|
|
372
|
+
- `@figma/plugin-typings` – Type definitions for Figma plugin API
|
|
373
|
+
- `typescript` – TypeScript compiler
|
|
374
|
+
|
|
375
|
+
### MCP Runtime
|
|
376
|
+
- `express` – Web server framework
|
|
377
|
+
- `cors` – Cross-Origin Resource Sharing middleware
|
|
378
|
+
- `ws` – WebSocket bridge relay
|
|
379
|
+
- `@modelcontextprotocol/sdk` – MCP server SDK for the stdio wrapper
|
|
380
|
+
- `zod` – MCP tool input schemas
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
Part of the AiWebplatform project.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { spawn } = require('node:child_process');
|
|
6
|
+
|
|
7
|
+
const CLI_NAME = 'figma-swiftui-mcp';
|
|
8
|
+
const PACKAGE_NAME = '@createlex/figma-swiftui-mcp';
|
|
9
|
+
|
|
10
|
+
function printHelp() {
|
|
11
|
+
console.log(`${CLI_NAME}
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
npx ${PACKAGE_NAME} login
|
|
15
|
+
npx ${PACKAGE_NAME} start [--project /path/to/Xcode/source]
|
|
16
|
+
|
|
17
|
+
Commands:
|
|
18
|
+
login Open the CreateLex browser login flow and save ~/.createlex/auth.json
|
|
19
|
+
start Start the local figma-swiftui MCP runtime and localhost bridge
|
|
20
|
+
help Show this help message
|
|
21
|
+
version Show the package version
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
npx ${PACKAGE_NAME} login
|
|
25
|
+
npx ${PACKAGE_NAME} start --project /Users/you/MyApp/MyApp
|
|
26
|
+
npm install -g ${PACKAGE_NAME}
|
|
27
|
+
${CLI_NAME} start --project /Users/you/MyApp/MyApp
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resolveEntry(command) {
|
|
32
|
+
if (command === 'login') {
|
|
33
|
+
return path.join(__dirname, '..', 'companion', 'login.mjs');
|
|
34
|
+
}
|
|
35
|
+
return path.join(__dirname, '..', 'companion', 'mcp-server.mjs');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function runNode(entry, args) {
|
|
39
|
+
const child = spawn(process.execPath, [entry, ...args], {
|
|
40
|
+
stdio: 'inherit',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
child.on('exit', (code, signal) => {
|
|
44
|
+
if (signal) {
|
|
45
|
+
process.kill(process.pid, signal);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
process.exit(code ?? 0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
child.on('error', (error) => {
|
|
52
|
+
console.error(`${CLI_NAME} failed: ${error.message}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const packageJson = require(path.join(__dirname, '..', 'package.json'));
|
|
58
|
+
const [command = 'help', ...args] = process.argv.slice(2);
|
|
59
|
+
|
|
60
|
+
switch (command) {
|
|
61
|
+
case 'login':
|
|
62
|
+
runNode(resolveEntry('login'), args);
|
|
63
|
+
break;
|
|
64
|
+
case 'start':
|
|
65
|
+
runNode(resolveEntry('start'), args);
|
|
66
|
+
break;
|
|
67
|
+
case 'help':
|
|
68
|
+
case '--help':
|
|
69
|
+
case '-h':
|
|
70
|
+
printHelp();
|
|
71
|
+
break;
|
|
72
|
+
case 'version':
|
|
73
|
+
case '--version':
|
|
74
|
+
case '-v':
|
|
75
|
+
console.log(packageJson.version);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
console.error(`Unknown command: ${command}\n`);
|
|
79
|
+
printHelp();
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|