@kizzlebot/hapi-plugins

0.0.1 • Public • Published

@kizzlebot/hapi-plugins

Build Status Dependencies Dev dependencies

Plugin to autoload plugins given relative path and glob pattern. Optionally, options.plugins[pluginName] can be used to pass arguments to plugins

How to use:

  • Install hapi-plugins npm package in your project our plugin. npm i @flexshopper/hapi-plugins
  • Register plugin in your hapi server:

Registering

const server = new Hapi.Server();

server.connection();

server.register({
    register: require('hapi-plugins'),
    options: {
        relativeTo: proccess.cwd() + '/plugins',
        includes: ['path/to/**/*plugins.js'],
        ignore: ['*.git'],
        // plugin options
        plugins: {
            myPlugin: {
                host: '192.168.1.1'
            }
        }
    }
}, (err) => {
  // continue application
});

manifest style:

registrations: [
    ...
    {
        plugin: {
            register: 'hapi-plugins',
            options: {
                relativeTo: proccess.cwd() + '/plugins',
                includes: ['path/to/**/*plugins.js'],
                ignore: ['*.git'],
                // plugin options
                plugins: {
                    myPlugin: {
                        host: '192.168.1.1'
                    }
                }
            }
        }
    }
];

Options

includes

Required
Type: array

The glob pattern you would like to include

ignore

Type: array

The pattern or an array of patterns to exclude

relativeTo

Type: string

The current working directory in which to search (defaults to process.cwd())

plugins

Type: object

key-value where key is your plugin name (ie internals.register.attributes.name) and value is options to pass to plugin

Route Signature

'use strict';

const internals = module.exports = {};
internals.register = (server, options, next) => {
    // ...do stuff

    return next();
};

internals.register.attributes = {
    name: 'myplugin:',
    version: '0.0.1'
};

Readme

Keywords

Package Sidebar

Install

npm i @kizzlebot/hapi-plugins

Weekly Downloads

0

Version

0.0.1

License

ISC

Last publish

Collaborators

  • kizzlebot