figma-to-ide
Version:
Convert Figma designs to developer-friendly MCP structure with CLI & tree visualization
48 lines (47 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformToMCP = transformToMCP;
function transformToMCP(figmaData) {
const pages = figmaData.document.children || [];
const mcp = {
type: "project",
source: "Figma",
name: figmaData.name,
pages: pages.map((page) => {
var _a, _b;
return ({
id: page.id,
name: (_a = page.name) !== null && _a !== void 0 ? _a : "Unnamed Page",
type: page.type,
components: extractComponents(page, (_b = page.name) !== null && _b !== void 0 ? _b : "UnnamedPage"),
});
}),
meta: {
lastModified: figmaData.lastModified,
},
};
return mcp;
}
function extractComponents(node, pageName) {
const result = [];
function traverse(n, parent = null) {
var _a;
if (["FRAME", "COMPONENT"].includes(n.type)) {
result.push({
type: "component",
name: n.name,
description: "Generated from Figma",
children: ((_a = n.children) === null || _a === void 0 ? void 0 : _a.map((c) => c.name)) || [],
props: {},
source: "Figma",
filePath: `/${pageName}/${n.name}.tsx`,
parent: parent,
});
}
if (n.children) {
n.children.forEach((child) => traverse(child, n.name));
}
}
traverse(node);
return result;
}