Calling all plugin authors! Time for 2.x...

May 18, 2017

Posted in Tutorials

Posted By: Tom King

Tags: 2.0, plugins

<p>With CFWheels 2.0 beta around the corner, it's time to have a cold hard look at the CFWheels plugin ecosystem. With 2.x, we've taken the opportunity to modernise how we deal with plugins. If you're a plugin author who has previously released something for 1.x, you'll be pleased to hear there aren't that many changes required to get your plugins playing nicely with 2.x, but it's definitely a good time to revisit what you've got out there.</p><h3>Introducing Forgebox.io</h3><p>One of the main problems we had previously was a lack of a centralised repository of CFwheels plugins. The old system relied on a bit too much manual updating, and over time got a little long in the tooth. So now, all plugins should be added to <a href="https://www.forgebox.io/type/cfwheels-plugins" rel="noopener noreferrer" target="_blank">forgebox.io</a>, specifically in the <code>CFWheels Plugins</code> category. If you <a href="https://www.forgebox.io/type/cfwheels-plugins" rel="noopener noreferrer" target="_blank">go and have a look now</a>, you'll see a few added by the core team as examples. Adding your plugin shouldn't be too much hard work, but it's definitely worth setting yourself up properly to publish to forgebox automatically via the commandline. There's an extensive tutorial over at&nbsp;<a href="https://guides.cfwheels.org/v2.0/docs/publishing-plugins" rel="noopener noreferrer" target="_blank">guides.cfwheels.org</a>&nbsp;which we recommend you follow. In short, you ideally need a properly configured <code>box.json</code>&nbsp;file and for your plugins to use git tagged releases (ideally). If you've not installed <a href="https://www.ortussolutions.com/products/commandbox" rel="noopener noreferrer" target="_blank">commandbox</a> and the <a href="https://guides.cfwheels.org/v2.0/docs/commandbox" rel="noopener noreferrer" target="_blank">CFWheels CLI</a>, now is definitely the time to try it!</p><h3>Easier for other developers too</h3><p>Once your plugin is in the forgebox system, other CFWheels users can install your plugin with a single CLI command: <code>install slugName</code>; If they've got the CFWheels CLI installed, it will automatically create appropriate <code>.zip</code>&nbsp;files with the correct version number (which you'll have set in <code>box.json</code>) too. They'll also be able to view all existing plugins with <code>wheels plugins list</code>&nbsp; making it extra quick to find the plugin they need. Dependencies are then tracked in that user's <code>box.json</code>&nbsp;file, so they can even distribute an app without your plugin, and then simply run <code>install</code>&nbsp;to go and download the correct version later: they can even update to the latest version of your plugin via the CLI too, or freeze it to a specific version.</p><h3>Automatic Java Mappings</h3><p>One of the nice new features of 2.x is the automatic java library mappings which plugins can now take advantage of. Previously, you had to rely on the developer to manually add an entry into <code>this.javaSettings.loadpaths</code> if your plugin required use of a <code>.class</code>&nbsp;or <code>.jar</code>&nbsp;file. Now, we scan the plugin folders on startup, and automatically add any folders which contain <code>.jar</code>&nbsp;or <code>.class</code>&nbsp;files. One less step for configuration! You can see an example of this in the <a href="https://www.forgebox.io/view/cfwheels-bcrypt" rel="noopener noreferrer" target="_blank">CFWheels bCrypt</a>&nbsp;plugin, which adds a quick wrapper around the bCrypt java class.</p><h3>Don't forget your comments!</h3><p>In a previous post, we talked about the new embedded documentation: plugins can now take advantage of this. For plugin authors, we're recommending you comment all public functions - here's a quasi code example below. <a href="https://gist.github.com/neokoenig/d149a75aa69b8cac49464ffc12f19027" rel="noopener noreferrer" target="_blank">https://gist.github.com/neokoenig/d149a75aa69b8cac49464ffc12f19027</a> The important part is the <code>[section: Plugins]</code>&nbsp;and <code>[category: Plugin Name]</code>&nbsp;part, which will automatically sort your functions in the correct place in the internal documentation. It's a good habit to get into, and will help other users of your plugin too.</p><h3>Oh, and unit tests :)</h3><p>Don't forget to write some unit tests too (hey, don't we all do TDD?); there's been some changes to the test suite in 2.x, and writing unit tests is loads easier. More to follow on:</p><ol><li data-list="bullet"><span class="ql-ui" contenteditable="false"></span>New functions for testing in 2.x</li><li data-list="bullet"><span class="ql-ui" contenteditable="false"></span>Running plugin tests via command line,</li><li data-list="bullet"><span class="ql-ui" contenteditable="false"></span>How to add your plugin to Travis CI for continuous integration testing</li></ol>

Latest Blog Posts