TrailheaDX ’18 was chock-full of great technical content, but the one session I looked forward to most of all was “Create and Use Salesforce CLI Plugins” with the great Dave Carroll, Jeffrey Dickey, and Thomas Dvornik. To give context on what the session was about, here is an excerpt from the description:
The new Salesforce CLI brings a whole new level of control and scriptability to your orgs, but the CLI doesn’t do everything out-of-the-box. Learn how to install plugins that do exactly what you need, and how to build a plugin if one doesn’t exist.The Salesforce CLI is a plugin based on the SFDX Core, a set of accessible libraries and modules. This session will dive into the SFDX Core and demonstrate how you can accelerate app development by taking advantage of these modules and libraries from other languages, outside of the context of the Salesforce CLI.
If that description doesn’t thrill you to the core of your being, you might be reading the wrong blog post. Check out this video of the presentation for an excellent walkthrough of the plugin building process:
Salesforce developer tools have long been the neglected stepchild in the SFDC family of products. Metadata deployments can be painful and messy, especially when using somewhat cryptic tools like Ant and Eclipse. But with the dawning of DX, that has begun to change, and Salesforce is committed to a new generation of developer tools to unleash the power of an open toolchain.
The DX Command Line Interface (CLI) is already a great tool, but until recently, if you wanted to add any functionality to it you needed to write separate scripts to drive that functionality. Starting with the release of version 6.7.1, the CLI now comes bundled with a generator to let you write your own namespaced plugins that you can link to in order to add new abilities.
The sfdx-plugin-generate Github repository walks you through the process of building, linking and testing your custom plugin. To see a freshly made plugin in action, check out this repo codescience-dx-plugin; this takes the suggestion of parsing unit test coverage from the TrailheaDX demo and adds some user-friendly features, like colored output, to highlight your coverage. You won’t be able to install it via npm as it has not been published yet, but you can link it to your existing SFDX CLI and start tweaking it. The default coverage minimum is 75%, but you can override that via your sfdx-project.json file as shown in the image below.
The default coverage minimum can also be overridden by specifying the -m argument from the command line. This flexibility will allow you to easily set a minimum coverage percentage from the developer’s desktop or via continuous integration.
By extending the base plugin, you get the ability to leverage standard flags like –json, which turns your output into a json object to let you chain commands that parse the output of the previous command.
All of this configurability and flexibility add up to a rich environment for extending the standard CLI with your own custom DX plugins. Enhancements to the plugin environment are landing all the time, so get plugged into the DX plugin scene today!
Need help configuring your DX CLI or making the most of development plugins? Feel free to schedule a consultation with our team!