@hi-ui/hiui-cli
v5.0.0
Published
HiUI CLI for AI agents — fetch component docs and props from llms endpoints
Readme
@hi-ui/hiui-cli
面向 AI Agent 的 HiUI 命令行工具,用于查询组件文档与 Props API。设计参考 @ant-design/cli,数据从 HiUI 官方 llms 端点拉取。
安装
npm install -g @hi-ui/hiui-cli
# 或在 monorepo 根目录
yarn --cwd scripts/hiui-cli install命令
| 命令 | 说明 |
| --- | --- |
| hiui version | 查询当前 CLI 版本号(亦支持 hiui -V / hiui --version) |
| hiui list | 列出所有可用组件(来自 llms.txt) |
| hiui doc <component> | 获取组件完整 Markdown 文档 |
| hiui info <component> | 获取组件 Props 表格(解析自文档) |
| hiui url <component> | 输出组件 llms 文档 URL |
| hiui migrate <from> <to> | 跨主版本迁移(如 hiui migrate 4 5) |
| hiui patch-for-react | 安装 React 19 兼容包并在入口顶部引入 |
全局选项
| 选项 | 说明 | 默认值 |
| --- | --- | --- |
| --base-url <url> | 文档站点根地址 | https://xiaomi.github.io/hiui |
| --format text\|json | 输出格式(Agent 推荐 json) | text |
| --timeout <ms> | HTTP 超时 | 30000 |
也可通过环境变量 HIUI_DOCS_BASE_URL 设置文档根地址。
使用示例
# 查询 CLI 版本
hiui version
hiui version --format json
hiui --version
# 列出组件
hiui list
hiui list --format json
# 获取 Alert 完整文档(对应 https://xiaomi.github.io/hiui/llms/alert.md)
hiui doc alert
hiui doc Alert --format json
# 仅获取 Props
hiui info button --format json
# 获取文档 URL
hiui url cascaderV4 升级到 V5
hiui migrate 4 5 会在指定目录(默认当前目录)内:
- 将所有
package.json中的@hi-ui/*依赖版本更新为^5.0.0(工具包@hi-ui/hi-build等除外) - 将项目文件中的
.hi-v4替换为.hi-v5,并将hi-v4-类名前缀替换为hi-v5-(覆盖[class^='hi-v4-']等写法)
# 预览变更(不写入文件)
hiui migrate 4 5 --dry-run
# 升级当前项目
hiui migrate 4 5
# 升级指定目录
hiui migrate 4 5 --path ./apps/web
# 仅升级 package.json
hiui migrate 4 5 --deps-only
# 仅替换样式类名
hiui migrate 4 5 --class-only升级完成后请执行 npm install 或 yarn 安装依赖,并参考 从 V4 升级至 V5 处理 API 变更。
React 19 兼容包
在 React 19 业务项目中快速接入 @hi-ui/patch-for-react:
# 自动修改 package.json、入口文件并执行 npm/yarn/pnpm install
hiui patch-for-react
# 预览
hiui patch-for-react --dry-run
# 指定项目目录与入口
hiui patch-for-react --path ./apps/web --entry src/main.tsx
# 仅改文件,不执行安装
hiui patch-for-react --skip-install入口文件顶部将添加:
import '@hi-ui/patch-for-react'若存在 'use client' 等指令,会插入在指令之后、其他 import 之前。
JSON 输出示例
hiui info alert --format json{
"component": "alert",
"url": "https://xiaomi.github.io/hiui/llms/alert.md",
"description": "作用于页面的内容区域的提示,非触发类信息",
"props": [
{
"name": "Alert",
"props": [
{
"name": "type",
"description": "警告提示类型",
"type": "AlertTypeEnum",
"enum": "\"primary\" | \"warning\"",
"default": "\"primary\"",
"required": false
}
]
}
]
}程序化调用
const { resolveComponentDoc } = require('@hi-ui/hiui-cli/lib/docs')
const { parsePropsFromMarkdown } = require('@hi-ui/hiui-cli/lib/parse')
async function main() {
const { markdown } = await resolveComponentDoc('alert')
const props = parsePropsFromMarkdown(markdown)
console.log(props)
}开发
cd scripts/hiui-cli
yarn install
node bin/index.js doc alert
node __tests__/parse.test.js
node __tests__/utils.test.js与 Ant Design CLI 的对比
| 能力 | @ant-design/cli | @hi-ui/hiui-cli |
| --- | --- | --- |
| 数据来源 | 内置离线数据 | 在线 llms 端点 |
| list / doc / info | ✅ | ✅ |
| migrate (V4→V5) | — | ✅ |
| MCP Server | ✅ (antd mcp) | 规划中 |
| --format json | ✅ | ✅ |
