@finedesign/cli 0.6.1 → 0.8.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 +17 -0
- package/README.md +22 -15
- package/data/1.25.0/catalog.json +1 -1
- package/data/1.25.0/manifest.json +8 -6
- package/package.json +1 -1
- package/skills/fine-design/SKILL.md +5 -4
- package/skills/fine-design/references/component-guide.md +4 -0
- package/skills/fine-design/references/imports-and-setup.md +2 -0
- package/skills/fine-design/references/standalone-task-page.md +30 -0
- package/skills/fine-design/references/task-list.js +82 -0
- package/src/cli.mjs +144 -12
- package/src/core/contracts.mjs +10 -1
- package/src/core/figma-data.json +2929 -0
- package/src/core/figma.mjs +138 -0
- package/src/core/html.cjs +12 -10
- package/src/core/lint.mjs +75 -78
- package/src/core/runtime.mjs +59 -2
- package/src/mcp.mjs +9 -1
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"version": "1.25.0",
|
|
4
4
|
"sourceKind": "repository-snapshot",
|
|
5
|
-
"sourceRevision": "
|
|
5
|
+
"sourceRevision": "c9d380a665f17001c406dbb081b1fcd91f6befa7",
|
|
6
6
|
"sourceDirty": false,
|
|
7
|
-
"contentHash": "
|
|
8
|
-
"catalogSha256": "
|
|
7
|
+
"contentHash": "b4069c8284ff843f8824b5685dad688e867eb13622832cedc36cfbe48da584a3",
|
|
8
|
+
"catalogSha256": "63de4489e56aaf268d6363a65f35bd57cede27cd679afba7ae45bcc49ae16500",
|
|
9
9
|
"skillFiles": {
|
|
10
|
-
"references/component-guide.md": "
|
|
10
|
+
"references/component-guide.md": "a91d47075e1c9fc90e8c4a5160e645a4d6ba7d12903688014cd1a22b0c5ef627",
|
|
11
11
|
"references/docs-slug-map.md": "440ce5cf137fd22eabfcc5b51c3f55b85174aa643773ef0cedd5df542e77bbc2",
|
|
12
|
-
"references/imports-and-setup.md": "
|
|
12
|
+
"references/imports-and-setup.md": "12278a80918a003a2285da510a77e77521a2771d47ae7bd0c8ea3f9a181d8398",
|
|
13
|
+
"references/standalone-task-page.md": "97f05c06e1a4e7a9517d53ed6a358d9515d799e1b8c8731cbd50ccf060f3eaea",
|
|
14
|
+
"references/task-list.js": "8e9f7daea7b8a003b0eb4cc1fc510b4a2d37f6812c846c882c01fa23be5adf19",
|
|
13
15
|
"references/theme-and-dark-mode.md": "2eccae4930ea993e7088eee03a4b4a0f1c839033079db5f21f8c60e0fe8168d1",
|
|
14
|
-
"SKILL.md": "
|
|
16
|
+
"SKILL.md": "ad0bb8cf8a588b28e06a2a786483cb54124198a1e2bdf2e99a4c178147cd7968"
|
|
15
17
|
}
|
|
16
18
|
}
|
package/package.json
CHANGED
|
@@ -7,17 +7,17 @@ user-invocable: true
|
|
|
7
7
|
|
|
8
8
|
# Fine Design
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Apply this skill proactively when the task asks for Fine Design pages or touches `@fx-ui/fine-design` / `window.FineDesign` components, including fixes and reviews. Do not wait for a `/fine-design` invocation. Unrelated tasks do not trigger CLI calls. This folder guides AI; generated code must run without resolving skill files.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Use the project-local `npx fine-design` when installed, otherwise the global `fine-design`; fall back to `npx -y @finedesign/cli` when neither is available. On the first Fine Design task in a workspace, run `doctor --format json` unless its result is already available in this session. This Skill is already loaded; do not read it again through `bundledSkillPath`. Reuse discovery and API results while the workspace, CLI and component versions remain unchanged. The public CLI is separate from the private component package; a failed private-package lookup does not prove the CLI is unavailable. Report the actual command and error if it fails.
|
|
13
13
|
|
|
14
14
|
## Workflow
|
|
15
15
|
|
|
16
16
|
1. Identify the deliverable and runtime: existing package-based project, standalone browser page, fix, or read-only review. Standalone HTML and embedded pages may use the public CDN runtime without npm or private-registry credentials. Preserve compatible existing components and explicit user choices; follow [imports-and-setup.md](references/imports-and-setup.md) for runtime selection.
|
|
17
17
|
2. In a package-based project, resolve Fine Design and React versions from installed packages or the lockfile; in this repository use the checked-out package and sources. In browser mode, use the selected runtime manifest and its compatibility evidence rather than requiring an installed package. State unknown versions instead of inventing them or upgrading dependencies to fit examples.
|
|
18
|
-
3.
|
|
18
|
+
3. Before implementation or review conclusions, verify only the relevant components at the exact target version; reuse matching results already read in this session. Prefer connected Fine Design MCP tools when matching-version data is available, or use the CLI with `--format json`. Start with `info <component>`; it includes example IDs, so fetch `example <component> <id>` source only when needed. Use `search` for unknown component names, `doc --toc` / `doc --section` for missing details, and `token` for theming. Do not default to full catalogs, full docs or `--help`. If the version is unknown or unsupported, consult matching local declarations/docs or verify browser exports and behavior. Resolve website pages through [docs-slug-map.md](references/docs-slug-map.md).
|
|
19
19
|
4. Use the relevant sections of [component-guide.md](references/component-guide.md) for component selection and API traps. Consult other references only for the conditions below.
|
|
20
|
-
5.
|
|
20
|
+
5. After code changes, run the existing build/type check (plus `fine-design lint <file>` when available) and verify the affected interaction with local test data. Check that filter wording matches its date/value semantics, primary actions produce their stated results, and filters/actions can be reached by keyboard. Report actual commands and results, distinguishing API lint, DOM tests, independent browser checks, target preview checks and unverified steps. A passing lint is not a business or visual acceptance result. Reviews remain read-only.
|
|
21
21
|
|
|
22
22
|
## Core Contracts
|
|
23
23
|
|
|
@@ -31,4 +31,5 @@ Run `npx -y @finedesign/cli doctor --format json` in the target project and read
|
|
|
31
31
|
| Condition | Reference |
|
|
32
32
|
| --- | --- |
|
|
33
33
|
| Version mismatch, installation failures, unavailable docs, imports, or standalone setup | [imports-and-setup.md](references/imports-and-setup.md) |
|
|
34
|
+
| New standalone table with filters, pagination and draft editing, or offline runtime export | [standalone-task-page.md](references/standalone-task-page.md) |
|
|
34
35
|
| Theme, dark mode, or scoped themes | [theme-and-dark-mode.md](references/theme-and-dark-mode.md) |
|
|
@@ -36,6 +36,7 @@ Use the sections relevant to the task. Selection choices are defaults for new wo
|
|
|
36
36
|
| `Dialog` | Save via `onOk`; handle close/cancel via `onCancel` (clicking the close button triggers `onCancel`, so do not bind the same handler to both `onCancel` and deprecated `onCloseBtnClick`) |
|
|
37
37
|
| `Tag` | Use semantic `type` or `style`; do not assume a `color` prop |
|
|
38
38
|
| `Avatar` | Character fallback uses `name` |
|
|
39
|
+
| `Radio.Group` | Set `tabFocus: true` for keyboard-reachable filters/view switches; its default is false |
|
|
39
40
|
| `SvgIcon`, built-in icons | Import built-in icons from `@fx-ui/fine-design` (56 icons such as `SearchOutlined`, `PlusOutlined`, `EditOutlined`, `DeleteOutlined`, `SyncOutlined`, `RotateOutlined`, `EllipsisOutlined`); verify names via declarations or CLI `search`/`doc` instead of inventing `@ant-design/icons` names like `SettingOutlined` or `ReloadOutlined` |
|
|
40
41
|
|
|
41
42
|
The table declaration differs from common `columns` APIs:
|
|
@@ -64,5 +65,8 @@ render: (_value, record) => {
|
|
|
64
65
|
- Reset page to `1` when filters or page size change, including `AutoComplete.onSearch` and `onChange`. Use the filtered total, and clamp the page after filtering or deletion reduces available pages.
|
|
65
66
|
- Edit a draft separate from saved data. Validation/save failure preserves the draft and leaves the dialog open; cancel/close must not persist the edit. Expose pending/error feedback for asynchronous saves.
|
|
66
67
|
- Verify affected behavior: change a filter from a later page; cancel then confirm removal; submit an invalid draft; cancel an edit; save and reopen another row. Choose checks for the actual change rather than testing every example.
|
|
68
|
+
- Check business wording against actual predicates (calendar week versus rolling days), ensure actions report real results, and verify keyboard access to filters, cards and actions. New multi-project records must select or inherit the intended project. CLI lint does not verify these business contracts.
|
|
69
|
+
|
|
70
|
+
For standalone HTML, see the bundled [task page](standalone-task-page.md). Use shared semantic tokens for page surfaces/text instead of recoloring every component; select exact theme tokens through `token` when needed.
|
|
67
71
|
|
|
68
72
|
For full page patterns in this repository, consult `playground/product-list/index.tsx`. Outside it, reuse local project examples. These are references, not dependencies for single-file outputs.
|
|
@@ -56,6 +56,8 @@ Run `npx -y @finedesign/cli runtime list --format json` first and check its exit
|
|
|
56
56
|
3. The host retains only the current release files. Old URLs may disappear on upgrade; save matching resources yourself for long-lived standalone pages. Do not claim historical runtime availability from the CLI's offline catalog.
|
|
57
57
|
4. If the manifest cannot be retrieved, report the failure and use an explicitly selected verified host or previously saved matching resources. The old unversioned website resources have been removed; do not fall back to them or substitute another component version.
|
|
58
58
|
|
|
59
|
+
For offline or CSP-restricted previews, use `fine-design runtime --fd-version <exact-version> --output ./demo` with a new destination directory. `--dry-run --format json` previews file paths. The export verifies sizes/SHA-256 before writing local resources, preserves SRI and records their remote provenance in `runtime-lock.json`; it also includes a working [task page](standalone-task-page.md). Initial export needs network access; subsequent pages reference only local resources. The host must still permit page scripts/styles. Existing destinations are rejected rather than overwritten.
|
|
60
|
+
|
|
59
61
|
Load `fineDesignCss`, then `react`, `reactDOM`, `fineDesign`. Pin exact URLs and integrity in generated HTML and use `crossorigin="anonymous"`; the host must provide CORS. Do not drop SRI from a selected versioned runtime to hide an error. Avoid async scripts and conflicting second React instances. If an embedding host lacks compatible React globals, use a separate document/iframe.
|
|
60
62
|
|
|
61
63
|
Use `--runtime-url <verified-base-url>` only for a clearly selected host. The default public host is `https://fine-design-runtime.pages.dev/`, verified after production deployment; local testing alone does not prove a host is live. Optional chart resources are loaded only for chart requests.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Standalone Task Page
|
|
2
|
+
|
|
3
|
+
Use this reference for a new standalone table with filters, pagination and draft editing. Preserve existing project components instead of replacing them with this sample.
|
|
4
|
+
|
|
5
|
+
After discovering the hosted version, run:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
fine-design runtime --fd-version <exact-version> --output ./task-demo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The destination must not exist. `--dry-run --format json` previews paths without downloading assets or writing files. Export downloads the four required resources once, checks their declared sizes and SHA-256, then installs the directory. Download, integrity or conflict failures leave the destination untouched. The current browser starter uses React 18's `createRoot`; verify compatibility when targeting a different React major.
|
|
12
|
+
|
|
13
|
+
- `index.html`: existing button/runtime smoke example.
|
|
14
|
+
- `task-list.html` and `task-list.js`: working local task example. No JSX transformer or extra dependency.
|
|
15
|
+
- `vendor/`: pinned React, ReactDOM, Fine Design JavaScript and stylesheet.
|
|
16
|
+
- `runtime-lock.json`: source manifest URL, exact resource metadata and local paths. This is an archive record, not a hosting manifest.
|
|
17
|
+
|
|
18
|
+
Use the target host's normal local preview. Resource URLs are local and SRI is retained; the host must still permit the page's scripts and styles. No CDN fallback is needed for an exported directory. Keep the whole directory together when copying it.
|
|
19
|
+
|
|
20
|
+
The complete [task-list.js](task-list.js) is also bundled with this Skill. It is a reference, not a runtime dependency: copy it into the deliverable before linking it. Its component is `window.FineDesignTaskList`; mount it after the runtime is loaded. The example stores status codes consistently, enables Radio keyboard focus, labels text inputs, keeps edits in a separate draft, and binds deletion to `PopConfirm.onOk`.
|
|
21
|
+
|
|
22
|
+
## Verify The Business Contract
|
|
23
|
+
|
|
24
|
+
1. From a later page, filter by keyword/status and reset; verify the matching rows and page number.
|
|
25
|
+
2. Create a task, reject an empty name, save a valid task, edit it, cancel an edit, then reopen it.
|
|
26
|
+
3. Cancel deletion, then confirm deletion; remove the last row on a later page and verify pagination clamps.
|
|
27
|
+
4. Use Tab and the component's supported keys to reach filters and actions; check focus and the actual accessible names in the target preview.
|
|
28
|
+
5. For extensions, define calendar-week versus rolling-date semantics explicitly. An export action must create a file or report a real result; mark intentionally unfinished actions. If tasks belong to multiple projects, new tasks must select or inherit the intended project.
|
|
29
|
+
|
|
30
|
+
CLI lint checks API usage, not business correctness, accessibility compliance or visual layout. Report syntax/API tests, DOM behavior tests and actual browser/host checks separately. DOM-only checks cannot verify clipping, colors or responsive layout.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* 独立页面组合参考:运行时加载后用 React.createElement(window.FineDesignTaskList) 渲染。 */
|
|
2
|
+
window.FineDesignTaskList = function FineDesignTaskList() {
|
|
3
|
+
const React = window.React;
|
|
4
|
+
const h = React.createElement;
|
|
5
|
+
const { Button, Input, Select, Radio, NextTable, Pagination, Drawer, PopConfirm, Tag } = window.FineDesign;
|
|
6
|
+
const [rows, setRows] = React.useState([
|
|
7
|
+
{ id: 1, name: '整理需求', status: 'todo' },
|
|
8
|
+
{ id: 2, name: '接口联调', status: 'doing' },
|
|
9
|
+
{ id: 3, name: '组件验收', status: 'done' },
|
|
10
|
+
{ id: 4, name: '补充用例', status: 'todo' },
|
|
11
|
+
{ id: 5, name: '检查交付', status: 'doing' }
|
|
12
|
+
]);
|
|
13
|
+
const [keyword, setKeyword] = React.useState('');
|
|
14
|
+
const [status, setStatus] = React.useState('all');
|
|
15
|
+
const [page, setPage] = React.useState(1);
|
|
16
|
+
const [size, setSize] = React.useState(2);
|
|
17
|
+
const [draft, setDraft] = React.useState(null);
|
|
18
|
+
const [error, setError] = React.useState('');
|
|
19
|
+
const statuses = [{ label: '待规划', value: 'todo' }, { label: '进行中', value: 'doing' }, { label: '已完成', value: 'done' }];
|
|
20
|
+
const filtered = rows.filter(row => (status === 'all' || row.status === status) && row.name.includes(keyword.trim()));
|
|
21
|
+
const maxPage = Math.max(1, Math.ceil(filtered.length / size));
|
|
22
|
+
React.useEffect(() => { if (page > maxPage) setPage(maxPage); }, [page, maxPage]);
|
|
23
|
+
|
|
24
|
+
function edit(row) { setDraft({ ...row }); setError(''); }
|
|
25
|
+
function close() { setDraft(null); setError(''); }
|
|
26
|
+
function save() {
|
|
27
|
+
const name = draft.name.trim();
|
|
28
|
+
if (!name) { setError('请填写任务名称'); return; }
|
|
29
|
+
const saved = { ...draft, name, id: draft.id ?? Math.max(0, ...rows.map(row => row.id)) + 1 };
|
|
30
|
+
setRows(draft.id == null ? [saved, ...rows] : rows.map(row => row.id === saved.id ? saved : row));
|
|
31
|
+
if (draft.id == null) setPage(1);
|
|
32
|
+
close();
|
|
33
|
+
}
|
|
34
|
+
function column(title, width, render) {
|
|
35
|
+
return h(NextTable.Column, { width }, h(NextTable.HeaderCell, null, title),
|
|
36
|
+
h(NextTable.Cell, null, row => row?.id != null ? render(row) : null));
|
|
37
|
+
}
|
|
38
|
+
const fieldStyle = { display: 'grid', gap: 8 };
|
|
39
|
+
return h('div', { style: { display: 'grid', gap: 16, padding: 20, color: 'var(--fd-color-text)' } },
|
|
40
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 12 } },
|
|
41
|
+
h('strong', { 'aria-live': 'polite' }, '任务清单 · ' + filtered.length + ' 项'),
|
|
42
|
+
h(Button, { type: 'primary', onClick: () => edit({ id: null, name: '', status: 'todo' }) }, '新建任务')),
|
|
43
|
+
h('label', { style: fieldStyle }, '任务关键词', h(Input, {
|
|
44
|
+
value: keyword, placeholder: '输入任务名称', allowClear: true,
|
|
45
|
+
onChange: value => { setKeyword(value); setPage(1); }
|
|
46
|
+
})),
|
|
47
|
+
h(Radio.Group, { value: status, tabFocus: true, direction: 'horizontal', optionType: 'button', block: false,
|
|
48
|
+
onChange: value => { setStatus(value); setPage(1); }
|
|
49
|
+
}, [{ label: '全部任务', value: 'all' }, ...statuses].map(item => h(Radio, { key: item.value, value: item.value }, item.label))),
|
|
50
|
+
h(Button, { onClick: () => { setKeyword(''); setStatus('all'); setPage(1); } }, '重置筛选'),
|
|
51
|
+
h('div', { style: { overflowX: 'auto', minWidth: 0 } }, h(NextTable, {
|
|
52
|
+
data: filtered.slice((page - 1) * size, page * size), rowKey: 'id', width: 780, autoHeight: true, fillHeight: false,
|
|
53
|
+
renderEmpty: () => h('p', null, '暂无符合条件的任务')
|
|
54
|
+
},
|
|
55
|
+
column('编号', 100, row => String(row.id)),
|
|
56
|
+
column('名称', 340, row => row.name),
|
|
57
|
+
column('状态', 140, row => h(Tag, { type: row.status === 'done' ? 'success' : 'info' }, statuses.find(item => item.value === row.status).label)),
|
|
58
|
+
column('操作', 200, row => h('div', { style: { display: 'flex', gap: 8 } },
|
|
59
|
+
h(Button, { type: 'text', onClick: () => edit(row) }, '编辑'),
|
|
60
|
+
h(PopConfirm, { content: '确认删除“' + row.name + '”?', text4Ok: '确认删除', text4Cancel: '取消',
|
|
61
|
+
onOk: () => setRows(rows.filter(item => item.id !== row.id))
|
|
62
|
+
}, h(Button, { type: 'text', danger: true }, '删除'))))
|
|
63
|
+
)),
|
|
64
|
+
h(Pagination, { page, size, sizeSet: [2, 5], count: filtered.length, showPageSize: value => value + ' 条/页',
|
|
65
|
+
showTotal: count => '共 ' + count + ' 项', onPageChange: setPage,
|
|
66
|
+
onSizeChange: value => { setSize(value); setPage(1); }
|
|
67
|
+
}),
|
|
68
|
+
draft && h(Drawer, { visible: true, placement: 'right', edge: { width: 'min(520px, 100vw)', top: 0 },
|
|
69
|
+
title: draft.id == null ? '新建任务' : '编辑任务', onClose: close,
|
|
70
|
+
footer: h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } },
|
|
71
|
+
h(Button, { onClick: close }, '取消'), h(Button, { type: 'primary', onClick: save }, '保存'))
|
|
72
|
+
}, h('div', { style: { display: 'grid', gap: 16 } },
|
|
73
|
+
h('label', { style: fieldStyle }, '任务名称(必填)', h(Input, { value: draft.name,
|
|
74
|
+
inputState: error ? 'error' : 'normal', onChange: value => { setDraft({ ...draft, name: value }); setError(''); }
|
|
75
|
+
})),
|
|
76
|
+
error && h('p', { role: 'alert' }, error),
|
|
77
|
+
h('div', { style: fieldStyle }, h('span', null, '任务状态'), h(Select, { value: draft.status, options: statuses, 'aria-label': '任务状态',
|
|
78
|
+
onChange: value => setDraft({ ...draft, status: value })
|
|
79
|
+
})))
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
};
|
package/src/cli.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { validateInput } from './core/contracts.mjs';
|
|
|
7
7
|
import { loadCatalog, readIndex } from './core/data.mjs';
|
|
8
8
|
import { resolveLintVersion, resolveVersion } from './core/version.mjs';
|
|
9
9
|
import { ToolError, errorResult } from './core/errors.mjs';
|
|
10
|
-
import { listRuntimes, resolveRuntime } from './core/runtime.mjs';
|
|
10
|
+
import { listRuntimes, resolveRuntime, exportRuntime } from './core/runtime.mjs';
|
|
11
11
|
import html from './core/html.cjs';
|
|
12
12
|
|
|
13
13
|
const help = `Usage: fine-design <command> [arguments] [options]
|
|
@@ -25,6 +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 or list Code Connect mappings
|
|
28
29
|
mcp Start the stdio MCP server
|
|
29
30
|
|
|
30
31
|
Options:
|
|
@@ -32,11 +33,11 @@ Options:
|
|
|
32
33
|
--project <directory> Project used to detect the installed version
|
|
33
34
|
--component <name> Compare only this component (diff command only)
|
|
34
35
|
--agent <cursor|claude|codex|all> Target agent configuration (init command only)
|
|
35
|
-
--output <directory> Destination
|
|
36
|
+
--output <directory> Destination for an example or offline runtime (add and runtime)
|
|
36
37
|
--force Update managed files or overwrite examples (init and add)
|
|
37
|
-
--dry-run Preview changes without writing (init and
|
|
38
|
+
--dry-run Preview changes without writing (init, add and runtime --output)
|
|
38
39
|
--runtime-url <url> Runtime hosting base URL (runtime command only)
|
|
39
|
-
--format <text|json|markdown|html> Output format (markdown: doc/info/token; html: runtime)
|
|
40
|
+
--format <text|json|markdown|html> Output format (markdown: doc/info/token/figma; html: runtime)
|
|
40
41
|
--section <heading> Doc section heading (exact or case-insensitive)
|
|
41
42
|
--toc, --summary Show only doc metadata, section headings and example IDs
|
|
42
43
|
--offset <number> Search pagination offset
|
|
@@ -115,12 +116,12 @@ function runInit(values) {
|
|
|
115
116
|
|
|
116
117
|
const agentInstructions = `# Fine Design Rules
|
|
117
118
|
|
|
118
|
-
开发或修改 Fine Design
|
|
119
|
+
开发或修改 Fine Design 页面时,以及调试或评审涉及 \`@fx-ui/fine-design\` / \`window.FineDesign\` 的代码时,主动调用 CLI 核对组件 API,无需用户提醒。无关任务不触发。在目标工作目录运行:项目内已安装 CLI 时用 \`npx fine-design\`,否则使用全局 \`fine-design\`;两者均不可用时用 \`npx -y @finedesign/cli\`。
|
|
119
120
|
|
|
120
|
-
1.
|
|
121
|
+
1. 首次处理当前工作目录的 Fine Design 任务时,运行 \`doctor --format json\`,读取 \`bundledSkillPath\` 指向的 Skill;当前会话已加载则复用,不重复读取。同一工作目录、CLI 和组件版本未变化时复用诊断结果。先确定交付形式;接入现有 React 工程时沿用项目组件版本、壳层和同类页面。
|
|
121
122
|
2. 交付独立 HTML 或无构建预览时,先单独运行 \`runtime list --format json\`,根据退出码判断清单是否可用。用 \`versions\` 返回的版本解析 UMD 资源,再查组件 API。
|
|
122
|
-
3.
|
|
123
|
-
4.
|
|
123
|
+
3. 实现或给出评审结论前,按目标版本用 \`info <组件> --format json\` 核对本次涉及的 API。同一版本已查资料可复用;组件不明确时才 \`search\`,需要示例时从 \`info\` 返回的 ID 读取源码,不默认运行全量 \`list\` 或读取全部文档。
|
|
124
|
+
4. 有代码改动时,对改动文件运行 \`lint\` 并执行项目已有检查,验证受影响交互。分别记录实际执行的命令、检查结果和未验证项;只读评审不修改代码。
|
|
124
125
|
5. CLI 与私有组件包是独立的;本地命令缺失或私有包查询失败不能证明公开 CLI 不存在。失败时记录实际命令、退出码和错误。真实组件不可用时,原生页面只能标为替代实现,不能声称通过官方 lint;若必须使用真实组件则报告阻碍。
|
|
125
126
|
`;
|
|
126
127
|
|
|
@@ -319,17 +320,148 @@ export async function main(argv) {
|
|
|
319
320
|
if (command !== 'runtime' && (values['runtime-url'] !== undefined)) throw new ToolError('INVALID_ARGUMENT', 'Runtime options are only supported for runtime.', 2);
|
|
320
321
|
if (command !== 'diff' && values.component !== undefined) throw new ToolError('INVALID_ARGUMENT', '--component is only supported for diff.', 2);
|
|
321
322
|
if (command !== 'init' && values.agent !== undefined) throw new ToolError('INVALID_ARGUMENT', '--agent is only supported for init.', 2);
|
|
322
|
-
if (
|
|
323
|
+
if (!['add', 'runtime'].includes(command) && values.output !== undefined) throw new ToolError('INVALID_ARGUMENT', '--output is only supported for add and runtime.', 2);
|
|
323
324
|
if (!['init', 'add'].includes(command) && values.force !== undefined) throw new ToolError('INVALID_ARGUMENT', '--force is only supported for init and add.', 2);
|
|
324
|
-
if (!['init', 'add'].includes(command) && values['dry-run'] !== undefined) throw new ToolError('INVALID_ARGUMENT', '--dry-run is only supported for init and
|
|
325
|
-
if (format === 'markdown' && !['doc', 'info', 'token'].includes(command)) {
|
|
326
|
-
throw new ToolError('INVALID_ARGUMENT', 'Markdown output format is only supported for the doc, info and
|
|
325
|
+
if (!['init', 'add', 'runtime'].includes(command) && values['dry-run'] !== undefined) throw new ToolError('INVALID_ARGUMENT', '--dry-run is only supported for init, add and runtime --output.', 2);
|
|
326
|
+
if (format === 'markdown' && !['doc', 'info', 'token', 'figma'].includes(command)) {
|
|
327
|
+
throw new ToolError('INVALID_ARGUMENT', 'Markdown output format is only supported for the doc, info, token and figma commands.', 2);
|
|
327
328
|
}
|
|
328
329
|
if (format === 'html' && (command !== 'runtime' || args.length)) throw new ToolError('INVALID_ARGUMENT', 'HTML output format is only supported for runtime resolution.', 2);
|
|
330
|
+
if (command === 'figma') {
|
|
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);
|
|
334
|
+
}
|
|
335
|
+
if (values.version || values.section !== undefined || summaryFlag || values.offset !== undefined || values.limit !== undefined || values['include-assets'] !== undefined || values['fd-version'] !== undefined) {
|
|
336
|
+
throw new ToolError('INVALID_ARGUMENT', 'Invalid options for figma command. Use --help for usage.', 2);
|
|
337
|
+
}
|
|
338
|
+
if (sub === 'list') {
|
|
339
|
+
if (args.length > 1) {
|
|
340
|
+
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma list [--format text|json|markdown]', 2);
|
|
341
|
+
}
|
|
342
|
+
const { listFigmaComponents } = await import('./core/figma.mjs');
|
|
343
|
+
const result = listFigmaComponents();
|
|
344
|
+
if (format === 'json') {
|
|
345
|
+
console.log(JSON.stringify(result));
|
|
346
|
+
} else if (format === 'markdown') {
|
|
347
|
+
const rows = result.components.map((c) => `| \`${c.component}\` | \`${c.designName}\` | \`${c.nodeId}\` | \`${c.templateId}\` |`);
|
|
348
|
+
console.log([
|
|
349
|
+
`# Fine Design 已连接 Figma 组件 (${result.total})`,
|
|
350
|
+
`文件 Key: \`${result.fileKey}\``,
|
|
351
|
+
'',
|
|
352
|
+
'| 组件 | 设计名称 | Node ID | Code Connect ID |',
|
|
353
|
+
'| --- | --- | --- | --- |',
|
|
354
|
+
...rows
|
|
355
|
+
].join('\n'));
|
|
356
|
+
} else {
|
|
357
|
+
const lines = result.components.map((c) => ` ${c.component.padEnd(20)} ${c.nodeId.padEnd(16)} ${c.templateId.padEnd(28)} ${c.designName}`);
|
|
358
|
+
console.log([
|
|
359
|
+
`Fine Design Connected Figma Components (${result.total}):`,
|
|
360
|
+
`File Key: ${result.fileKey}`,
|
|
361
|
+
'',
|
|
362
|
+
...lines
|
|
363
|
+
].join('\n'));
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (sub === 'resolve') {
|
|
368
|
+
if (args.length !== 2) {
|
|
369
|
+
throw new ToolError('INVALID_ARGUMENT', 'Usage: fine-design figma resolve <url-or-nodeId-or-component> [--format text|json|markdown]', 2);
|
|
370
|
+
}
|
|
371
|
+
const target = args[1];
|
|
372
|
+
const { resolveFigmaComponent } = await import('./core/figma.mjs');
|
|
373
|
+
const result = resolveFigmaComponent({ target });
|
|
374
|
+
if (format === 'json') {
|
|
375
|
+
console.log(JSON.stringify(result));
|
|
376
|
+
} else if (format === 'markdown') {
|
|
377
|
+
if (result.matched) {
|
|
378
|
+
console.log([
|
|
379
|
+
`# ${result.component} (\`${result.nodeId}\`) - ${result.designName}`,
|
|
380
|
+
`- **Figma URL**: [${result.nodeId}](${result.url})`,
|
|
381
|
+
`- **Code Connect ID**: \`${result.codeConnect.templateId}\` (\`${result.codeConnect.templateFile}\`)`,
|
|
382
|
+
...(result.codeConnect.shortcut ? [`- **注意项**: ${result.codeConnect.shortcut}`] : []),
|
|
383
|
+
...(result.codeConnect.businessInputs ? [`- **业务参数**: ${result.codeConnect.businessInputs}`] : []),
|
|
384
|
+
'',
|
|
385
|
+
'## 导入语句',
|
|
386
|
+
'```tsx',
|
|
387
|
+
...result.codeConnect.imports,
|
|
388
|
+
'```',
|
|
389
|
+
...(result.codeConnect.wrapperSignature ? ['', '## 包装函数签名', '```ts', result.codeConnect.wrapperSignature, '```'] : []),
|
|
390
|
+
...(result.codeConnect.exampleSnippet ? [
|
|
391
|
+
'',
|
|
392
|
+
'## 参考示例',
|
|
393
|
+
...(result.codeConnect.exampleNodeId ? [`采样节点 ${result.codeConnect.exampleNodeId}`] : []),
|
|
394
|
+
'```tsx',
|
|
395
|
+
...(result.codeConnect.exampleImports ?? []),
|
|
396
|
+
result.codeConnect.exampleSnippet,
|
|
397
|
+
'```'
|
|
398
|
+
] : []),
|
|
399
|
+
...(result.recommendations.length ? ['', '## 最佳实践与避坑指引', ...result.recommendations.map((r) => `- ${r}`)] : []),
|
|
400
|
+
'',
|
|
401
|
+
`> 更多组件 API 详情请运行: \`${result.apiDocHint}\``
|
|
402
|
+
].join('\n'));
|
|
403
|
+
} else if (result.unmapped) {
|
|
404
|
+
console.log([
|
|
405
|
+
`# ${result.component} (未连接组件)`,
|
|
406
|
+
result.note,
|
|
407
|
+
'',
|
|
408
|
+
`> 代码侧请运行: \`${result.apiDocHint}\``
|
|
409
|
+
].join('\n'));
|
|
410
|
+
} else {
|
|
411
|
+
console.log([
|
|
412
|
+
`# 未找到匹配组件: "${target}"`,
|
|
413
|
+
result.message,
|
|
414
|
+
...(result.suggestions ? ['', '推荐搜索:', ...result.suggestions.map((s) => `- ${s}`)] : [])
|
|
415
|
+
].join('\n'));
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
if (result.matched) {
|
|
419
|
+
const lines = [
|
|
420
|
+
`Component: ${result.component} (${result.designName})`,
|
|
421
|
+
`Figma Node: ${result.nodeId}`,
|
|
422
|
+
`Figma URL: ${result.url}`,
|
|
423
|
+
`Code Connect ID: ${result.codeConnect.templateId} (${result.codeConnect.templateFile})`,
|
|
424
|
+
'Imports:',
|
|
425
|
+
...result.codeConnect.imports.map((i) => ` ${i}`),
|
|
426
|
+
...(result.codeConnect.shortcut ? [`Shortcut: ${result.codeConnect.shortcut}`] : []),
|
|
427
|
+
...(result.codeConnect.businessInputs ? [`Business Inputs: ${result.codeConnect.businessInputs}`] : []),
|
|
428
|
+
...(result.codeConnect.wrapperSignature ? ['Wrapper Signature:', ` ${result.codeConnect.wrapperSignature}`] : []),
|
|
429
|
+
...(result.codeConnect.exampleSnippet ? [
|
|
430
|
+
result.codeConnect.exampleNodeId ? `Reference Example (sample node ${result.codeConnect.exampleNodeId}):` : 'Reference Example:',
|
|
431
|
+
...(result.codeConnect.exampleImports ?? []).map((line) => ` ${line}`),
|
|
432
|
+
` ${result.codeConnect.exampleSnippet.split('\n').join('\n ')}`
|
|
433
|
+
] : []),
|
|
434
|
+
...(result.recommendations.length ? ['Recommendations:', ...result.recommendations.map((r) => ` - ${r}`)] : []),
|
|
435
|
+
`API Docs: ${result.apiDocHint}`
|
|
436
|
+
];
|
|
437
|
+
console.log(lines.join('\n'));
|
|
438
|
+
} else if (result.unmapped) {
|
|
439
|
+
console.log([
|
|
440
|
+
`Component: ${result.component} (Unmapped)`,
|
|
441
|
+
`Note: ${result.note}`,
|
|
442
|
+
`API Docs: ${result.apiDocHint}`
|
|
443
|
+
].join('\n'));
|
|
444
|
+
} else {
|
|
445
|
+
console.log([
|
|
446
|
+
result.message,
|
|
447
|
+
...(result.suggestions ? ['Suggestions:', ...result.suggestions.map((s) => ` - ${s}`)] : [])
|
|
448
|
+
].join('\n'));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (!result.matched && !result.unmapped) process.exitCode = 1;
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
329
455
|
if (command === 'runtime') {
|
|
330
456
|
const list = args.length === 1 && args[0] === 'list';
|
|
331
457
|
if ((!list && args.length) || values.version || values.section !== undefined || summaryFlag || values.offset !== undefined || values.limit !== undefined || values['include-assets'] !== undefined || (list && (values['fd-version'] !== undefined || values.project !== undefined))) throw new ToolError('INVALID_ARGUMENT', 'Use runtime [list] with --fd-version and --runtime-url as applicable.', 2);
|
|
458
|
+
if ((list && (values.output !== undefined || values['dry-run'] !== undefined)) || (values['dry-run'] !== undefined && values.output === undefined) || (values.output !== undefined && (!values.output.trim() || !['text', 'json'].includes(format)))) throw new ToolError('INVALID_ARGUMENT', 'Use runtime --output <new-directory> [--dry-run] [--format text|json].', 2);
|
|
332
459
|
const result = list ? await listRuntimes(values['runtime-url']) : await resolveRuntime({ version: resolveVersion(values['fd-version'], values.project), runtimeURL: values['runtime-url'] });
|
|
460
|
+
if (values.output !== undefined) {
|
|
461
|
+
const report = await exportRuntime(result, path.resolve(values.project || process.cwd(), values.output), Boolean(values['dry-run']));
|
|
462
|
+
console.log(format === 'json' ? JSON.stringify(report) : `${report.dryRun ? 'Preview' : 'Exported'} Fine Design ${report.version} to ${report.targetDir}:\n${report.plannedFiles.map((name) => ` ${name}`).join('\n')}`);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
333
465
|
console.log(format === 'html' ? html.exampleHTML(result.resources, './').trimEnd() : format === 'json' ? JSON.stringify(result) : list ? result.versions.join('\n') : `Fine Design ${result.version} (offline docs: ${result.docsAvailable ? 'available' : 'not bundled'})\n${result.tags}\nExample: ${result.exampleURL}`);
|
|
334
466
|
return;
|
|
335
467
|
}
|
package/src/core/contracts.mjs
CHANGED
|
@@ -47,7 +47,16 @@ export const schemas = {
|
|
|
47
47
|
}).strict().refine(({ exampleId, includeAssets }) => exampleId !== undefined || includeAssets === undefined, {
|
|
48
48
|
path: ['includeAssets'],
|
|
49
49
|
message: 'includeAssets requires an example ID.'
|
|
50
|
-
})
|
|
50
|
+
}),
|
|
51
|
+
resolve_figma_component: z.object({
|
|
52
|
+
target: z.string().min(1).max(2048).optional().describe('Fine Design library node URL, library node ID (e.g. 100:4283), or component name'),
|
|
53
|
+
url: z.string().min(1).max(2048).optional().describe('Mapped node URL in the Fine Design library. Use Figma MCP to locate the main component for a page or instance first.'),
|
|
54
|
+
nodeId: z.string().min(1).max(100).optional().describe('Fine Design library node ID (e.g. "100:4283" or "100-4283")'),
|
|
55
|
+
component: z.string().min(1).max(100).optional().describe('Component name (e.g. "Button", "NextTable", "Dialog")')
|
|
56
|
+
}).strict().refine((data) => data.target || data.url || data.nodeId || data.component, {
|
|
57
|
+
message: 'Provide at least one of target, url, nodeId, or component.'
|
|
58
|
+
}),
|
|
59
|
+
list_figma_components: z.object({}).strict()
|
|
51
60
|
};
|
|
52
61
|
|
|
53
62
|
export function validateInput(tool, input) {
|