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
Always use
--format json
for structured output you can parse programmatically.
首次使用前,检查CLI是否已安装。如果未安装,自动安装:
bash
which antd || 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选择日期时崩溃"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. 打开DatePicker 2. 点击日期"
--expected "日期被选中"
--actual "组件崩溃并抛出错误"
--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选择日期时崩溃"
--reproduction "https://codesandbox.io/s/xxx"
--steps "1. 打开DatePicker 2. 点击日期"
--expected "日期被选中"
--actual "组件崩溃并抛出错误"
--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对v5.12.0版本返回错误属性" \
  --description "查询v5.12.0版本的Button属性时,输出包含该版本不存在的属性" \
  --steps "1. 执行命令:antd info Button --version 5.12.0 --format json" \
  --expected "返回符合antd 5.12.0 Button API的属性" \
  --actual "输出包含'classNames'属性,该属性是在5.16.0版本新增的" \
  --format json
  1. 向用户展示报告:“我在使用CLI时发现一个问题,这是生成的Bug报告——是否需要提交?”
  2. 用户确认后提交:
bash
antd bug-cli --title "antd info Button对v5.12.0版本返回错误属性" \
  --description "..." \
  --steps "..." \
  --expected "..." \
  --actual "..." \
  --submit
核心原则:你是CLI的质量反馈环节。不要默默绕过CLI问题——上报问题以使其得到修复。提交前务必获得用户确认。

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
输出中文内容(默认:
en
--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的质量反馈环节——不要默默绕过问题。