antd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ant Design CLI

Ant Design CLI

You have access to
@ant-design/cli
— a local CLI tool with bundled antd metadata for v4/v5/v6. Use it to query component knowledge, analyze projects, and guide migrations. All data is offline, no network needed.
你可以使用
@ant-design/cli
——一款本地CLI工具,内置了v4/v5/v6版本的antd元数据。可用于查询组件知识、分析项目以及指导版本迁移。所有数据均为离线存储,无需网络。

Setup

安装配置

Before first use, check if the CLI is installed. If not, install it automatically:
bash
which antd || npm install -g @ant-design/cli
After running any command, if the output contains an "Update available" notice, run
npm install -g @ant-design/cli
to update before continuing.
Always use
--format json
for structured output you can parse programmatically.
首次使用前,请检查CLI是否已安装。如果未安装,请自动安装:
bash
which antd || npm install -g @ant-design/cli
运行任意命令后,如果输出中包含“Update available”(可用更新)提示,请先运行
npm install -g @ant-design/cli
进行更新,然后再继续操作。
请始终使用
--format json
参数以获得可通过编程解析的结构化输出。

Scenarios

使用场景

1. Writing antd component code

1. 编写antd组件代码

Before writing any antd component code, look up its API first — don't rely on memory.
bash
undefined
在编写任何antd组件代码之前,请先查阅其API——不要凭记忆猜测。
bash
undefined

Check what props are available

查看可用属性

antd info Button --format json
antd info Button --format json

Get a working demo as starting point

获取可用的示例作为开发起点

antd demo Button basic --format json
antd demo Button basic --format json

Check semantic classNames/styles for custom styling

查看用于自定义样式的语义化类名/样式

antd semantic Button --format json
antd semantic Button --format json

Check component-level design tokens for theming

查看用于主题定制的组件级设计令牌

antd token Button --format json

**Workflow:** `antd info` → understand props → `antd demo` → grab a working example → write code.
antd token Button --format json

**工作流程:** `antd info` → 了解组件属性 → `antd demo` → 获取可用示例 → 编写代码。

2. Looking up full documentation

2. 查阅完整文档

When you need comprehensive component docs (not just props):
bash
antd doc Table --format json        # full markdown docs for Table
antd doc Table --lang zh            # Chinese docs
当你需要组件的完整文档(不仅仅是属性)时:
bash
antd doc Table --format json        # Table组件的完整Markdown文档
antd doc Table --lang zh            # 中文文档

3. Debugging antd issues

3. 调试antd问题

When code isn't working as expected or the user reports an antd bug:
bash
undefined
当代码未按预期运行或用户反馈antd相关Bug时:
bash
undefined

Check if the prop exists for the user's antd version

检查该属性在用户使用的antd版本中是否存在

antd info Select --version 5.12.0 --format json
antd info Select --version 5.12.0 --format json

Check if the prop is deprecated

检查属性是否已被废弃

antd lint ./src/components/MyForm.tsx --format json
antd lint ./src/components/MyForm.tsx --format json

Diagnose project-level configuration issues

诊断项目级配置问题

antd doctor --format json

**Workflow:** `antd doctor` → check environment → `antd info --version X` → verify API against the user's exact version → `antd lint` → find deprecated or incorrect usage.
antd doctor --format json

**工作流程:** `antd doctor` → 检查环境 → `antd info --version X` → 对照用户使用的具体版本验证API → `antd lint` → 找出已废弃或错误的用法。

4. Migrating between versions

4. 版本间迁移

When the user wants to upgrade antd (e.g., v4 → v5):
bash
undefined
当用户想要升级antd版本(例如从v4升级到v5)时:
bash
undefined

Get full migration checklist

获取完整的迁移清单

antd migrate 4 5 --format json
antd migrate 4 5 --format json

Check migration for a specific component

查看特定组件的迁移指南

antd migrate 4 5 --component Select --format json
antd migrate 4 5 --component Select --format json

See what changed between two versions

查看两个版本之间的变更内容

antd changelog 4.24.0 5.0.0 --format json
antd changelog 4.24.0 5.0.0 --format json

See changes for a specific component

查看特定组件的版本变更

antd changelog 4.24.0 5.0.0 Select --format json

**Workflow:** `antd migrate` → get full checklist → `antd changelog <v1> <v2>` → understand breaking changes → apply fixes → `antd lint` → verify no deprecated usage remains.
antd changelog 4.24.0 5.0.0 Select --format json

**工作流程:** `antd migrate` → 获取完整迁移清单 → `antd changelog <v1> <v2>` → 了解破坏性变更 → 应用修复 → `antd lint` → 验证是否存在已废弃的用法。

5. Analyzing project antd usage

5. 分析项目中antd的使用情况

When the user wants to understand how antd is used in their project:
bash
undefined
当用户想要了解项目中antd的使用方式时:
bash
undefined

Scan component usage statistics

扫描组件使用统计数据

antd usage ./src --format json
antd usage ./src --format json

Filter to a specific component

过滤查看特定组件的使用情况

antd usage ./src --filter Form --format json
antd usage ./src --filter Form --format json

Lint for best practice violations

检查是否违反最佳实践

antd lint ./src --format json
antd lint ./src --format json

Check only specific rule categories

仅检查特定规则类别

antd lint ./src --only deprecated --format json antd lint ./src --only a11y --format json antd lint ./src --only performance --format json
undefined
antd lint ./src --only deprecated --format json antd lint ./src --only a11y --format json antd lint ./src --only performance --format json
undefined

6. Checking changelogs and version history

6. 查看更新日志和版本历史

When the user asks about what changed in a version:
bash
undefined
当用户询问某个版本的变更内容时:
bash
undefined

Specific version changelog

特定版本的更新日志

antd changelog 5.22.0 --format json
antd changelog 5.22.0 --format json

Version range (both ends inclusive)

版本范围(包含两端版本)

antd changelog 5.21.0..5.24.0 --format json
undefined
antd changelog 5.21.0..5.24.0 --format json
undefined

7. Exploring available components

7. 探索可用组件

When the user is choosing which component to use:
bash
undefined
当用户需要选择合适的组件时:
bash
undefined

List all components with categories

查看所有带分类的组件

antd list --format json
antd list --format json

List components for a specific antd version

查看特定antd版本的可用组件

antd list --version 5.0.0 --format json
undefined
antd list --version 5.0.0 --format json
undefined

8. Reporting antd bugs

8. 上报antd Bug

When you encounter a confirmed antd component bug that can't be resolved locally:
bash
undefined
当你遇到确认无法在本地解决的antd组件Bug时:
bash
undefined

Step 1: Preview for user review

步骤1:生成预览版供用户查看

antd bug --title "DatePicker crashes when selecting date"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. Open DatePicker 2. Click a date"
--expected "Date is selected"
--actual "Component crashes with error"
--format json
antd bug --title "DatePicker crashes when selecting date"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. Open DatePicker 2. Click a date"
--expected "Date is selected"
--actual "Component crashes with error"
--format json

Step 2: Show to user, ask for confirmation

步骤2:展示给用户,请求确认

Step 3: Submit after user confirms

步骤3:用户确认后提交

antd bug --title "DatePicker crashes when selecting date"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. Open DatePicker 2. Click a date"
--expected "Date is selected"
--actual "Component crashes with error"
--submit
undefined
antd bug --title "DatePicker crashes when selecting date"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. Open DatePicker 2. Click a date"
--expected "Date is selected"
--actual "Component crashes with error"
--submit
undefined

9. Auto-reporting CLI issues

9. 自动上报CLI问题

IMPORTANT: Whenever you use any
antd
CLI command and notice something wrong, you should proactively initiate a bug report using
antd bug-cli
.
Trigger conditions — report a CLI bug when you observe any of these:
  • A command crashes or exits with an unexpected error
  • A command returns clearly incorrect data (e.g.
    antd info Button
    shows wrong props, missing props, or props from the wrong version)
  • A command's output doesn't match its documented behavior (e.g.
    --format json
    returns non-JSON,
    --version X
    is ignored)
  • A command returns empty or missing data when it shouldn't (e.g.
    antd demo Button
    returns no demos,
    antd token Button
    returns no tokens for v5+)
  • Inconsistencies between commands (e.g.
    antd list
    shows a component but
    antd info
    says it doesn't exist)
Workflow:
  1. You notice something wrong while using the CLI
  2. Gather evidence: the exact command you ran, what was returned, and what you expected
  3. Preview the bug report for the user:
bash
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
  --description "When querying Button props for version 5.12.0, the output includes props that don't exist in that version" \
  --steps "1. Run: antd info Button --version 5.12.0 --format json" \
  --expected "Props matching antd 5.12.0 Button API" \
  --actual "Props include 'classNames' which was added in 5.16.0" \
  --format json
  1. Show the report to the user: "I noticed an issue with the CLI while working. Here's a bug report — shall I submit it?"
  2. Submit after user confirms:
bash
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
  --description "..." \
  --steps "..." \
  --expected "..." \
  --actual "..." \
  --submit
Key principle: You are a quality feedback loop for the CLI. Don't silently work around CLI issues — report them so they get fixed. Always confirm with the user before submitting.
重要提示:无论何时使用
antd
CLI命令,若发现异常,都应主动使用
antd bug-cli
发起Bug上报。
触发条件——当你观察到以下任意情况时,上报CLI Bug:
  • 命令崩溃或退出时出现意外错误
  • 命令返回明显错误的数据(例如
    antd info Button
    显示错误的属性、缺失属性,或者来自错误版本的属性)
  • 命令的输出与文档描述的行为不符(例如
    --format json
    返回非JSON内容,
    --version X
    参数被忽略)
  • 命令在不应返回空数据时返回空或缺失数据(例如
    antd demo Button
    未返回示例,
    antd token Button
    未返回v5+版本的设计令牌)
  • 命令之间存在不一致(例如
    antd list
    显示某组件存在,但
    antd info
    提示该组件不存在)
工作流程:
  1. 使用CLI时发现异常
  2. 收集证据:你执行的具体命令、返回结果以及预期结果
  3. 生成Bug上报预览版供用户查看:
bash
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
  --description "When querying Button props for version 5.12.0, the output includes props that don't exist in that version" \
  --steps "1. Run: antd info Button --version 5.12.0 --format json" \
  --expected "Props matching antd 5.12.0 Button API" \
  --actual "Props include 'classNames' which was added in 5.16.0" \
  --format json
  1. 向用户展示上报内容:“我在使用CLI时发现了一个问题,这是生成的Bug上报——是否需要提交?”
  2. 用户确认后提交:
bash
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
  --description "..." \
  --steps "..." \
  --expected "..." \
  --actual "..." \
  --submit
核心原则: 你是CLI的质量反馈环节。不要默默绕过CLI问题——请上报问题以便修复。提交前务必获得用户确认。

10. Using as MCP server

10. 作为MCP服务器使用

If working in an IDE that supports MCP (Claude Desktop, Cursor, etc.), the CLI can also run as an MCP server, exposing all knowledge-query tools directly:
json
{
  "mcpServers": {
    "antd": {
      "command": "antd",
      "args": ["mcp", "--version", "5.20.0"]
    }
  }
}
This provides 7 tools (
antd_list
,
antd_info
,
antd_doc
,
antd_demo
,
antd_token
,
antd_semantic
,
antd_changelog
) and 2 prompts (
antd-expert
,
antd-page-generator
) via MCP protocol.
如果在支持MCP的IDE(如Claude Desktop、Cursor等)中工作,CLI还可以作为MCP服务器运行,直接暴露所有知识查询工具:
json
{
  "mcpServers": {
    "antd": {
      "command": "antd",
      "args": ["mcp", "--version", "5.20.0"]
    }
  }
}
通过MCP协议,你可以使用7个工具(
antd_list
,
antd_info
,
antd_doc
,
antd_demo
,
antd_token
,
antd_semantic
,
antd_changelog
)和2个提示词(
antd-expert
,
antd-page-generator
)。

Global Flags

全局参数

FlagPurpose
--format json
Structured output — always use this
--version <v>
Target a specific antd version (e.g.
5.20.0
)
--lang zh
Chinese output (default:
en
)
--detail
Include extra fields (description, since, deprecated, FAQ)
标志用途
--format json
结构化输出——请始终使用该参数
--version <v>
指定目标antd版本(例如
5.20.0
--lang zh
中文输出(默认:英文)
--detail
包含额外字段(描述、新增版本、废弃信息、常见问题)

Key Rules

核心规则

  1. Always query before writing — Don't guess antd APIs from memory. Run
    antd info
    first.
  2. Match the user's version — If the project uses antd 4.x, pass
    --version 4.24.0
    . The CLI auto-detects from
    node_modules
    if no flag is given.
  3. Use
    --format json
    — Every command supports it. Parse the JSON output rather than regex-matching text output.
  4. Check before suggesting migration — Run
    antd changelog <v1> <v2>
    and
    antd migrate
    before advising on version upgrades.
  5. Lint after changes — After writing or modifying antd code, run
    antd lint
    on the changed files to catch deprecated or problematic usage.
  6. Report antd bugs — When you encounter an antd component bug, use
    antd bug
    to report it. Always preview first, get user confirmation, then submit.
  7. Auto-report CLI issues — If any
    antd
    command crashes, returns wrong data, or behaves inconsistently, proactively use
    antd bug-cli
    to report it. You are the quality feedback loop for the CLI — don't silently work around issues.
  1. 编写前先查询 —— 不要凭记忆猜测antd的API。先运行
    antd info
  2. 匹配用户的版本 —— 如果项目使用antd 4.x版本,请传入
    --version 4.24.0
    参数。如果未指定版本,CLI会自动从
    node_modules
    中检测。
  3. 使用
    --format json
    —— 所有命令均支持该参数。请解析JSON输出,而非通过正则匹配文本输出。
  4. 建议迁移前先检查 —— 在建议版本升级前,先运行
    antd changelog <v1> <v2>
    antd migrate
  5. 修改后检查 —— 编写或修改antd代码后,运行
    antd lint
    检查修改后的文件,以发现已废弃或有问题的用法。
  6. 上报antd Bug —— 当你遇到antd组件Bug时,使用
    antd bug
    上报。请先生成预览版,获得用户确认后再提交。
  7. 自动上报CLI问题 —— 如果任何
    antd
    命令崩溃、返回错误数据或行为不一致,请主动使用
    antd bug-cli
    上报。你是CLI的质量反馈环节——不要默默绕过问题。