@finedesign/cli 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/cli.mjs +60 -3
- package/src/core/contracts.mjs +4 -1
- package/src/core/figma.mjs +93 -2
- package/src/core/lint.mjs +7 -179
- package/src/core/source-code.mjs +204 -0
- package/src/mcp.mjs +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
2026-11-12
|
|
6
|
+
|
|
7
|
+
- 新增 Figma 组件物料清单。CLI 提供 `fine-design figma scan <file-or-dir>`,stdio MCP 提供 `scan_figma_components`。根据 JSX 与 `React.createElement` 的源码绑定识别组件,输出设计库节点、Code Connect 模板和未映射组件。CLI 支持 text、json 和 markdown。解析失败时返回部分清单及诊断。
|
|
8
|
+
- 优化 `figma resolve` 对设计规范总览画板的反查交互,提供明确的组件定位指引。
|
|
9
|
+
|
|
3
10
|
## 0.8.1
|
|
4
11
|
|
|
5
12
|
2026-11-11
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ fine-design init
|
|
|
75
75
|
}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
MCP 提供组件搜索、API、Design Token、示例、版本对比、代码检查、浏览器运行时查询以及 Figma
|
|
78
|
+
MCP 提供组件搜索、API、Design Token、示例、版本对比、代码检查、浏览器运行时查询以及 Figma 节点映射与代码物料清单扫描(`resolve_figma_component` / `list_figma_components` / `scan_figma_components`)。客户端可自动发现工具参数。组件资料查询可省略 `version`:默认从 MCP 进程工作目录检测组件版本,检测不到时使用内置 Skill 对应的资料版本;已检测但未收录的版本仍会报错。代码检查从扫描目标检测版本。`get_browser_runtime` 省略版本时使用当前托管版本,运行时查询需要联网。
|
|
79
79
|
|
|
80
80
|
## 命令
|
|
81
81
|
|
|
@@ -106,7 +106,7 @@ MCP 提供组件搜索、API、Design Token、示例、版本对比、代码检
|
|
|
106
106
|
| --- | --- |
|
|
107
107
|
| `init` | 一键初始化 Agent 规则与配置(`--agent cursor/claude/codex/all`) |
|
|
108
108
|
| `add <component> [id]` | 提取组件示例代码及附属文件到项目目录(支持 `--output` 与 `--force`) |
|
|
109
|
-
| `figma <resolve\|list>` | 反查 Fine Design 库节点的离线 Code Connect
|
|
109
|
+
| `figma <resolve\|list\|scan>` | 反查 Fine Design 库节点的离线 Code Connect 映射、浏览已连接模板,或扫描代码输出物料清单 (BOM) |
|
|
110
110
|
| `mcp` | 启动 stdio MCP 服务 |
|
|
111
111
|
| `runtime [list]` | 查询在线运行时或生成完整 HTML 页面 |
|
|
112
112
|
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -25,7 +25,7 @@ Commands:
|
|
|
25
25
|
diff [fromVer] [toVer] Compare component changes and migrations between versions
|
|
26
26
|
doctor Inspect detected version, available catalogs and bundled Skill
|
|
27
27
|
runtime [list] Resolve a versioned online UMD runtime or list published versions
|
|
28
|
-
figma <resolve|list> [target] Look up Fine Design library nodes
|
|
28
|
+
figma <resolve|list|scan> [target] Look up Fine Design library nodes, list Code Connect mappings, or scan code for Figma components
|
|
29
29
|
mcp Start the stdio MCP server
|
|
30
30
|
|
|
31
31
|
Options:
|
|
@@ -329,12 +329,69 @@ export async function main(argv) {
|
|
|
329
329
|
if (format === 'html' && (command !== 'runtime' || args.length)) throw new ToolError('INVALID_ARGUMENT', 'HTML output format is only supported for runtime resolution.', 2);
|
|
330
330
|
if (command === 'figma') {
|
|
331
331
|
const sub = args[0];
|
|
332
|
-
if (!['resolve', 'list'].includes(sub)) {
|
|
333
|
-
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma <resolve|list> [target] [--format text|json|markdown]', 2);
|
|
332
|
+
if (!['resolve', 'list', 'scan'].includes(sub)) {
|
|
333
|
+
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma <resolve|list|scan> [target] [--format text|json|markdown]', 2);
|
|
334
334
|
}
|
|
335
335
|
if (values.version || values.section !== undefined || summaryFlag || values.offset !== undefined || values.limit !== undefined || values['include-assets'] !== undefined || values['fd-version'] !== undefined) {
|
|
336
336
|
throw new ToolError('INVALID_ARGUMENT', 'Invalid options for figma command. Use --help for usage.', 2);
|
|
337
337
|
}
|
|
338
|
+
if (sub === 'scan') {
|
|
339
|
+
if (args.length !== 2) {
|
|
340
|
+
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma scan <file-or-dir> [--format text|json|markdown]', 2);
|
|
341
|
+
}
|
|
342
|
+
const targetPath = args[1];
|
|
343
|
+
const { scanFigmaComponents } = await import('./core/figma.mjs');
|
|
344
|
+
const result = scanFigmaComponents(targetPath);
|
|
345
|
+
if (format === 'json') {
|
|
346
|
+
console.log(JSON.stringify(result));
|
|
347
|
+
} else if (format === 'markdown') {
|
|
348
|
+
const rows = result.matched.map((c) => `| \`${c.component}\` | \`${c.designName}\` | \`${c.nodeId}\` | \`${c.templateId}\` | ${c.businessInputs ? c.businessInputs.replace(/\|/g, '\\|') : '-'} |`);
|
|
349
|
+
const unmappedRows = result.unmapped.map((u) => `- **${u.component}**: ${u.note}`);
|
|
350
|
+
console.log([
|
|
351
|
+
`# Fine Design 页面物料清单 (Figma BOM)`,
|
|
352
|
+
`- **目标路径**: \`${result.target}\``,
|
|
353
|
+
`- **官方设计库**: \`${result.fileKey}\``,
|
|
354
|
+
`- **扫描文件数**: ${result.scannedFiles}`,
|
|
355
|
+
`- **检测到组件总数**: ${result.totalDetected}`,
|
|
356
|
+
'',
|
|
357
|
+
`## 已连接设计组件 (${result.matched.length})`,
|
|
358
|
+
'| 代码组件 | 设计名称 | Node ID | Code Connect 模板 | 业务入参要求 |',
|
|
359
|
+
'| --- | --- | --- | --- | --- |',
|
|
360
|
+
...rows,
|
|
361
|
+
...(result.unmapped.length ? [
|
|
362
|
+
'',
|
|
363
|
+
`## 未连接设计组件 (${result.unmapped.length})`,
|
|
364
|
+
...unmappedRows
|
|
365
|
+
] : []),
|
|
366
|
+
...(!result.passed ? [
|
|
367
|
+
'',
|
|
368
|
+
'## 解析失败,清单不完整',
|
|
369
|
+
...result.diagnostics.map(({ file, line, column, message }) => `- \`${file}:${line}:${column}\` ${message}`)
|
|
370
|
+
] : [])
|
|
371
|
+
].join('\n'));
|
|
372
|
+
} else {
|
|
373
|
+
const lines = result.matched.map((c) => ` ${c.component.padEnd(18)} ${c.nodeId.padEnd(16)} ${c.templateId.padEnd(24)} ${c.designName}`);
|
|
374
|
+
console.log([
|
|
375
|
+
`Fine Design Page Component Manifest (${result.matched.length} mapped / ${result.totalDetected} total):`,
|
|
376
|
+
`Target: ${result.target} (File Key: ${result.fileKey})`,
|
|
377
|
+
'',
|
|
378
|
+
'Mapped Library Components:',
|
|
379
|
+
...lines,
|
|
380
|
+
...(result.unmapped.length ? [
|
|
381
|
+
'',
|
|
382
|
+
'Unmapped Components:',
|
|
383
|
+
...result.unmapped.map((u) => ` * ${u.component.padEnd(16)} - ${u.note}`)
|
|
384
|
+
] : []),
|
|
385
|
+
...(!result.passed ? [
|
|
386
|
+
'',
|
|
387
|
+
'Parse errors (manifest is incomplete):',
|
|
388
|
+
...result.diagnostics.map(({ file, line, column, message }) => ` ${file}:${line}:${column} ${message}`)
|
|
389
|
+
] : [])
|
|
390
|
+
].join('\n'));
|
|
391
|
+
}
|
|
392
|
+
if (!result.passed) process.exitCode = 1;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
338
395
|
if (sub === 'list') {
|
|
339
396
|
if (args.length > 1) {
|
|
340
397
|
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma list [--format text|json|markdown]', 2);
|
package/src/core/contracts.mjs
CHANGED
|
@@ -56,7 +56,10 @@ export const schemas = {
|
|
|
56
56
|
}).strict().refine((data) => data.target || data.url || data.nodeId || data.component, {
|
|
57
57
|
message: 'Provide at least one of target, url, nodeId, or component.'
|
|
58
58
|
}),
|
|
59
|
-
list_figma_components: z.object({}).strict()
|
|
59
|
+
list_figma_components: z.object({}).strict(),
|
|
60
|
+
scan_figma_components: z.object({
|
|
61
|
+
path: z.string().min(1).max(2048).describe('Source file or directory to scan for Fine Design components, e.g. "src/App.tsx".')
|
|
62
|
+
}).strict()
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
export function validateInput(tool, input) {
|
package/src/core/figma.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { ToolError } from './errors.mjs';
|
|
4
|
+
import { componentName, isCodeFile, isReactCreateElement, listCodeFiles, visitCode } from './source-code.mjs';
|
|
3
5
|
|
|
4
6
|
const figmaData = JSON.parse(fs.readFileSync(new URL('./figma-data.json', import.meta.url), 'utf8'));
|
|
5
7
|
|
|
@@ -50,6 +52,18 @@ function matchedResult(match, query) {
|
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
function primaryMapping(matches) {
|
|
56
|
+
const nodeId = figmaData.primaryLinks[matches[0]?.component];
|
|
57
|
+
return matches.find((match) => match.nodeId === nodeId) ?? matches[0];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function exactComponentMapping(name) {
|
|
61
|
+
const exact = primaryMapping(figmaData.mappings.filter((match) => match.component === name));
|
|
62
|
+
const alias = name.toLowerCase();
|
|
63
|
+
if (exact || !Object.hasOwn(figmaData.aliases, alias)) return exact;
|
|
64
|
+
return primaryMapping(figmaData.mappings.filter((match) => match.component === figmaData.aliases[alias]));
|
|
65
|
+
}
|
|
66
|
+
|
|
53
67
|
export function resolveFigmaComponent(input = {}) {
|
|
54
68
|
const target = (input.target || input.url || input.nodeId || input.component || '').trim();
|
|
55
69
|
if (!target) {
|
|
@@ -68,6 +82,17 @@ export function resolveFigmaComponent(input = {}) {
|
|
|
68
82
|
const nodeId = isUrl ? url.nodeId : normalizeNodeId(target);
|
|
69
83
|
if (isUrl || nodeId || (!input.target && input.nodeId)) {
|
|
70
84
|
const query = { input: target, nodeId };
|
|
85
|
+
if (nodeId === figmaData.indexNodeId) {
|
|
86
|
+
return {
|
|
87
|
+
matched: false,
|
|
88
|
+
isIndex: true,
|
|
89
|
+
query,
|
|
90
|
+
fileKey: figmaData.fileKey,
|
|
91
|
+
indexNodeId: figmaData.indexNodeId,
|
|
92
|
+
url: `https://www.figma.com/design/${figmaData.fileKey}/FineDesign-System?node-id=${figmaData.indexNodeId.replace(':', '-')}`,
|
|
93
|
+
message: 'Target is the FineDesign System component index page (9874:1042). No mapped library node found for the index frame. Use Figma MCP to locate the main component for a page, instance or variant, or use "fine-design figma list" to view all 70 mapped components.'
|
|
94
|
+
};
|
|
95
|
+
}
|
|
71
96
|
const match = figmaData.mappings.find((m) => m.nodeId === nodeId);
|
|
72
97
|
if (match) return matchedResult(match, query);
|
|
73
98
|
return {
|
|
@@ -96,8 +121,7 @@ export function resolveFigmaComponent(input = {}) {
|
|
|
96
121
|
}
|
|
97
122
|
|
|
98
123
|
const exact = figmaData.mappings.filter((m) => m.component.toLowerCase() === canonicalName);
|
|
99
|
-
const
|
|
100
|
-
const matchedEntry = exact.find((m) => m.nodeId === primaryNodeId) ?? exact[0]
|
|
124
|
+
const matchedEntry = primaryMapping(exact)
|
|
101
125
|
?? figmaData.mappings.find((m) => m.component.toLowerCase().replace(/[-_\s.]/g, '') === searchName)
|
|
102
126
|
?? (searchName && figmaData.mappings.find((m) => m.designName.toLowerCase().includes(searchName) || m.component.toLowerCase().includes(searchName)));
|
|
103
127
|
if (matchedEntry) {
|
|
@@ -136,3 +160,70 @@ export function listFigmaComponents() {
|
|
|
136
160
|
}))
|
|
137
161
|
};
|
|
138
162
|
}
|
|
163
|
+
|
|
164
|
+
export function scanFigmaComponents(targetPath) {
|
|
165
|
+
const resolved = path.resolve(targetPath);
|
|
166
|
+
if (!fs.existsSync(resolved)) {
|
|
167
|
+
throw new ToolError('INVALID_ARGUMENT', `Target does not exist: ${targetPath}`, 2);
|
|
168
|
+
}
|
|
169
|
+
if (fs.statSync(resolved).isFile() && !isCodeFile(resolved)) {
|
|
170
|
+
throw new ToolError('INVALID_ARGUMENT', `Unsupported file type: ${targetPath}. Use a JavaScript, TypeScript, or HTML file.`, 2);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const files = listCodeFiles(resolved);
|
|
174
|
+
const names = new Set();
|
|
175
|
+
const diagnostics = [];
|
|
176
|
+
for (const file of files) {
|
|
177
|
+
visitCode(file, fs.readFileSync(file, 'utf8'), (node, scope) => {
|
|
178
|
+
let component;
|
|
179
|
+
if (node.type === 'JSXOpeningElement' &&
|
|
180
|
+
(node.name.type !== 'JSXIdentifier' || !/^[a-z]/.test(node.name.name))) {
|
|
181
|
+
component = componentName(node.name, scope);
|
|
182
|
+
} else if (node.type === 'CallExpression' && isReactCreateElement(node.callee, scope)) {
|
|
183
|
+
component = componentName(node.arguments[0], scope);
|
|
184
|
+
}
|
|
185
|
+
if (component) names.add(component);
|
|
186
|
+
}, (error) => diagnostics.push({
|
|
187
|
+
file, line: error.loc.line, column: error.loc.column + 1, message: error.message
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const matched = new Map();
|
|
192
|
+
const unmapped = new Map();
|
|
193
|
+
for (const name of names) {
|
|
194
|
+
const root = name.split('.')[0];
|
|
195
|
+
const match = exactComponentMapping(name) ?? (root !== name ? exactComponentMapping(root) : undefined);
|
|
196
|
+
if (match) {
|
|
197
|
+
matched.set(match.component, {
|
|
198
|
+
component: match.component,
|
|
199
|
+
designName: match.designName,
|
|
200
|
+
nodeId: match.nodeId,
|
|
201
|
+
url: match.url,
|
|
202
|
+
templateId: match.templateId,
|
|
203
|
+
templateFile: match.file,
|
|
204
|
+
businessInputs: match.businessInputs,
|
|
205
|
+
recommendations: match.recommendations
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
const component = [name, root].find((candidate) => Object.hasOwn(figmaData.unmappedNotes, candidate)) ?? name;
|
|
209
|
+
unmapped.set(component, {
|
|
210
|
+
component,
|
|
211
|
+
note: Object.hasOwn(figmaData.unmappedNotes, component)
|
|
212
|
+
? figmaData.unmappedNotes[component]
|
|
213
|
+
: 'No Figma library mapping is available for this component.'
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const byComponent = (a, b) => a.component.localeCompare(b.component);
|
|
219
|
+
return {
|
|
220
|
+
target: targetPath,
|
|
221
|
+
fileKey: figmaData.fileKey,
|
|
222
|
+
scannedFiles: files.length,
|
|
223
|
+
passed: diagnostics.length === 0,
|
|
224
|
+
totalDetected: matched.size + unmapped.size,
|
|
225
|
+
matched: [...matched.values()].sort(byComponent),
|
|
226
|
+
unmapped: [...unmapped.values()].sort(byComponent),
|
|
227
|
+
diagnostics
|
|
228
|
+
};
|
|
229
|
+
}
|
package/src/core/lint.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { parse } from '@babel/parser';
|
|
4
3
|
import { ToolError } from './errors.mjs';
|
|
5
4
|
import { suggestSimilarComponents } from './catalog.mjs';
|
|
5
|
+
import { componentName, isFineDesignNamespace, isReactCreateElement, isTypeScriptFile, listCodeFiles, visitCode } from './source-code.mjs';
|
|
6
6
|
|
|
7
|
-
const CODE_FILE_PATTERN = /\.(?:[cm]?[jt]sx?|html?)$/i;
|
|
8
|
-
const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'lib', 'es', '.dumi', 'coverage', 'artifacts']);
|
|
9
7
|
const BUTTON_TYPES = new Set(['primary', 'secondary', 'normal', 'negative', 'link', 'text', 'text-normal', 'bare']);
|
|
10
8
|
|
|
11
9
|
const KNOWN_TYPE_EXPORTS = new Set([
|
|
@@ -60,157 +58,7 @@ function collectFiles(targetPath) {
|
|
|
60
58
|
if (!fs.existsSync(resolved)) {
|
|
61
59
|
throw new ToolError('INVALID_ARGUMENT', `Lint target does not exist: ${targetPath}`, 2);
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
function walk(current) {
|
|
65
|
-
const stat = fs.statSync(current);
|
|
66
|
-
if (stat.isFile()) {
|
|
67
|
-
if (CODE_FILE_PATTERN.test(current)) results.push(current);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!stat.isDirectory()) return;
|
|
71
|
-
for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
72
|
-
if (entry.isDirectory()) {
|
|
73
|
-
if (!IGNORED_DIRS.has(entry.name) && !entry.name.startsWith('.')) {
|
|
74
|
-
walk(path.join(current, entry.name));
|
|
75
|
-
}
|
|
76
|
-
} else if (entry.isFile() && CODE_FILE_PATTERN.test(entry.name)) {
|
|
77
|
-
results.push(path.join(current, entry.name));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
walk(resolved);
|
|
82
|
-
return results;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function lineOfIndex(content, index) {
|
|
86
|
-
let line = 1;
|
|
87
|
-
for (let i = 0; i < index; i++) {
|
|
88
|
-
if (content.charCodeAt(i) === 10) line++;
|
|
89
|
-
}
|
|
90
|
-
return line;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function codeSources(file, content) {
|
|
94
|
-
if (!/\.html?$/i.test(file)) return [{ content, startLine: 1 }];
|
|
95
|
-
return [...content.matchAll(/<!--[\s\S]*?-->|<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)]
|
|
96
|
-
.filter((match) => {
|
|
97
|
-
if (match[1] === undefined) return false;
|
|
98
|
-
const type = match[1].match(/\btype\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i);
|
|
99
|
-
return !type || /^(?:module|(?:text|application)\/(?:javascript|ecmascript|babel|typescript))$/i.test(type[1] ?? type[2] ?? type[3]);
|
|
100
|
-
})
|
|
101
|
-
.map((match) => ({ content: match[2], startLine: lineOfIndex(content, match.index + match[0].indexOf('>') + 1) }));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function bindPattern(pattern, scope) {
|
|
105
|
-
if (!pattern) return;
|
|
106
|
-
if (pattern.type === 'Identifier') scope.bindings.set(pattern.name, null);
|
|
107
|
-
else if (pattern.type === 'ObjectPattern') {
|
|
108
|
-
for (const prop of pattern.properties) bindPattern(prop.type === 'RestElement' ? prop.argument : prop.value, scope);
|
|
109
|
-
} else if (pattern.type === 'ArrayPattern') {
|
|
110
|
-
for (const element of pattern.elements) bindPattern(element, scope);
|
|
111
|
-
} else if (pattern.type === 'AssignmentPattern') bindPattern(pattern.left, scope);
|
|
112
|
-
else if (pattern.type === 'RestElement') bindPattern(pattern.argument, scope);
|
|
113
|
-
else if (pattern.type === 'TSParameterProperty') bindPattern(pattern.parameter, scope);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function collectScopes(program) {
|
|
117
|
-
const scopes = new WeakMap();
|
|
118
|
-
function collect(node, scope) {
|
|
119
|
-
if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') bindPattern(node.id, scope);
|
|
120
|
-
const isFunction = /Function(?:Declaration|Expression)$|Method$/.test(node.type);
|
|
121
|
-
if (isFunction || ['Program', 'BlockStatement', 'CatchClause', 'ForStatement', 'ForInStatement', 'ForOfStatement', 'SwitchStatement', 'StaticBlock', 'ClassDeclaration', 'ClassExpression'].includes(node.type)) {
|
|
122
|
-
scope = { parent: scope, bindings: new Map(), varScope: isFunction || node.type === 'Program' || node.type === 'StaticBlock' ? null : scope.varScope };
|
|
123
|
-
scope.varScope ||= scope;
|
|
124
|
-
if (isFunction || node.type === 'ClassExpression') bindPattern(node.id, scope);
|
|
125
|
-
for (const param of node.params || []) bindPattern(param, scope);
|
|
126
|
-
if (node.type === 'CatchClause') bindPattern(node.param, scope);
|
|
127
|
-
}
|
|
128
|
-
scopes.set(node, scope);
|
|
129
|
-
if (node.type === 'ImportDeclaration') {
|
|
130
|
-
for (const spec of node.specifiers) {
|
|
131
|
-
bindPattern(spec.local, scope);
|
|
132
|
-
if (node.source.value === '@fx-ui/fine-design' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
133
|
-
if (spec.type === 'ImportSpecifier') scope.bindings.set(spec.local.name, { component: spec.imported.name ?? spec.imported.value });
|
|
134
|
-
else if (spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { namespace: true });
|
|
135
|
-
}
|
|
136
|
-
if (node.source.value === 'react' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
137
|
-
if (spec.type === 'ImportDefaultSpecifier' || spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { reactNamespace: true });
|
|
138
|
-
else if ((spec.imported.name ?? spec.imported.value) === 'createElement') scope.bindings.set(spec.local.name, { reactFactory: true });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} else if (node.type === 'VariableDeclaration') {
|
|
142
|
-
const targetScope = node.kind === 'var' ? scope.varScope : scope;
|
|
143
|
-
for (const declaration of node.declarations) {
|
|
144
|
-
bindPattern(declaration.id, targetScope);
|
|
145
|
-
if (declaration.id.type === 'Identifier' && declaration.init) {
|
|
146
|
-
targetScope.bindings.set(declaration.id.name, { initializer: declaration.init, scope });
|
|
147
|
-
}
|
|
148
|
-
if (declaration.id.type !== 'ObjectPattern') continue;
|
|
149
|
-
for (const prop of declaration.id.properties) {
|
|
150
|
-
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
151
|
-
const local = prop.value.type === 'AssignmentPattern' ? prop.value.left : prop.value;
|
|
152
|
-
if (local.type === 'Identifier') targetScope.bindings.set(local.name, { component: String(prop.key.name ?? prop.key.value), source: declaration.init, scope });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
for (const child of Object.values(node)) {
|
|
157
|
-
if (Array.isArray(child)) child.filter((item) => item?.type).forEach((item) => collect(item, scope));
|
|
158
|
-
else if (child?.type) collect(child, scope);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
collect(program);
|
|
162
|
-
return scopes;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function findBinding(scope, name) {
|
|
166
|
-
for (; scope; scope = scope.parent) {
|
|
167
|
-
if (scope.bindings.has(name)) return scope.bindings.get(name);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function isGlobalMember(node, scope, object, property) {
|
|
172
|
-
return ['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed &&
|
|
173
|
-
node.object.name === object && node.property.name === property && findBinding(scope, object) === undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isFineDesignNamespace(node, scope) {
|
|
177
|
-
if (node?.type === 'Identifier' || node?.type === 'JSXIdentifier') {
|
|
178
|
-
const binding = findBinding(scope, node.name);
|
|
179
|
-
return Boolean(binding?.namespace || (node.name === 'FineDesign' && binding === undefined) ||
|
|
180
|
-
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'FineDesign'));
|
|
181
|
-
}
|
|
182
|
-
return isGlobalMember(node, scope, 'window', 'FineDesign');
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// shortcut: resolve imports and direct initializers in the same script, add data-flow analysis if reassigned or cross-script aliases need checking.
|
|
186
|
-
function componentName(node, scope) {
|
|
187
|
-
if (node?.type === 'JSXIdentifier' || node?.type === 'Identifier') {
|
|
188
|
-
const binding = findBinding(scope, node.name);
|
|
189
|
-
if (binding?.component && (!Object.hasOwn(binding, 'source') || isFineDesignNamespace(binding.source, binding.scope))) return binding.component;
|
|
190
|
-
node = binding?.initializer;
|
|
191
|
-
scope = binding?.scope;
|
|
192
|
-
}
|
|
193
|
-
if (['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed) {
|
|
194
|
-
if (isFineDesignNamespace(node.object, scope)) return node.property.name;
|
|
195
|
-
const parent = componentName(node.object, scope);
|
|
196
|
-
if (parent) return `${parent}.${node.property.name}`;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function isReactCreateElement(node, scope) {
|
|
201
|
-
if (node.type === 'Identifier') {
|
|
202
|
-
const binding = findBinding(scope, node.name);
|
|
203
|
-
if (binding?.reactFactory) return true;
|
|
204
|
-
node = binding?.initializer;
|
|
205
|
-
scope = binding?.scope;
|
|
206
|
-
}
|
|
207
|
-
if (node?.type !== 'MemberExpression' || node.computed || node.property.name !== 'createElement') return false;
|
|
208
|
-
if (isGlobalMember(node.object, scope, 'window', 'React')) return true;
|
|
209
|
-
if (node.object.type !== 'Identifier') return false;
|
|
210
|
-
const binding = findBinding(scope, node.object.name);
|
|
211
|
-
return (node.object.name === 'React' && binding === undefined) ||
|
|
212
|
-
binding?.reactNamespace ||
|
|
213
|
-
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'React');
|
|
61
|
+
return listCodeFiles(resolved);
|
|
214
62
|
}
|
|
215
63
|
|
|
216
64
|
function staticProps(attributes) {
|
|
@@ -249,7 +97,7 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
249
97
|
|
|
250
98
|
for (const file of files) {
|
|
251
99
|
const content = fs.readFileSync(file, 'utf8');
|
|
252
|
-
const typescript =
|
|
100
|
+
const typescript = isTypeScriptFile(file);
|
|
253
101
|
const report = (node, rule, severity, message, suggestion) => diagnostics.push({
|
|
254
102
|
file, line: node.loc.start.line, rule, severity, message, suggestion
|
|
255
103
|
});
|
|
@@ -328,8 +176,7 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
328
176
|
}
|
|
329
177
|
}
|
|
330
178
|
|
|
331
|
-
function visit(node,
|
|
332
|
-
const scope = scopes.get(node);
|
|
179
|
+
function visit(node, scope) {
|
|
333
180
|
if (node.type === 'ImportDeclaration') {
|
|
334
181
|
const source = node.source.value;
|
|
335
182
|
if (/^(?:@fx-ui\/fine-design\/(?:es|lib)\/icons|@ant-design\/icons)$/.test(source)) {
|
|
@@ -358,30 +205,11 @@ export function lintFiles(catalog, targets = ['.']) {
|
|
|
358
205
|
} else if (node.type === 'JSXOpeningElement') {
|
|
359
206
|
checkProps(componentName(node.name, scope), node.attributes);
|
|
360
207
|
}
|
|
361
|
-
for (const child of Object.values(node)) {
|
|
362
|
-
if (Array.isArray(child)) child.filter((item) => item?.type).forEach((item) => visit(item, scopes));
|
|
363
|
-
else if (child?.type) visit(child, scopes);
|
|
364
|
-
}
|
|
365
208
|
}
|
|
366
209
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
ast = parse(source.content, {
|
|
371
|
-
sourceType: 'unambiguous', startLine: source.startLine, attachComment: false,
|
|
372
|
-
plugins: [
|
|
373
|
-
'decorators-legacy',
|
|
374
|
-
...(typescript ? [['typescript', { dts: /\.d\.[cm]?ts$/i.test(file) }]] : []),
|
|
375
|
-
...(!typescript || /tsx$/i.test(file) ? ['jsx'] : [])
|
|
376
|
-
]
|
|
377
|
-
});
|
|
378
|
-
} catch (error) {
|
|
379
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
380
|
-
report({ loc: { start: error.loc } }, 'parse-error', 'error', error.message, 'Fix the syntax error before checking Fine Design APIs.');
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
visit(ast.program, collectScopes(ast.program));
|
|
384
|
-
}
|
|
210
|
+
visitCode(file, content, visit, (error) => {
|
|
211
|
+
report({ loc: { start: error.loc } }, 'parse-error', 'error', error.message, 'Fix the syntax error before checking Fine Design APIs.');
|
|
212
|
+
});
|
|
385
213
|
}
|
|
386
214
|
|
|
387
215
|
const errorCount = diagnostics.filter((d) => d.severity === 'error').length;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from '@babel/parser';
|
|
4
|
+
|
|
5
|
+
const CODE_FILE_PATTERN = /\.(?:[cm]?[jt]sx?|html?)$/i;
|
|
6
|
+
const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'lib', 'es', '.dumi', 'coverage', 'artifacts']);
|
|
7
|
+
const FINE_DESIGN_GLOBALS = new Set(['FineDesign', 'jdyDesign']);
|
|
8
|
+
|
|
9
|
+
export function isCodeFile(file) {
|
|
10
|
+
return CODE_FILE_PATTERN.test(file);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isTypeScriptFile(file) {
|
|
14
|
+
return /\.[cm]?tsx?$/i.test(file);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function listCodeFiles(file) {
|
|
18
|
+
const stat = fs.statSync(file);
|
|
19
|
+
if (stat.isFile()) return isCodeFile(file) ? [file] : [];
|
|
20
|
+
if (!stat.isDirectory()) return [];
|
|
21
|
+
|
|
22
|
+
const results = [];
|
|
23
|
+
function walk(dir) {
|
|
24
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
25
|
+
if (entry.isDirectory()) {
|
|
26
|
+
if (!IGNORED_DIRS.has(entry.name) && !entry.name.startsWith('.')) walk(path.join(dir, entry.name));
|
|
27
|
+
} else if (entry.isFile() && isCodeFile(entry.name)) {
|
|
28
|
+
results.push(path.join(dir, entry.name));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
walk(file);
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function lineOfIndex(content, index) {
|
|
37
|
+
let line = 1;
|
|
38
|
+
for (let i = 0; i < index; i++) {
|
|
39
|
+
if (content.charCodeAt(i) === 10) line++;
|
|
40
|
+
}
|
|
41
|
+
return line;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function codeSources(file, content) {
|
|
45
|
+
if (!/\.html?$/i.test(file)) return [{ content, startLine: 1 }];
|
|
46
|
+
return [...content.matchAll(/<!--[\s\S]*?-->|<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)]
|
|
47
|
+
.filter((match) => {
|
|
48
|
+
if (match[1] === undefined) return false;
|
|
49
|
+
const type = match[1].match(/\btype\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i);
|
|
50
|
+
return !type || /^(?:module|(?:text|application)\/(?:javascript|ecmascript|babel|typescript))$/i.test(type[1] ?? type[2] ?? type[3]);
|
|
51
|
+
})
|
|
52
|
+
.map((match) => ({ content: match[2], startLine: lineOfIndex(content, match.index + match[0].indexOf('>') + 1) }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function bindPattern(pattern, scope) {
|
|
56
|
+
if (!pattern) return;
|
|
57
|
+
if (pattern.type === 'Identifier') scope.bindings.set(pattern.name, null);
|
|
58
|
+
else if (pattern.type === 'ObjectPattern') {
|
|
59
|
+
for (const prop of pattern.properties) bindPattern(prop.type === 'RestElement' ? prop.argument : prop.value, scope);
|
|
60
|
+
} else if (pattern.type === 'ArrayPattern') {
|
|
61
|
+
for (const element of pattern.elements) bindPattern(element, scope);
|
|
62
|
+
} else if (pattern.type === 'AssignmentPattern') bindPattern(pattern.left, scope);
|
|
63
|
+
else if (pattern.type === 'RestElement') bindPattern(pattern.argument, scope);
|
|
64
|
+
else if (pattern.type === 'TSParameterProperty') bindPattern(pattern.parameter, scope);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function collectScopes(program) {
|
|
68
|
+
const scopes = new WeakMap();
|
|
69
|
+
function collect(node, scope) {
|
|
70
|
+
if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') bindPattern(node.id, scope);
|
|
71
|
+
const isFunction = /Function(?:Declaration|Expression)$|Method$/.test(node.type);
|
|
72
|
+
if (isFunction || ['Program', 'BlockStatement', 'CatchClause', 'ForStatement', 'ForInStatement', 'ForOfStatement', 'SwitchStatement', 'StaticBlock', 'ClassDeclaration', 'ClassExpression'].includes(node.type)) {
|
|
73
|
+
scope = { parent: scope, bindings: new Map(), varScope: isFunction || node.type === 'Program' || node.type === 'StaticBlock' ? null : scope.varScope };
|
|
74
|
+
scope.varScope ||= scope;
|
|
75
|
+
if (isFunction || node.type === 'ClassExpression') bindPattern(node.id, scope);
|
|
76
|
+
for (const param of node.params || []) bindPattern(param, scope);
|
|
77
|
+
if (node.type === 'CatchClause') bindPattern(node.param, scope);
|
|
78
|
+
}
|
|
79
|
+
scopes.set(node, scope);
|
|
80
|
+
if (node.type === 'ImportDeclaration') {
|
|
81
|
+
for (const spec of node.specifiers) {
|
|
82
|
+
bindPattern(spec.local, scope);
|
|
83
|
+
if (node.source.value === '@fx-ui/fine-design' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
84
|
+
if (spec.type === 'ImportSpecifier') scope.bindings.set(spec.local.name, { component: spec.imported.name ?? spec.imported.value });
|
|
85
|
+
else if (spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { namespace: true });
|
|
86
|
+
}
|
|
87
|
+
if (node.source.value === 'react' && node.importKind !== 'type' && spec.importKind !== 'type') {
|
|
88
|
+
if (spec.type === 'ImportDefaultSpecifier' || spec.type === 'ImportNamespaceSpecifier') scope.bindings.set(spec.local.name, { reactNamespace: true });
|
|
89
|
+
else if ((spec.imported.name ?? spec.imported.value) === 'createElement') scope.bindings.set(spec.local.name, { reactFactory: true });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else if (node.type === 'VariableDeclaration') {
|
|
93
|
+
const targetScope = node.kind === 'var' ? scope.varScope : scope;
|
|
94
|
+
for (const declaration of node.declarations) {
|
|
95
|
+
bindPattern(declaration.id, targetScope);
|
|
96
|
+
if (declaration.id.type === 'Identifier' && declaration.init) {
|
|
97
|
+
targetScope.bindings.set(declaration.id.name, { initializer: declaration.init, scope });
|
|
98
|
+
}
|
|
99
|
+
if (declaration.id.type !== 'ObjectPattern') continue;
|
|
100
|
+
for (const prop of declaration.id.properties) {
|
|
101
|
+
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
102
|
+
const local = prop.value.type === 'AssignmentPattern' ? prop.value.left : prop.value;
|
|
103
|
+
if (local.type === 'Identifier') targetScope.bindings.set(local.name, { component: String(prop.key.name ?? prop.key.value), source: declaration.init, scope });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const child of Object.values(node)) {
|
|
108
|
+
if (Array.isArray(child)) child.filter((item) => item?.type).forEach((item) => collect(item, scope));
|
|
109
|
+
else if (child?.type) collect(child, scope);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
collect(program);
|
|
113
|
+
return scopes;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findBinding(scope, name) {
|
|
117
|
+
for (; scope; scope = scope.parent) {
|
|
118
|
+
if (scope.bindings.has(name)) return scope.bindings.get(name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isGlobalMember(node, scope, object, property) {
|
|
123
|
+
return ['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed &&
|
|
124
|
+
node.object.name === object && node.property.name === property && findBinding(scope, object) === undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function isFineDesignNamespace(node, scope, visited = new Set()) {
|
|
128
|
+
if (node?.type === 'Identifier' || node?.type === 'JSXIdentifier') {
|
|
129
|
+
const binding = findBinding(scope, node.name);
|
|
130
|
+
if (binding === undefined) return FINE_DESIGN_GLOBALS.has(node.name);
|
|
131
|
+
if (binding?.namespace) return true;
|
|
132
|
+
if (!binding?.initializer || visited.has(binding)) return false;
|
|
133
|
+
visited.add(binding);
|
|
134
|
+
return isFineDesignNamespace(binding.initializer, binding.scope, visited);
|
|
135
|
+
}
|
|
136
|
+
return FINE_DESIGN_GLOBALS.has(node?.property?.name) && isGlobalMember(node, scope, 'window', node.property.name);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// shortcut: resolve imports and direct initializers in the same script, add data-flow analysis if reassigned or cross-script aliases need checking.
|
|
140
|
+
export function componentName(node, scope, visited = new Set()) {
|
|
141
|
+
if (node?.type === 'JSXIdentifier' || node?.type === 'Identifier') {
|
|
142
|
+
const binding = findBinding(scope, node.name);
|
|
143
|
+
if (!binding || visited.has(binding)) return;
|
|
144
|
+
visited.add(binding);
|
|
145
|
+
if (binding.component) {
|
|
146
|
+
if (!Object.hasOwn(binding, 'source') || isFineDesignNamespace(binding.source, binding.scope)) return binding.component;
|
|
147
|
+
const parent = componentName(binding.source, binding.scope, visited);
|
|
148
|
+
if (parent) return `${parent}.${binding.component}`;
|
|
149
|
+
}
|
|
150
|
+
return componentName(binding.initializer, binding.scope, visited);
|
|
151
|
+
}
|
|
152
|
+
if (['MemberExpression', 'JSXMemberExpression'].includes(node?.type) && !node.computed) {
|
|
153
|
+
if (isFineDesignNamespace(node.object, scope)) return node.property.name;
|
|
154
|
+
const parent = componentName(node.object, scope, visited);
|
|
155
|
+
if (parent) return `${parent}.${node.property.name}`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function isReactCreateElement(node, scope) {
|
|
160
|
+
if (node.type === 'Identifier') {
|
|
161
|
+
const binding = findBinding(scope, node.name);
|
|
162
|
+
if (binding?.reactFactory) return true;
|
|
163
|
+
node = binding?.initializer;
|
|
164
|
+
scope = binding?.scope;
|
|
165
|
+
}
|
|
166
|
+
if (node?.type !== 'MemberExpression' || node.computed || node.property.name !== 'createElement') return false;
|
|
167
|
+
if (isGlobalMember(node.object, scope, 'window', 'React')) return true;
|
|
168
|
+
if (node.object.type !== 'Identifier') return false;
|
|
169
|
+
const binding = findBinding(scope, node.object.name);
|
|
170
|
+
return (node.object.name === 'React' && binding === undefined) ||
|
|
171
|
+
binding?.reactNamespace ||
|
|
172
|
+
isGlobalMember(binding?.initializer, binding?.scope, 'window', 'React');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function visitCode(file, content, visit, reportParseError) {
|
|
176
|
+
const typescript = isTypeScriptFile(file);
|
|
177
|
+
for (const source of codeSources(file, content)) {
|
|
178
|
+
let ast;
|
|
179
|
+
try {
|
|
180
|
+
ast = parse(source.content, {
|
|
181
|
+
sourceType: 'unambiguous', startLine: source.startLine, attachComment: false,
|
|
182
|
+
plugins: [
|
|
183
|
+
'decorators-legacy',
|
|
184
|
+
...(typescript ? [['typescript', { dts: /\.d\.[cm]?ts$/i.test(file) }]] : []),
|
|
185
|
+
...(!typescript || /tsx$/i.test(file) ? ['jsx'] : [])
|
|
186
|
+
]
|
|
187
|
+
});
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
190
|
+
reportParseError(error);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const scopes = collectScopes(ast.program);
|
|
195
|
+
function walk(node) {
|
|
196
|
+
visit(node, scopes.get(node));
|
|
197
|
+
for (const child of Object.values(node)) {
|
|
198
|
+
if (Array.isArray(child)) child.filter((item) => item?.type).forEach(walk);
|
|
199
|
+
else if (child?.type) walk(child);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
walk(ast.program);
|
|
203
|
+
}
|
|
204
|
+
}
|
package/src/mcp.mjs
CHANGED
|
@@ -31,7 +31,8 @@ export async function startMcp() {
|
|
|
31
31
|
list_browser_runtimes: 'Read the one currently hosted UMD version from its online manifest. Requires network access.',
|
|
32
32
|
get_browser_runtime: 'Resolve a component version to versioned current UMD URLs and SRI loading tags. Version is optional (defaults to hosted version). Requires network access; never falls back to another version.',
|
|
33
33
|
resolve_figma_component: 'Look up a Fine Design library node URL, library node ID, or component name in the offline Code Connect snapshot. Use Figma MCP first for page, frame, or instance links.',
|
|
34
|
-
list_figma_components: 'List all Figma-connected Fine Design components, node IDs, and Code Connect template IDs.'
|
|
34
|
+
list_figma_components: 'List all Figma-connected Fine Design components, node IDs, and Code Connect template IDs.',
|
|
35
|
+
scan_figma_components: 'Scan source files for Fine Design components used in JSX or React.createElement and return their Figma library mappings. Parse errors return an incomplete manifest with diagnostics.'
|
|
35
36
|
};
|
|
36
37
|
server.setRequestHandler(ListToolsRequestSchema, () => ({ tools: Object.entries(schemas).map(([name, schema]) => ({
|
|
37
38
|
name, description: descriptions[name], inputSchema: z.toJSONSchema(schema, { target: 'draft-07' }),
|
|
@@ -69,11 +70,17 @@ export async function startMcp() {
|
|
|
69
70
|
} else if (toolName === 'list_figma_components') {
|
|
70
71
|
const { listFigmaComponents } = await import('./core/figma.mjs');
|
|
71
72
|
result = listFigmaComponents();
|
|
73
|
+
} else if (toolName === 'scan_figma_components') {
|
|
74
|
+
const { scanFigmaComponents } = await import('./core/figma.mjs');
|
|
75
|
+
result = scanFigmaComponents(args.path);
|
|
72
76
|
} else {
|
|
73
77
|
const ver = resolveMcpVersion(args.version);
|
|
74
78
|
result = queryCatalog(loadCatalog(ver), toolName, { ...args, version: ver });
|
|
75
79
|
}
|
|
76
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
...(toolName === 'scan_figma_components' && !result.passed ? { isError: true } : {}),
|
|
82
|
+
content: [{ type: 'text', text: JSON.stringify(result) }]
|
|
83
|
+
};
|
|
77
84
|
} catch (error) {
|
|
78
85
|
return { isError: true, content: [{ type: 'text', text: JSON.stringify(errorResult(error)) }] };
|
|
79
86
|
}
|