Skip to content

Plugins

Benjamin Arthur Lupton edited this page Jun 24, 2014 · 11 revisions

Creating Plugins

If you've created an extension that you love, you can share it with others by making it into a plugin.

Preparation

First create a new directory for your plugin to live in:

mkdir chainy-plugin-myplugin
cd chainy-plugin-myplugin

Scaffolding

Use the Chainy CLI to scaffold the structure of your plugin (it will ask you a few questions):

chainy create-plugin

Writing your Plugin

Inside lib/yourPluginName.js convert your extension from something that looks like this:

// using the `action` API call to execute an unnamed action
require('chainy').create()
    .action(function(currentValue, newValue){
        return newValue
    })

// or via using the `addExtension` API call to define an action extension called `set`
require('chainy').create()
    .addExtension('set', 'action', function(currentValue, newValue){
        return newValue
    })

Into something that looks like this:

module.exports = function(currentValue, newValue){
    return newValue
}
module.exports.extensionType = 'action'
module.exports.extensionOptions = {}  // optional

If you would like to export something else as the top level export and not the extension method, you can do this by exporting an extension object instead like so:

module.exports = 'something else'
module.exports.extension = {
    method: function(currentValue, newValue){
        return newValue
    },
    type: 'action'
}

Publishing your Plugin

If you used chainy create-plugin to create your plugin, you can use cake publish to publish your plugin to the npm registry as well as git tag it among other nifty things.

If you didn't use our awesome chainy create-plugin command to create your plugin, you can just use the standard npm publish call instead.