Plugins
Every asimov.js app is a plugin. The protocol is one function:
module.exports = function plugin (options) { asimov.init(myInitializer); asimov.register('myThing', somePublicMethod); asimov.config({ default_setting: true });};Other apps mount you with asimov.use(yourPlugin). The framework runs your plugin function once, during the bootstrap phase, before any initializer fires.
Configuration
Plugins typically expose options through asimov.config(). Keys are arbitrary; values can be anything JSON-serialisable.
asimov.config('myConfigVar', true);
var myVar = asimov.config('myConfigVar'); // read onevar allConfig = asimov.config(); // read allConstants
A key in UPPER_SNAKE_CASE is treated as a constant. Setting it twice throws.
asimov.config('SOMETHING_CONSTANT', true);asimov.config('SOMETHING_CONSTANT', false); // throwsLoading from JSON
You can also pass an object literal or a require()-loaded JSON file. The keys are merged into the existing config.
var production = require('./env/production.json');asimov.config(production);Public interface registration
Plugins extend the global asimov object by registering methods. asimov.pages, asimov.logger, asimov.server are all just register() calls under the hood.
asimov.register('doNothing', function () {});
asimov.register()can only be called beforeasimov.start()— that is, inside a plugin hook, not inside an initializer.
Dev-only plugins
Plugins added inside module.exports.start (the bootstrap function) only load when the app is being run standalone — not when it is being required as a plugin from another app. This is the right place for debuggers, REPLs, and watch loops.
var devtools = require('asimov-devtools');module.exports.start = function bootstrap () { asimov .use(module.exports) .use(devtools) // never loads when we are a plugin .start();};