0.1.0 • Published 8 years ago
plugmgr1801-pmb v0.1.0
plugmgr1801-pmb
Yet another plugin mechanism.
Usage
from test/foo-app.js:
var app = { name: 'Foo App', config: { fooSlot: 'qux' } },
fooPlugin = require('./foo-plug'),
plugMgr = require('plugmgr1801-pmb');
plugMgr.makePlugList().add([
fooPlugin,
]).installAllOnto(app, app.config);
console.log(app.qux()); // prints "bar @ Foo App"from test/foo-plug.js:
var dfltCfg = { slot: 'foo' },
meta = { defaultConfig: dfltCfg,
descr: 'A nice foo for your app.',
apiVersion: 1,
};
function install(app, plugCfg, appCfg) {
if (plugCfg === appCfg) { plugCfg = false; }
var slot = (plugCfg.slot
|| appCfg.fooSlot // <-- that's why we checked above
|| dfltCfg.slot);
app[slot] = function () { return 'bar @ ' + app.name; };
}
module.exports = require('plugmgr1801-pmb/plugify')(module, meta, install);Plugin Lists API
plugList = plugMgr.makePlugList()
Prepare a new empty plugin list.
plugList.add(plug)
Add a plugin, or multiple if an array of them is given.
plugList.addWithConfig(config, plug)
Add one or more plugins with a custom config for all of them.
plugList.installAllOnto(app, appConfig)
Install all plugins in the list onto your app.
You may share your app's config with them if you like.
Plugin API
plug.srcUrl
A unique identifier string that looks like an URL or an absolute path.
Will be set by plugify.
plug.name
Optional. Authors: How about a string?
plug.apiVersion
Optional. Authors: How about a number? Then people can compare it with >=.
plug.install(app, plugCfg, appCfg)
plugCfgshould default appCfg if no specific config was given.- Plugins can expect safe property lookup on
plugCfgandappCfg, i.e. neither of them is allowd to benullnorundefined. Usually they should be either an object orfalse.
Known issues
- Needs more/better tests and docs.
License
ISC
0.1.0
8 years ago