用途:@ant-design/cli 是 Ant Design 的本地 CLI,内置 antd v3/v4/v5/v6 元数据,全部数据离线,无需联网。用于查询组件知识、分析项目、指导版本迁移。安装为开发依赖后通过 npx antd 运行,建议始终加 --format json 以获得可解析的结构化输出。
主要能力:编写组件前查询 API,如 npx antd info Button --format json;获取可用示例 npx antd demo Button basic --format json;查询语义化 classNames/styles 用 npx antd semantic Button --format json;查询组件级设计 token 用 npx antd token Button --format json;查看完整文档 npx antd doc Table --format json,中文加 --lang zh。调试时用 npx antd env --format json 收集环境快照,npx antd info Select --version 5.12.0 --format json 核对指定版本 API,npx antd lint ./src/components/MyForm.tsx --format json 检查废弃用法,npx antd doctor --format json 诊断项目配置。迁移用 npx antd migrate 3 4 或 4 5,可加 --component Select;用 npx antd changelog 4.24.0 5.0.0 查看变更。项目分析用 npx antd usage ./src --format json,可加 --filter Form;lint 支持 --only deprecated、a11y、performance。组件探索用 npx antd list --format json。缺陷报告用 npx antd bug,先预览、经用户确认后再加 --submit 提交;CLI 问题用 npx antd bug-cli。设置环境变量 ANTD_NO_AUTO_REPORT=1 可跳过所有缺陷报告建议。
使用方式:CLI 也可作为 MCP 服务器运行,在支持 MCP 的 IDE 中配置 command 为 npx、args 为 ["antd", "mcp"],提供 7 个工具(antd_list、antd_info、antd_doc、antd_demo、antd_token、antd_semantic、antd_changelog)和 2 个提示(antd-expert、antd-page-generator)。全局标志包括 --format json、--version <v>、--lang zh、--detail。
限制与规则:不要凭记忆猜测 antd API,写代码前先查询;版本需与用户项目匹配,未指定时 CLI 从 node_modules 自动检测;建议迁移前先运行 changelog 与 migrate;修改代码后运行 lint 检查废弃或问题用法;报告缺陷前先预览并获用户确认。具体收费、平台支持范围等资料暂未提供。