- how to create a new Webiny CLI command
- how to override existing commands
This can be useful if you want to create one or more custom commands for your project, which the developers can use.
For this tutorial, we’re going to create a new plugin directly in the
webiny.project.js file, located in your project root folder.
The content of this file might look something like the following:
Notice the plugins required in the
cli.plugins array. This is where we are going to add our own, for example:
To test it out, in your terminal of choice, you can run the following commands:
Inserting new plugins directly into the
webiny.project.js works, but overtime, may become crowded. Feel free to move this code into a separate file, for example
scripts/drinkCommand.js, and use the
webiny.project.js just to call the necessary
To define commands, we use the
yargs library, which is provided as one of the named arguments of the
create function. Be sure to check out the official Yargs documentation for more information.
We override existing commands by overriding already registered plugins, which is done by registering a new plugin with the
name property equal to the
name property of the plugin we want to override.
In the above shown code, we have the following import in the
cli-command-deploymentplugin, which sets up all of the necessary commands for deploying your project, using the default deployment solution - Pulumi. If we wanted to override it, we’d simply register a plugin with the same
cli-command-deploymentname again, and write our own commands in the
createfunction we’ve seen above.
If you can access the plugin you’re overriding, you should also remove it. So, if we wanted to override the
cli-command-deployment plugin, we should also remove the