In this article we'll create a very basic CLI plugin to become familiar with how the CLI works, and uses plugins.
We will create a simple CLI plugin called
hello that takes your desired
name as an argument and prints a nice greeting.
Create a new package in your project's root:
./hello. Initialise it using
yarn init -y and create an entrypoint
All CLI command plugins must implement this type (you can write your plugins in plain JS, but the plugin structure is important):
create function receives the
yargs instance and a
context, which is a CLI context object, with various helper utilities.
We define a required positional argument that accepts your name and is later used when printing it in the greeting.
Enabling the plugin
The last thing to do is enable this plugin in your CLI. Edit your
webiny.root.js file and add your new plugin:
webiny.root.js may have a different set of default plugins, but the most important thing is that you require your new plugin and ad it to the
The location of your plugin is not important. Since you have to
require your plugin, you can do it from anywhere, so you're free to structure your folders withing the project however you like.
To verify your command is registered, run
yarn webiny --help, it should be visible in the list of commands.
Let's now test the command:
And now you have created your first CLI plugin!
In the next article we'll build a more complex plugin, the one that will scaffold some code for us.