Aller au contenu
Skillpedia
Programmation générale8.1k · #12593

webiny-cli-extensions

Ce qu’il fait

Cette compétence aide votre IA à construire de nouvelles commandes pour l'outil en ligne de commande Webiny. Elle s'adresse aux développeurs qui veulent exécuter leurs propres scripts via la CLI du projet.

Quand l’utiliser

  • ✓Quand vous voulez une commande personnalisée pour une migration de données ou un export de contenu.
  • ✓Quand vous avez besoin d'un générateur de code ou d'un outil de déploiement dans la CLI Webiny.
  • ✓Quand vous voulez une commande de contrôle de santé qui affiche un résultat clair dans le terminal.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/webiny/webiny-js/blob/next/skills/user-skills/cli-extensions/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Ajoute une commande Webiny CLI qui exporte toutes les entrées du blog dans un fichier JSON.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

La compétence explique une classe de commande avec un nom, une description, des paramètres typés et un gestionnaire. Le gestionnaire affiche les messages via un assistant de terminal, et la commande est enregistrée dans le fichier de configuration.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes

Comment la commande est-elle enregistrée ?

Avec un réglage de commande dans le fichier de configuration webiny.

Comment les paramètres sont-ils définis ?

Chaque paramètre a un nom, une description et un type.

Comment la commande affiche-t-elle ses résultats ?

Grâce à un assistant de terminal qui affiche des informations, des messages de réussite et des lignes vides.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
8.1k
Position au classement
#12593
Licence
—
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires