Skip to content
Lenso UI

命令行

使用命令行管理 HeroUI 依赖并初始化项目。

heroui-cli是官方命令行工具,提供了一整套命令,用于初始化、管理和优化你的 HeroUI 项目。你可以 install、uninstall 或 upgrade 单个组件,检查项目健康状况,下载用于 AI 编程助手的文档,等等。

安装

环境要求:

全局安装

要全局安装 heroui-cli,请在终端中执行以下命令之一:

npm install heroui-cli@latest -g

无需安装直接使用

或者,你也可以在不进行全局安装的情况下使用 heroui-cli,运行以下命令之一即可:

pnpm dlx heroui-cli@latest

快速开始

安装 heroui-cli 后,运行以下命令以查看可用命令:

heroui

将会输出如下帮助信息:

Usage: heroui [command]
Options:  -v, --version                  Output the current version  --no-cache                     Disable cache, by default data will be cached for 30m after the first request  -d, --debug                    Debug mode will not install dependencies  -h --help                      Display help information for commands
Commands:  init [options] [projectName]   Initializes a new project  install [options]              Installs @lenso/ui and @lenso/tokens to your project  upgrade [options]              Upgrades @lenso/ui and @lenso/tokens to the latest versions  uninstall [options]            Uninstall @lenso/ui and @lenso/tokens from the project  list [options]                 Lists installed HeroUI packages (@lenso/ui, @lenso/tokens)  env [options]                  Displays debugging information for the local environment  doctor [options]               Checks for issues in the project  agents-md [options]            Downloads HeroUI documentation for AI coding agents  help [command]                 Display help for command

init

使用 init 命令初始化一个新的 HeroUI 项目。该命令会为你的项目完成必要的配置。

heroui init [options]

选项:

  • -t --template [string] 新项目使用的模板,例如 app、pages、vite、react-router
  • -p --package [string] 新项目使用的包管理器

输出:

HeroUI CLI <version>
┌  Create a new project│◇  Select a template (Enter to select)│  ● App (A Next.js 16 with app directory template pre-configured with HeroUI (v3) and Tailwind CSS.)│  ○ Pages (A Next.js 16 with pages directory template pre-configured with HeroUI (v3) and Tailwind CSS.)│  ○ Vite (A Vite template pre-configured with HeroUI (v3) and Tailwind CSS.)│  ○ React Router (A React Router template pre-configured with HeroUI (v3) and Tailwind CSS.)│◇  New project name (Enter to skip with default name)│  my-heroui-app│◇  Select a package manager (Enter to select)│  ● npm│  ○ yarn│  ○ pnpm│  ○ bun│◇  Template created successfully!│◇  Next steps ───────╮│                    ││  cd my-heroui-app  ││  npm install       ││                    │├────────────────────╯│└  🚀 Get started with npm run dev

安装依赖以启动本地服务器:

cd my-heroui-app && npm install

启动本地服务器:

npm run dev

Install

将 @lenso/ui 和 @lenso/tokens 及其对等依赖安装到你的项目中。若它们已安装,则该命令不会执行任何操作。

heroui install [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>
📦 Packages to be installed:╭─────────────────────────────────────────────────────────────────────────────╮│   Package          │   Version        │   Status   │   Docs                 ││─────────────────────────────────────────────────────────────────────────────││   @lenso/ui    │   3.0.0          │   stable   │   https://heroui.com   ││   @lenso/tokens   │   3.0.0          │   stable   │   https://heroui.com   │╰─────────────────────────────────────────────────────────────────────────────╯
╭─────────────── PeerDependencies ────────────────╮│  [email protected]                      latest       ││  [email protected]                  latest       ││  [email protected]                 latest       │╰─────────────────────────────────────────────────╯? Proceed with installation? › - Use arrow-keys. Return to submit.❯   Yes    No
✅ @lenso/ui and @lenso/tokens installed successfully

upgrade

将 @lenso/ui 和 @lenso/tokens 及其对等依赖升级到最新版本。

heroui upgrade [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>
╭──────────────────────────── Upgrade ────────────────────────────╮│  @lenso/ui               ^3.0.0  ->  ^3.1.0                ││  @lenso/tokens              ^3.0.0  ->  ^3.1.0                │╰─────────────────────────────────────────────────────────────────╯
? Would you like to proceed with the upgrade? › - Use arrow-keys. Return to submit.❯   Yes    No
✅ Upgrade complete. All packages are up to date.

uninstall

从你的项目中卸载 @lenso/ui 和 @lenso/tokens。对等依赖不会被卸载。

heroui uninstall [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>
❗️ Packages slated for uninstallation:╭──────────────────────────────────────────────────────────────────────────────────────╮│   Package          │   Version   │   Status   │   Docs                               ││──────────────────────────────────────────────────────────────────────────────────────││   @lenso/ui    │   3.0.0     │   stable   │   https://heroui.com                 ││   @lenso/tokens   │   3.0.0     │   stable   │   https://heroui.com                 │╰──────────────────────────────────────────────────────────────────────────────────────╯? Confirm uninstallation of these packages: › - Use arrow-keys. Return to submit.❯   Yes    No
✅ Successfully uninstalled: @lenso/ui, @lenso/tokens

list

列出已安装的 HeroUI 包(@lenso/ui、@lenso/tokens)。

heroui list [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>
Current installed packages:
╭──────────────────────────────────────────────────────────────────────────────────────╮│   Package          │   Version          │   Status   │   Docs                        ││──────────────────────────────────────────────────────────────────────────────────────││   @lenso/ui    │   3.0.0 🚀latest   │   stable   │   https://heroui.com          ││   @lenso/tokens   │   3.0.0 🚀latest   │   stable   │   https://heroui.com          │╰──────────────────────────────────────────────────────────────────────────────────────╯

doctor

检查项目中存在的问题。

  • 检查 @lenso/ui 和 @lenso/tokens 是否已安装
  • 检查项目中是否安装了所需的 对等依赖 并满足最低版本要求
heroui doctor [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

如果项目中存在问题,doctor 命令将显示问题信息。

HeroUI CLI <version>
HeroUI CLI: ❌ Your project has 1 issue that require attention
❗️Issue 1: missingHeroUIPackages
The following HeroUI packages are not installed:- @lenso/tokens
Run `heroui install` to install them.

否则,doctor 命令将显示以下消息。

HeroUI CLI <version>
✅ Your project has no detected issues.

env

显示本地环境的调试信息。

heroui env [options]

选项:

  • -p --packagePath [string] package.json 文件的路径

输出:

HeroUI CLI <version>
Current installed packages:
╭──────────────────────────────────────────────────────────────────────────────────────╮│   Package          │   Version          │   Status   │   Docs                        ││──────────────────────────────────────────────────────────────────────────────────────││   @lenso/ui    │   3.0.0 🚀latest   │   stable   │   https://heroui.com          ││   @lenso/tokens   │   3.0.0 🚀latest   │   stable   │   https://heroui.com          │╰──────────────────────────────────────────────────────────────────────────────────────╯
Environment Info:  System:    OS: darwin    CPU: arm64  Binaries:    Node: v25.8.1

agents-md

下载用于 AI 编程助手(Claude、Cursor 等)的 HeroUI 文档。该命令会从 HeroUI 仓库克隆最新文档,并将一份精简索引注入到 AGENTS.md 或 CLAUDE.md 中,方便助手参考你项目中的 HeroUI 配置。

heroui agents-md [options]

选项:

  • --react [boolean] 仅包含 React 文档(一次只能选择一个文档库)
  • --native [boolean] 仅包含 Native 文档
  • --migration [boolean] 仅包含 HeroUI v2 到 v3 的迁移文档
  • --output <file> [string] 目标文件路径(例如 AGENTS.md、CLAUDE.md)
  • --ssh [boolean] 使用 SSH 而非 HTTPS 进行 git clone

示例:

不带任何标志运行以进入交互模式:

heroui agents-md

将 React 文档下载到指定文件:

heroui agents-md --react --output AGENTS.md

下载 Native 或迁移文档:

heroui agents-md --native --output CLAUDE.mdheroui agents-md --migration --output AGENTS.md

工作原理:

  1. 使用 git sparse-checkout 从 v3 分支克隆文档
  2. 生成文档和示例文件的精简索引
  3. 将该索引注入到你的 markdown 文件中,置于标记之间(<!-- HEROUI-REACT-AGENTS-MD-START --> / <!-- HEROUI-REACT-AGENTS-MD-END -->,Native 和 Migration 也有类似的标记)
  4. 将 .heroui-docs/ 添加到 .gitignore

--react、--native 和 --migration 一次只能选择其中一个。

更多详情请参阅 AGENTS.md。

agents-md 命令会收集匿名使用数据(所选项、输出文件名、耗时、成功或错误)。设置 HEROUI_ANALYTICS_DISABLED=1 可以选择不参与。

问题反馈

如果你发现了 bug,请在 heroui-cli Issues 中报告。