findhit / findhit-hotplug

Hotplug is an universal plugin manager system for nodejs apps
http://findhit.github.io/projects/hotplug
GNU General Public License v3.0
7 stars 1 forks source link

Hotplug

Test Status Dependency Status

Hotplug is an universal plugin manager system for nodejs apps

Instalation

npm install findhit-hotplug --save

Usage / Implementation Example

App-side


    var Hotplug = require( 'findhit-hotplug' );

    Hotplug( 'MyAwesomeAppName' )
        .on( 'plug-in', function ( e ) {
            var plugin = e.plugin;

            // Some I/O over plugin ?
        })
        .on( 'plug-out', function ( e ) {
            var plugin = e.plugin;

            // Some I/O over plugin ?
        })
        .start({
            host: '127.0.0.1',
            port: '80',
            zip: '4490',
        });

Plugin-side


    var Hotplug = require( 'findhit-hotplug' ),
        app = Hotplug( 'MyAwesomeAppName' )
        plugin = Hotplug.Plugin( 'MyPlugin', 'SomeType' );

    plugin
        .on( 'starting', function () {
            // ...
        })
        .on( 'started', function () {
            // ...
        })
        .on( 'stoping', function () {
            // ...
        })
        .on( 'stopped', function () {
            // ...
        })
        .on( 'state-change', function ( e ) {
            // Everytime state changes
        });

    // Now we can introduce methods to plugin
    plugin.sync = function () {
        // Some I/O
    };

    plugin.teach = function () {
        // Some I/O
    };

    plugin.YOLO = function () {
        // Some I/O
    };

    // In the end, we just have to plug into app
    app.plug( plugin );

Available Classes

How to access them?


    var Hotplug = require( 'findhit-hotplug' ),
        app, plugin;

    // Lets examplify App creation
    app = new Hotplug.App( 'MyAwesomeAppName' );

    // Initialize app
    app.start({ app: 'options', so: 'each', plugin: 'can', read: 'it' });

    // Now, Plugin creation
    plugin = new Hotplug.Plugin( 'PluginName', 'Type', { object: 'with', plugin: 'data' });

    // Linking plugin into app
    app.plug( plugin );