MCPcopy Index your code
hub / github.com/bernaferrari/FigmaToCode / run

Function run

packages/backend/src/code.ts:26–174  ·  view source on GitHub ↗
(settings: PluginSettings)

Source from the content-addressed store, hash-verified

24} from "./altNodes/jsonNodeConversion";
25
26export const run = async (settings: PluginSettings) => {
27 resetPerformanceCounters();
28 clearWarnings();
29
30 const { framework, useOldPluginVersion2025 } = settings;
31 const selection = figma.currentPage.selection;
32
33 if (selection.length === 0) {
34 postEmptyMessage();
35 return;
36 }
37
38 const MAX_NODE_COUNT_PREVIEW = 1200;
39 const MAX_NODE_COUNT_HARD = 4000;
40 const countNodes = (nodes: ReadonlyArray<SceneNode>) => {
41 let count = 0;
42 const stack = [...nodes];
43 while (stack.length > 0) {
44 const node = stack.pop()!;
45 count += 1;
46 if ("children" in node && Array.isArray(node.children)) {
47 for (const child of node.children) {
48 stack.push(child);
49 }
50 }
51 }
52 return count;
53 };
54
55 const nodeCount = countNodes(selection);
56 if (nodeCount > MAX_NODE_COUNT_HARD) {
57 postError(
58 `Selection too large (${nodeCount} nodes). Please select a smaller frame.`,
59 );
60 return;
61 }
62 const skipHeavyUI = nodeCount > MAX_NODE_COUNT_PREVIEW;
63 if (skipHeavyUI) {
64 addWarning(
65 `Large selection (${nodeCount} nodes). HTML preview and colors are disabled to avoid memory issues.`,
66 );
67 }
68
69 // Timing with Date.now() instead of console.time
70 const nodeToJSONStart = Date.now();
71
72 let convertedSelection: any;
73 if (useOldPluginVersion2025) {
74 convertedSelection = oldConvertNodesToAltNodes(selection, null);
75 console.log(
76 "[debug] convertedSelection count (old conversion):",
77 convertedSelection.length,
78 );
79 } else {
80 convertedSelection = await nodesToJSON(selection, settings);
81 console.log(`[benchmark] nodesToJSON: ${Date.now() - nodeToJSONStart}ms`);
82 console.log(
83 "[debug] convertedSelection count:",

Callers 1

safeRunFunction · 0.90

Calls 13

resetPerformanceCountersFunction · 0.90
clearWarningsFunction · 0.90
postEmptyMessageFunction · 0.90
postErrorFunction · 0.90
addWarningFunction · 0.90
nodesToJSONFunction · 0.90
convertToCodeFunction · 0.90
generateHTMLPreviewFunction · 0.90
postConversionCompleteFunction · 0.90

Tested by

no test coverage detected