webiny-cli-extensions
它能做什么
这个技能帮助你的 AI 为 Webiny 命令行工具编写新命令。适用于希望通过项目 CLI 运行自己脚本的开发者。
适用场景
- ✓需要用于数据迁移或内容导出的自定义命令的时候。
- ✓需要在 Webiny CLI 中使用代码生成器或部署辅助工具的时候。
- ✓想要一个能输出清晰终端信息的健康检查命令时。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/cli-extensions/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我添加一个 Webiny CLI 命令,将所有博客条目导出为 JSON 文件。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能讲解了命令类,它包含名称、描述、带类型的参数和处理程序。处理程序通过终端辅助工具输出信息,命令则在 webiny 配置文件中注册。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
CLI Extensions
TL;DR
Add custom commands to the Webiny CLI using the CliCommandFactory pattern. Define a class implementing CliCommandFactory.Interface<TParams>, specify command name, description, params, and handler, then export with CliCommandFactory.createImplementation(). Register in webiny.config.tsx via <Cli.Command>.
The CliCommandFactory Pattern
// extensions/MyCustomCommand.ts
import { Ui } from "webiny/cli";
import { CliCommandFactory } from "webiny/cli/command";
export interface IMyCustomCommandParams {
name: string;
}
class MyCustomCommandImpl implements CliCommandFactory.Interface<IMyCustomCommandParams> {
constructor(private ui: Ui.Interface) {}
execute(): CliCommandFactory.CommandDefinition<IMyCustomCommandParams> {
return {
name: "my-custom-command",
description: "This is my custom command",
examples: ["$0 my-custom-command test1", "$0 my-custom-command test2"],
params: [
{
name: "name",
description: "Your name",
type: "string"
}
],
handler: async params => {
this.ui.info("Starting my custom command...");
this.ui.emptyLine();
this.ui.success(`Hello, ${params.name}! This is my custom command.`);
}
};
}
}
export default CliCommandFactory.createImplementation({
implementation: MyCustomCommandImpl,
dependencies: [Ui]
});
Register in webiny.config.tsx (YOU MUST include the .ts file extension in the src prop — omitting it will cause a build failure):
<Cli.Command src={"/extensions/MyCustomCommand.ts"} />
Run it:
yarn webiny my-custom-command "World"
Command Definition Properties
| Property | Type | Description |
|---|---|---|
name |
string |
The command name used on the CLI (e.g., "my-custom-command") |
description |
string |
Help text shown when listing commands |
examples |
string[] |
Usage examples ($0 is replaced with the CLI binary name) |
params |
ParamDefinition[] |
Positional parameters and options |
handler |
(params: TParams) => Promise<void> |
The function that executes the command |
Parameter Definition
Each param in the params array:
| Property | Type | Description |
|---|---|---|
name |
string |
Parameter name (matches the key in your TParams interface) |
description |
string |
Help text for this parameter |
type |
"string" | "number" | "boolean" |
Parameter value type |
The Ui Service
Inject Ui for formatted terminal output:
import { Ui } from "webiny/cli";
| Method | Description |
|---|---|
this.ui.info("message") |
Print an info message (blue) |
this.ui.success("message") |
Print a success message (green) |
this.ui.warning("message") |
Print a warning message (yellow) |
this.ui.error("message") |
Print an error message (red) |
this.ui.emptyLine() |
Print a blank line for spacing |
Use Cases
- Data migrations -- Scripts to migrate or seed CMS data
- Code generators -- Generate boilerplate extension files
- Deployment scripts -- Custom deployment workflows
- Data exports -- Export CMS content to files
- Health checks -- Verify infrastructure or API status
Quick Reference
Import: import { CliCommandFactory } from "webiny/cli/command";
Ui import: import { Ui } from "webiny/cli";
Interface: CliCommandFactory.Interface<TParams>
Definition: CliCommandFactory.CommandDefinition<TParams>
Export: CliCommandFactory.createImplementation({ implementation, dependencies })
Registe
常见问题
命令如何注册?
通过 webiny 配置文件中的命令设置注册。
参数如何定义?
每个参数都有名称、描述和类型。
命令如何显示输出?
通过终端辅助工具,它可以打印信息、成功消息和空行。
详情
作者的原始描述
Adding custom commands to the Webiny CLI using CliCommandFactory. Use this skill when the developer wants to create a custom CLI command, add a data migration script, build a code generator, create deployment scripts, export CMS content, or add health check commands. Covers CliCommandFactory.Interface, command definition, typed parameters, the Ui service for terminal output, and registration via <Cli.Command>.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12593
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。