dovetail 
Make your application pluggable!
Getting Started
To install the module, run the following in the command line:
npm i dovetail --save
Use within your application with the following lines of JavaScript:
var events = require('events');
var Dovetail = require('dovetail');
var MyApp = function (options) {
events.EventEmitter.call(this);
this.dovetail = new Dovetail(this);
this.dovetail.resolve('/path/to/plugins/*.js');
};
require('util').inherits(MyApp, events.EventEmitter);
Nothing else is required, but the plugins won't run until you
trigger them
MyApp.prototype.trigger = function (event, params, done) {
this.dovetail.runEvent(event, params, done);
};
Now you can drop a javascript file into your plugins folder and it'll be registered:
module.exports = function (app) {
var plugin = function (params, done) {
console.log('This is my custom plugin!');
console.log('event', params.event);
params.startTime = new Date();
done();
};
plugin.options = {
name: 'my-custom-plugin',
description: 'This is an awesome plugin that runs before the application starts.',
events: [ 'app:before:start' ]
};
var rtn = {};
rtn[plugin.options.name] = plugin;
return rtn;
};
Create a function for your app that will trigger some events:
MyApp.prototype.start = function () {
var self = this;
self.params = {};
self.trigger('app:before:start', self.params, function(err) {
if (err) {
throw new Error(err);
}
console.log('The app has started');
self.trigger('app:before:end', self.params, function (err) {
if (err) {
throw new Error(err);
}
console.log('The app has ended');
});
});
}
Contributing
Find a bug? Have a feature request? Please create an Issue.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt, and build the documentation with grunt-readme.
Pull requests are also encouraged, and if you find this project useful please consider "starring" it to show your support! Thanks!
Author
Jon Schlinkert
Brian Woodward
License
Copyright (c) 2014 undefined, contributors.
Released under the license
This file was generated by grunt-readme on Wednesday, March 12, 2014.