Plug-In Generation to Extend Salesforce CLI
When any team at Salesforce builds a new feature, we remind ourselves that every customer is unique. That is why we build features to be customizable and extendable. Salesforce CLI is no different: We know that as a developer your workflow is unique, and although Salesforce CLI comes with a great set of commands right out of the box, you might need something more. That is why the Salesforce CLI team worked closely with the Heroku team to give you the ability to create your own custom commands.
We call this Plug-In Generation and it is built on top of Heroku’s Open CLI Framework (oclif). When you run the Salesforce CLI command sfdx plugins:generate, the Salesforce CLI plug-in wizard leads you through the configuration steps for your new command and generates a plug-in project. You start with a scaffolded command, basically a fully functional “Hello World” command, and the project’s file structure so you don’t need to start from scratch.
Today, Plug-In Generation is generally available and we are open sourcing the Core and Command Libraries to allow you to dig into the code and if there is a functionality you wish to see, contribute back the repository.
What are we announcing today? Plug-In Generation is GA: We provide the scaffolding to get you going so you can build whatever you want. Plus, when you generate a new plug-in, there is an example command in the project folder you can dig into. A plug-in developer guide: The Salesforce CLI Plug-In Developer Guide walks you through the process of building a plug-in with examples so you can get going now. Open-sourcing the CLI Core and Command libraries: The Core Library is a NodeJS module that contains all the “core” utilities of the Salesforce CLI infrastructure. These utilities include authentication, config, project management, and much more. Your plug-in can use the Core library to access information in the same way the force:commands do. Explore the Examples folder in the repo, because you can do more than just Plug-In Generation with the Core Library. The Command Library gives your plug-in access to flag parsing, argument parsing and validation, and help: all the things that a good command should have. Using the Command library allows you to make your command consistent with other SFDX commands and to be user-friendly. What can I build?
If you already have custom scripts that you use with Salesforce CLI, revisit those scripts to determine if it makes sense to create a custom plug-in instead. Whenever you want to perform repetitive tasks and have to support multiple operating systems or work across multiple DX repositories a custom command or set of commands may make your team’s workflow better.
For example, let’s say you have a custom linting program that you want your team to run every time they push to a scratch org. You can create a plug-in that does just that.
Another example of a command that you can create might be to post to Chatter when