UNPKG

figma-to-ide

Version:

Convert Figma designs to developer-friendly MCP structure with CLI & tree visualization

77 lines (76 loc) 2.37 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const yargs_1 = __importDefault(require("yargs")); const helpers_1 = require("yargs/helpers"); const index_1 = require("./index"); const fs_1 = __importDefault(require("fs")); const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) .option("key", { alias: "k", type: "string", demandOption: true, description: "Your Figma API key", }) .option("file", { alias: "f", type: "string", demandOption: true, description: "Figma File ID", }) .option("visualize", { alias: "v", type: "boolean", description: "Show component tree in terminal", }) .option("output", { alias: "o", type: "string", description: "Save MCP output to a JSON file", }) .help() .argv; function printTree(pages) { pages.forEach((page) => { var _a; console.log(`📄 Page: ${(_a = page.name) !== null && _a !== void 0 ? _a : "Unnamed Page"}`); if (Array.isArray(page.components)) { page.components.forEach((comp) => { printComponent(comp, "├── "); }); } else { console.warn(`⚠️ No components found in page: ${page.name}`); } }); } function printComponent(comp, indent = "") { var _a; const icon = comp.type === "FRAME" ? "🧩" : "🧱"; console.log(`${indent}${icon} ${comp.type}: ${comp.name}`); (_a = comp.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => { printComponent(child, indent + "│ "); }); } (async () => { try { const mcp = await (0, index_1.fetchMCPFromFigma)(argv.key, argv.file); if (argv.visualize) { printTree(mcp.pages || []); } if (argv.output) { fs_1.default.writeFileSync(argv.output, JSON.stringify(mcp, null, 2)); console.log(`✅ Saved MCP to ${argv.output}`); } else if (!argv.visualize) { console.log(JSON.stringify(mcp, null, 2)); } } catch (error) { console.error("❌ Error occurred:", error.message || error); process.exit(1); } })();