Customizing Module Installation
Besides auto-installing modules with dependencies and life cycle specified inmeta.js
, Robo Installer also gives you ability to customize installation of any particular module. To manually install a module, specify functioninstall
in itsmeta.js
.
// meta.js
module.exports = {
install: function(container, name, path) {
// your custom installation logic here.
}
}
The functioninstall
accepts following parameters:
container: The instance of Robo-Container used to bind module to.
name: Name of the module recognized by the Module Installer, e.g 'config', 'config.development'.
path: Path to the directory that contains the module.
Once specified, only two optionsinstall
andon
will take effects and all other includinguse
,set
andsingleton
will be skipped.
Let's say yourpricing
module has more than one payload files:gateway.js
andconnector.js
and you want to install them all at once:
app
|- index.js
|- modules
| |- pricing
| | |- meta.js
| | |- gateway.js
| | |- connector.js
Your installation will look like:
// meta.js
module.exports = {
install: function($, name, path) {
$.bind(`${name}.connector`).to(`${path}/connector.js`); // $('pricing.connector') will return a connector.
$.bind(name).to(`${path}/gateway.js`).use(`${name}.connector`); // $('pricing') will return a gateway.
}
on: {
installed: ($, name, path) => {
// do some post-install checks here.
}
}
}
You can also use custom installation to install anynode_modules
to the container. For example:
app
|- index.js
|- modules
| |- core
| | |- meta.js
Installation statements:
// meta.js
module.exports = {
install: function ($, name, path) {
$.bind('express').to(() => require('express')).asSingleton();
$.bind('app').to((express) => {
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
return app;
}).use('express').asSingleton();
$.bind('http').to((app) => require('http').Server(app)).use('app').asSingleton();
}
}
$('core')
will throw anError
in this case as it's not bounded to container.
Do not install any utility library as module, e.g ImmutableJS. Otherwise you will make your application structure unnecessarily complex and you will also loose IDE intelli-sense supports as well.
Last updated