This repository is a template containing all the essential boilerplates to help you create new Toolbelt plugins. With this template, you'll be able to develop and locally test your new plugin commands on any VTEX IO app.
ℹ️ Toolbelt is a command-line interface that provides all the necessary features to start developing apps with VTEX IO. To see which commands the Toolbelt natively includes, check our docs or run
vtex
in your terminal.
In the following sections, you'll learn how to make better use of this template and all the necessary steps to create any Toolbelt plugin you want.
Before proceeding any further, we recommend you to:
-
Clone the Toolbelt repository into your local files.
-
Check if you have the Toolbelt correctly installed in your machine.
⚠️ We highly recommend that you install the Toolbelt usingyarn
. Follow these instructions for more information on why.
-
Install the
releasy
package by runningyarn global add releasy
. -
Check our Toolbelt design guidelines for keeping up with the best practices when developing your plugin.
-
Check oclif basic concepts.
ℹ️ Toolbelt is built with oclif, a framework for building extensible CLIs in Node.
To locally test your plugins as you code, you'll need to use the yarn watch
command, which is responsible for creating a symlink named vtex-test
.
To use the yarn watch
command, you must add $HOME/.vtex/dev/bin
to your PATH
environment variable. Take the following steps:
⚠️ Keep in mind: these steps may vary depending on your operating system.
- Open the
~/.bashrc
file (or the corresponding shell configuration file). - At the end of this file, add the line:
export PATH=$PATH:$HOME/.vtex/dev/bin
. - Save it.
- Run the command
source ~/.bashrc
(or corresponding file).
- Create a new repository from this template inside the
vtex
organization. - Open the
package.json
and update thename
anddescription
fields, according to your scenario.
⚠️ Please keep the standard@vtex/cli-plugin-{name}
when naming your plugin.
-
Check if
vtex
underdevdependecies
in thepackage.json
file is referring to the last version of the Toolbelt and update it if necessary. -
Open the
readme.md
file and update it, ensuring that you replacetemplate
with the name of your plugin and removing any unnecessary content.
⚠️ You don't need to worry about updating the usage and command references, since these sections will be automatically updated.
Develop your plugin commands inside the /src/commands/
folder, referring to the oclif API reference and /src/commands/hello.ts
example file.
Also, if necessary, feel free to create libraries, clients, and modules inside your src
folder.
ℹ️ Please refer to our Toolbelt design guidelines for keeping up with the best practices when developing your plugin.
At project root, run: ./bin/run
Before the steps to link, you need to ensure that your plugin already is in the two places on the Toolbelt package.json: The "dependencies" and "plugins". If aren't, run:
yarn add ./{path-do-plugin}/cli-plugin-{name}
And manually add your plugin to "plugins" at toolbelt/package.json.
Now, let's link:
- Run
yarn link
in your plugin project. - Now, in the cloned Toolbelt directory, run
yarn link @vtex/cli-plugin-{name}
. - Run
yarn watch
in both the clonedvtex/toolbelt
and in theplugin repo
.
A symlink named vtex-test
will be created and you'll be able to locally test your plugin as you develop it. That means, for example, that you can test your plugin commands on any VTEX IO app by locally running vtex-test {command-name}
.
If you're satisfied with the tests performed and the developed plugin:
- Access your profile on npm. As a part of the
vtex
organization, you'll have access to generate a new publish token. - Copy the generated token.
- Open your plugin repository on GitHub.
- Go to Settings > Secrets and create a new repository secret with the name
NPM_TOKEN
and paste the value of the previously generated token.
⚠️ Please use capital letters forNPM_TOKEN
.
- Now, go to Settings > Manage access and include the IO DevTools and IO Framework teams as admins.
⚠️ If you're already part of one of those teams, please consider removing your single access.
- In the Settings > Branches section, add a new rule to the master branch, making sure you check the following options:
- Require pull request reviews before merging (Required approving reviews: 1).
- Require status checks to pass before merging.
- Require branches to be up to date before merging.
- Open a pull request containing the changes in your plugin repository.
- Wait for comments from reviewers, discuss and fix any related issues. Once you receive an LGTM, deploy your plugin using the releasy package.
Once the CI tests are completed, your package will be automatically available on npm
as part of the vtex
organization.
The Toolbelt project adheres to a strict pull request review workflow.
To request including your plugin in the Toolbelt, update the Toolbelt dependencies
and the CHANGELOG.md
file. Open a pull request, explaining what your plugin does, wait for comments from reviewers, discuss and fix any related issues. Once you receive an LGTM, you'll be able to merge it to the master branch.
⚠️ Keep in mind: If your plugin is not accepted in the Toolbelt project, you can still use it locally. For that, you need to go inside de cloned toolbelt repo and fire the commandyarn add PLUGIN_NAME
, then add plugin name inpackage.json
inoclif:plugins
section - example -. Runyarn watch
and usevtex-test
to use it. In these cases, however, VTEX does not support, neither takes any responsibility for any damages caused by the developed plugin.
Please refer to the following sections as a template for your plugin README.md file.
$ npm install -g @vtex/cli-plugin-template
$ vtex COMMAND
running command...
$ vtex (-v|--version|version)
@vtex/cli-plugin-template/0.0.0 linux-x64 node-v12.22.7
$ vtex --help [COMMAND]
USAGE
$ vtex COMMAND
...
describe the command here
USAGE
$ vtex hello [FILE]
OPTIONS
-f, --force
-h, --help show CLI help
-n, --name=name name to print
-v, --verbose Show debug level logs
--trace Ensure all requests to VTEX IO are traced
EXAMPLE
$ oclif-example hello
hello world from ./src/hello.ts!
See code: build/commands/hello.ts