Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

feat(figma): core ./figma export + scan/merge wrapper scripts

gruming12af092a977d
diff --git a/understand-anything-plugin/packages/core/package.json b/understand-anything-plugin/packages/core/package.json
index e54ce728..5a577078 100644
--- a/understand-anything-plugin/packages/core/package.json
+++ b/understand-anything-plugin/packages/core/package.json
@@ -24,6 +24,10 @@
"./languages": {
"types": "./dist/languages/index.d.ts",
"default": "./dist/languages/index.js"
+ },
+ "./figma": {
+ "types": "./dist/figma/index.d.ts",
+ "default": "./dist/figma/index.js"
}
},
"scripts": {
diff --git a/understand-anything-plugin/skills/understand-figma/figma-merge.mjs b/understand-anything-plugin/skills/understand-figma/figma-merge.mjs
new file mode 100644
index 00000000..e7c757c2
--- /dev/null
+++ b/understand-anything-plugin/skills/understand-figma/figma-merge.mjs
@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+import { readFileSync, writeFileSync, readdirSync } from "node:fs";
+import { join } from "node:path";
+import { mergeDesignGraph } from "@understand-anything/core/figma";
+
+const [, , projectRoot] = process.argv;
+const interDir = join(projectRoot, ".understand-anything", "intermediate");
+const manifest = JSON.parse(readFileSync(join(interDir, "scan-manifest.json"), "utf8"));
+const analyses = readdirSync(interDir)
+ .filter((f) => /^analysis-batch-.*\.json$/.test(f))
+ .map((f) => JSON.parse(readFileSync(join(interDir, f), "utf8")));
+
+const result = mergeDesignGraph(
+ { nodes: manifest.nodes, edges: manifest.edges },
+ analyses,
+ manifest.project,
+);
+if (!result.success || !result.data) {
+ console.error("Merge failed:", result.fatal ?? "unknown error");
+ process.exit(1);
+}
+
+const outDir = join(projectRoot, ".understand-anything");
+writeFileSync(join(outDir, "knowledge-graph.json"), JSON.stringify(result.data, null, 2));
+writeFileSync(join(outDir, "meta.json"), JSON.stringify({
+ lastAnalyzedAt: new Date().toISOString(),
+ gitCommitHash: "",
+ version: "1.0.0",
+ analyzedFiles: result.data.nodes.length,
+}, null, 2));
+
+console.error(
+ `Design graph: ${result.data.nodes.length} nodes, ${result.data.edges.length} edges, ` +
+ `${result.data.layers.length} layers, ${result.data.tour.length} tour steps`,
+);
+for (const issue of result.issues) {
+ if (issue.level !== "auto-corrected") console.error(`[${issue.level}] ${issue.message}`);
+}
diff --git a/understand-anything-plugin/skills/understand-figma/figma-scan.mjs b/understand-anything-plugin/skills/understand-figma/figma-scan.mjs
new file mode 100644
index 00000000..bbbffb30
--- /dev/null
+++ b/understand-anything-plugin/skills/understand-figma/figma-scan.mjs
@@ -0,0 +1,45 @@
+#!/usr/bin/env node
+import { writeFileSync, mkdirSync } from "node:fs";
+import { join } from "node:path";
+import { parseFileKey, FigmaApiSource, parseDocument, extractTokens } from "@understand-anything/core/figma";
+
+const [, , projectRoot, urlOrKey] = process.argv;
+if (!projectRoot || !urlOrKey) {
+ console.error("usage: figma-scan.mjs <projectRoot> <figmaUrlOrKey>");
+ process.exit(1);
+}
+
+const fileKey = parseFileKey(urlOrKey);
+const source = new FigmaApiSource(fileKey); // reads FIGMA_TOKEN from env; throws a friendly error if missing
+const doc = await source.fetchDocument();
+const styles = await source.fetchStyles().catch(() => ({ meta: { styles: [] } }));
+
+const structural = parseDocument(doc, fileKey);
+const tokens = extractTokens(doc, styles, structural.nodes, fileKey);
+const nodes = [...structural.nodes, ...tokens.nodes];
+const edges = [...structural.edges, ...tokens.edges];
+
+const manifest = {
+ project: {
+ name: doc.name,
+ languages: ["figma"],
+ frameworks: [],
+ description: `Figma design file: ${doc.name}`,
+ analyzedAt: new Date().toISOString(),
+ gitCommitHash: "",
+ },
+ fileKey,
+ nodes,
+ edges,
+};
+
+const interDir = join(projectRoot, ".understand-anything", "intermediate");
+mkdirSync(interDir, { recursive: true });
+writeFileSync(join(interDir, "scan-manifest.json"), JSON.stringify(manifest, null, 2));
+
+const count = (t) => nodes.filter((n) => n.type === t).length;
+console.error(
+ `Figma scan: ${count("page")} pages, ${count("screen")} screens, ` +
+ `${count("component")} components, ${count("componentSet")} sets, ` +
+ `${count("instance")} instances, ${count("token")} tokens`,
+);