|
@@ -6,15 +6,56 @@ Introduction:
|
|
|
Researching a way to bring java alike OSGi to nodejs for hot swappable modules.
|
|
|
This is not an intention to replace nodejs modules but a way to swap certain areas of the application such as bringing new versions without a restart
|
|
|
|
|
|
+Usage:
|
|
|
+-------
|
|
|
+Bundle:
|
|
|
+A bundle should export bundleStart, or bundleActivator object
|
|
|
+
|
|
|
+This specific bundle it will receive messages from core-shell bundle, execute a shell command and print output
|
|
|
+Placing the bundle in {app path}/bundles/shell-test/index.js
|
|
|
+```javascript
|
|
|
+var log = require('hlogger').createLogger('shell-test');
|
|
|
+var child = require('child_process');
|
|
|
+
|
|
|
+function bundleStart(context) {
|
|
|
+
|
|
|
+ log.info("Command provider installed");
|
|
|
+
|
|
|
+ // Create a bash and transport commands
|
|
|
+ context.events
|
|
|
+ .channel('core-shell')
|
|
|
+ .after('cmd',(req,res,e) => {
|
|
|
+ if(e.count != 0) return;
|
|
|
+ e.wait();
|
|
|
+ var shcmd = req.cmd + " " + req.args.join(" ");
|
|
|
+ var proc = child.exec(shcmd);
|
|
|
+ proc.stdout.pipe(res);
|
|
|
+ proc.stderr.pipe(process.stderr);
|
|
|
+ proc.on('close',function() {
|
|
|
+ e.done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+module.exports.bundleStart = bundleStart;
|
|
|
+```
|
|
|
+
|
|
|
+Main app:
|
|
|
+```javascript
|
|
|
+var BundleManager = require('node-hci'); // or path to node-hci since is not published in npm yet
|
|
|
+// This will load bundles from the {app path}/bundles
|
|
|
+var manager = new BundleManager({runPath: __dirname + "/bundles"});
|
|
|
+manager.loadDefaultBundles();
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
|
|
|
Running examples:
|
|
|
-----------------
|
|
|
-
|
|
|
```
|
|
|
git clone http://dev.hexasoftware.com/stdio/node-hci
|
|
|
cd node-hci
|
|
|
npm install
|
|
|
-node test/hci-test
|
|
|
+node test/hci-usecase
|
|
|
```
|
|
|
|
|
|
And monitor bundle should be accessible by http://127.0.0.1:3500/monitor
|
|
@@ -22,8 +63,9 @@ And monitor bundle should be accessible by http://127.0.0.1:3500/monitor
|
|
|
|
|
|
|
|
|
|
|
|
-Cli bundle list
|
|
|
-
|
|
|
+Cli bundle list
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-Web based bundle listing
|
|
|
-
|
|
|
+Web based bundle listing
|
|
|
+
|