Chuyển đến nội dung
Skillpedia
Lập trình chung8.1k · #12593

webiny-cli-extensions

Skill này làm gì

Skill này giúp AI của bạn xây dựng lệnh mới cho công cụ dòng lệnh Webiny. Skill dành cho lập trình viên muốn script riêng chạy qua CLI của dự án.

Khi nào nên dùng

  • ✓Khi bạn cần một lệnh tùy chỉnh cho việc migration dữ liệu hoặc xuất nội dung.
  • ✓Khi bạn cần bộ sinh code hoặc công cụ hỗ trợ triển khai bên trong Webiny CLI.
  • ✓Khi bạn muốn một lệnh kiểm tra sức khỏe in kết quả rõ ràng ra terminal.

Liên kết skill

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/cli-extensions/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/cli-extensions/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm một lệnh Webiny CLI xuất toàn bộ mục blog ra một file JSON.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill giải thích một lớp lệnh có tên, mô tả, tham số có kiểu và một handler. Handler in thông báo qua một công cụ hỗ trợ terminal, và lệnh được đăng ký trong file cấu hình.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Lệnh được đăng ký như thế nào?

Bằng một cài đặt command trong file cấu hình webiny.

Tham số được định nghĩa ra sao?

Mỗi tham số có tên, mô tả và kiểu.

Lệnh hiển thị kết quả như thế nào?

Qua một công cụ hỗ trợ terminal, dùng để in thông tin, thông báo thành công và dòng trống.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
8.1k
Vị trí xếp hạng
#12593
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự