https://github.com/ppmathis/fusion.io
Fast and lightweight plugin system - everything's a plugin™
https://github.com/ppmathis/fusion.io
Last synced: 11 months ago
JSON representation
Fast and lightweight plugin system - everything's a plugin™
- Host: GitHub
- URL: https://github.com/ppmathis/fusion.io
- Owner: ppmathis
- License: other
- Created: 2013-09-15T19:17:06.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-10-10T22:50:26.000Z (over 12 years ago)
- Last Synced: 2025-07-03T12:58:51.818Z (12 months ago)
- Language: JavaScript
- Size: 176 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fusion.io #
[](http://travis-ci.org/NeoXiD/fusion.io)
fusion.io is fast and lightweight plugin system for Node.js applications. This module
follows the philosophy *everything's a plugin™*, which effectively means that your whole
application is just built on top of a bunch of plugins. They can interact and rely on each other,
without worrying about dependency resolving & injection.
## How it works ##
As mentioned above, the principle of fusion.io is that your whole application
is built on top of some plugins. Worried about dependency resolving & injection?
fusion.io handles these things for you!
## License & Requirements ##
GPL v3 - Please see LICENSE for more information.
No requirements except Node.js >= 0.6.x
## Application skeleton ##
### app.js ###
This is your main application file, which should be named *app,js*. Usually it should only
contain around 5 lines, thanks to fusion.io:
```js
var FusionIO = require('fusion.io');
var app = new FusionIO();
app.setRootPath(__dirname); // Specifies where the 'plugins' folder is located, usually __dirname is correct
app.loadConfig('config.js');
app.createApp();
```
### config.js ###
This file contains all active plugins and their configuration, if necessary.
It should be loaded by *loadConfig* before creating the application. Currently, multiple configurations
can *NOT* be merged together. Example configuration:
```js
var exports = module.exports = [
// How to require a plugin without any options
{
pluginName: 'fusion-blog.db'
},
// Shortcut to require plugins without any options
'fusion-blog.model',
// Require a plugin with some options
{
pluginName: 'fusion-blog.http',
port: 8080
}
];
```
### plugins/ ###
This is your plugin folder - each plugin should have its own folder within the *plugins* folder.
To prevent duplicates, you should prefix your plugins with the project name, your vendor name or anything you like.
Remember, you *must* specify the plugin name later on for dependency injection, so it shouldn't be too long.
**Example:** *fusion-blog.db* - *fusion-blog* is the product name, and *db* the plugin name.
## Plugin skeleton ##
### package.json ###
Every fusion.io plugin *needs* a package.json. It has two advances: First, you can easily use npm with your plugins.
Second, all the required plugin dependencies and exports can be easily specified and changed. You interchanged
a logging plugin with another one? Just edit the package.json to point to the new plugin. Example:
```js
{
"name": "fusion-example.kitten-demo", // Optional metadata, can be used with NPM
"version": "1.0.0", // Should always be specified! Otherwise fusion.io will log a warning.
"main": "kitten.js", // Must point to the main plugin file
"private": true, // Optional metadata, can be used with NPM
"fusionio": {
// Import 2 plugins, thats all you need to do...
"imports": [
"fusion-blog.db",
"fusion-example.kitten-milk"
],
// Export one plugin (hint: you can export more than just one plugin)
"exports": [
"fusion-example.kitten"
]
}
}
```
### kitten.js ###
This file can have any name, as long as it is specified in the *main* property of the *package.json* file.
As you might have guessed already, it represents your main plugin file, which should be built like this:
```js
/**
* This method gets called by the fusion.io core. There will always be exactly 3 arguments provided.
* {options} is an object which contains all configuration values (which where specified in the application config)
* {imports} This is a function which returns any import specified in package.json. If the import does not
exist, an error will be thrown. Signature: function(pluginName)
* {exports} This is a function with the signature: function(err, exports).
* If an error occured while initializing the plugin, pass the error to err.
* If everything went fine, pass an object containing the plugins to export.
* {fusion} Optional parameter, contains an object with some functions to control FusionIO. Currently, only
* the function 'fetchPluginList' is supported, which will return a list of all plugins with their versions.
*/
function FusionPlugin(options, imports, exports, fusion) {
var $db = imports('fusion-blog.db');
var $milk = imports('fusion-example.kitten-milk');
exports(null, {
'fusion-example.kitten': {
meow: function(hello, world) {
return $milk.mixWithChocolate($db.fetchMilk());
}
}
});
console.log('This cute example is powered by these plugins: ');
console.log(fusion.fetchPluginList());
}
// Exports the plugin
var exports = module.exports = FusionPlugin;
```
- - -
fusion.io plugin system - © 2013 Pascal Mathis