3.4 KiB
package.js
Open your node apps for plugin developers
package.js scans the given packageDirectories
for your installed application packages and creates an instance by require
ing the main JavasScript file if a package.json
file was found which contains expected package identifier(s). In the example case let us say {pandaPackage : true}
.
package.js will pass the packageContstructorSettings
to the new
require
d node module.
This implements an easy way to distribute packages akka addons or plugins for node applications via NPM or other package distribution networks.
Installation
npm install package.js --save;
Example usage
var path = require('path');
var events = require('events');
var packageController = require("package.js");
var CustomApp = function () {
this.events = new events.EventEmitter();
return this;
};
var customApp = new CustomApp();
packageController.autoload({
debug: true,
identify: function() {
return (this.meta.pandaPackage === true);
},
directories: [path.join(__dirname, "node_modules")],
packageContstructorSettings: {app:customApp}
});
To identify all application packages the method autoload
expects a custom method called identify
which is an event and will be executed for each package with the context of the package itself. So far you have access there to the following properties:
this.dir
- The package directory.this.meta
- The package meta data fetched from itspackage.json
.
A package is marked as identified if identify()
returns true (boolean)
.
A detailed demo of usage can be found in the library tests.
Application Packages
Application packages are regular NPM modules and must contain a file called package.json
which is normaly used by NPM but maybe with an extra field to identify your application plugins. Here is a very simple hello world example package
Contributing
License
Copyright (c) 2015 Stephan Ahlf stephan.ahlf@gmail.com
This software is dual licensed under MIT and GNU GENERAL PUBLIC LICENSE Version 3.