@todoforai/figma-api 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/bridge.ts +17 -2
package/package.json
CHANGED
package/src/bridge.ts
CHANGED
|
@@ -78,17 +78,32 @@ export function startBridge(port: number): void {
|
|
|
78
78
|
console.log("Point the plugin at this URL (or a cloudflared tunnel of it), then run draw-* commands.");
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/** Setup instructions shown only when a canvas-write command can't reach the plugin. */
|
|
82
|
+
const SETUP = `
|
|
83
|
+
To run canvas commands (create frames/text/shapes, edit variables off-Enterprise),
|
|
84
|
+
the plugin bridge must be set up — the Figma REST API can't do these:
|
|
85
|
+
1. Start the relay (keep running): figma-api bridge
|
|
86
|
+
2. In the Figma DESKTOP app: Plugins → Development → Import plugin from manifest
|
|
87
|
+
→ the plugin/manifest.json shipped with this package. Run it, paste the relay
|
|
88
|
+
URL (default http://localhost:8917), click Connect.
|
|
89
|
+
3. Retry. Verify the round-trip with: figma-api ping
|
|
90
|
+
Cross-machine: expose the relay via 'cloudflared tunnel --url http://localhost:8917'
|
|
91
|
+
and paste that https URL into the plugin. Browser-only Figma can't load dev plugins.`;
|
|
92
|
+
|
|
81
93
|
/** CLI helper: push a command to a running bridge and return the plugin's result. */
|
|
82
94
|
export async function sendCommand(relay: string, op: string, params: Record<string, unknown>): Promise<void> {
|
|
83
95
|
const res = await fetch(`${relay.replace(/\/$/, "")}/cmd`, {
|
|
84
96
|
method: "POST",
|
|
85
97
|
headers: { "content-type": "application/json" },
|
|
86
98
|
body: JSON.stringify({ op, ...params }),
|
|
87
|
-
}).catch((e) => {
|
|
99
|
+
}).catch((e) => {
|
|
100
|
+
console.error(`Bridge relay not reachable at ${relay} (${e.message}).${SETUP}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
|
88
103
|
const data = (await (res as Response).json()) as { result?: { timeout?: boolean; error?: string } };
|
|
89
104
|
const result = data.result;
|
|
90
105
|
if (result?.timeout) {
|
|
91
|
-
console.error(
|
|
106
|
+
console.error(`Timed out waiting for the plugin — the relay is up but no plugin is Connected.${SETUP}`);
|
|
92
107
|
process.exit(1);
|
|
93
108
|
}
|
|
94
109
|
console.log(JSON.stringify(result ?? data, null, 2));
|