UNPKG

dynamate-design-to-code

Version:

A powerful tool for converting Figma designs into high-quality, production-ready code with built-in best practices and customizable rulesets

58 lines 2.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FigmaService = void 0; const figma_api_1 = require("figma-api"); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config(); class FigmaService { constructor(config) { this.client = new figma_api_1.Api({ personalAccessToken: config.accessToken }); } async getFileComponents(fileId) { try { const response = await this.client.getFile(fileId); return this.extractComponents(response.document); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; throw new Error(`Failed to fetch Figma components: ${errorMessage}`); } } extractComponents(node) { const components = []; if (node.type === 'COMPONENT' || node.type === 'COMPONENT_SET') { components.push({ id: node.id, name: node.name, type: node.type, }); } if (node.children) { for (const child of node.children) { components.push(...this.extractComponents(child)); } } return components; } async getComponentStyles(componentId) { try { const response = await this.client.getFileNodes(componentId, { geometry: 'paths', plugin_data: 'shared', styles: true }); return response.nodes[componentId]; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; throw new Error(`Failed to fetch component styles: ${errorMessage}`); } } } exports.FigmaService = FigmaService; //# sourceMappingURL=figma.js.map