SuperAPI AI 工具集

21st-cli

编程与开发

查看项目

更新于 10-15 08:33

技能介绍

21st CLI(npx @21st-dev/cli,可执行命令为 21st)是 21st.dev 的单一命令行入口。其定位是:不要手写 UI,而是先在目录中搜索,安装合适的组件,并把可复用的部分发布回团队。

认证(只需一次)。支持两种可互换的凭据,均作为 API key 发送:一是登录会话,npx @21st-dev/cli login 会打开浏览器并把 token 保存到 ~/.config/21st/auth.json,适合交互式/开发机;二是 API key,从 https://21st.dev/mcp 或 studio 的 /studio/<username>/api-keys 页面获取形如 21st_sk_… 的 key,通过 --api-key <key> 或环境变量 TWENTYFIRST_TOKEN / API_KEY_21ST 传入,适合 CI。21st whoami 查看当前登录账户,21st usage 查看套餐与剩余免费额度,21st logout 清除保存的登录。

计量方式。元数据(搜索、预览)免费;获取组件代码(21st get、install)和 AI 生成按用户计量:每天有少量免费额度,之后进入付费墙(用 21st usage 查看剩余额度)。社区访问/会员身份可提升额度。

查找与安装。支持搜索组件、主题和模板,例如 21st search "pricing table" --limit 10;--type c 只搜组件(c | theme | template),21st search dark --type theme 搜主题。可用过滤器包括 --tag、--color、--sort、--free/--paid、--author、--mine、--liked,--json 输出机器可读结果。21st get 143 根据搜索得到的 id 打印组件代码和演示;21st theme <id> 打印主题 CSS;21st add <user>/<slug>(如 21st add shadcn/button)或 21st add @<team>/<slug> 把组件安装到当前项目,底层使用 shadcn,--print 只输出而不写文件。21st add 会解析注册表项,写入 components/ui/<slug>.tsx,并用项目自身的包管理器安装 npm 依赖。公开/未列出的项也可用原生 shadcn 安装:npx shadcn@latest add "https://21st.dev/r/<user>/<slug>"。

生成。21st generate "a glassy pricing section with a monthly/yearly toggle" 使用 21st AI 生成 UI 组件并打开浏览器以便迭代,单独占用一个每日计量桶。

发布组件到团队库。将 CLI 指向一个 React 文件,名称、slug、标签和演示会被自动检测,例如 21st publish ./PinList.tsx --description "..." --to default。可选参数包括:--description(必填,10 字符以上,说明功能与使用场景)、--name/--slug/--tags(覆盖自动检测结果)、--demo <file>(演示文件,默认自动查找 {Comp}.demo.tsx、demos/{slug}.tsx、demos/default.tsx,或合成一个简单演示)、--preview <img>(可选静态缩略图 png/jpg/webp)、--registry ui|hooks|blocks|icons(目标子注册表,默认 ui)、--registry-dep <ref>(可重复,shadcn 依赖,支持裸名、URL 或 @namespace/name)、--public/--unlisted/--private(可见性,默认 unlisted;只有用户明确要求时才用 --public,它会经过管理员审核)。编辑/重新发布:用相同 slug 再次运行同一命令即成 upsert(显示 "Updated"),队友始终拿到最新版本,没有版本号标志;要改可见性就用不同可见性标志重新发布。命令会打印组件 URL 和安装命令 npx @21st-dev/cli add @<handle>/<slug>。

团队、书签与配置。团队相关命令:21st teams、21st team <teamId>、21st team-lists <teamId>、21st team-components <teamId> [--library <id>]。书签相关:21st bookmarks [--type component|theme|template]、21st bookmark <id> --type <kind> [--remove]、21st lists、21st list <listId>、21st list-new <name>、21st list-add <listId> <id> --type <kind> [--remove]。配置相关:21st init --client cursor|claude|codex|vscode|windsurf [--write] 写入 MCP 配置,21st install-skill 全局安装本技能与发布技能。

发布主题与模板。主题是 CSS 文件,必须同时定义 :root 和 .dark 两套 token,例如 21st publish-theme ./my-theme.css --name "Midnight" [--tags dark,minimal]。模板是元数据列表(URL 而非文件),例如 21st publish-template "SaaS Starter" --site https://demo.example.com --preview https://example.com/thumb.png [--description "…"] [--price 49] [--buy-url https://…] [--video https://…],会先落到草稿等待审核。

编辑与删除已发布内容。21st edit <slug> --type component --visibility public|unlisted|private [--description "…"] [--tags a,b] 可更新自己条目的可见性/元数据(仅限 owner,否则 404);21st edit <theme-id> --type theme [--visibility public|private] [--name "New Name"];21st edit <template-id> --type template [--name N] [--description D]。删除:21st delete <id|slug> --type component|theme|template --yes,始终需要 --yes;组件/主题为软删除(可经重新发布/编辑恢复),模板为永久硬删除。注意:publish/edit/delete 需要真实 API key(21st_sk_),这些管理端点不接受登录会话 token;模板可见性由审核控制(作者提交审核,模板的 --visibility 会被忽略)。其他操作可引导用户访问其 studio:https://21st.dev/studio/<username>。

安装本技能。跨智能体安装(skills.sh,支持 70+ 智能体):npx skills add 21st-dev/skill。对于 Claude Code 和 Codex,本技能也打包在 21st 插件中,可一步配置 21st MCP server。