1.0.0 • Published 8 years ago
require-hapi-plugin-dir v1.0.0
require-hapi-plugin-dir
A simple method of requiring all files in a directory, but specifically for hapi plugins that don't require options
.
Use:
Directory Structure
MyPlugins/
|- index.js
|- myplugin1.js
|- myplugin2.js
|- myplugin3.js
index.js
module.exports = require('require-hapi-plugin-dir')(module);
This package simply exports each plugin in a flat array. Given the example directory structure above, this array would be equivalent to:
module.exports = [
require('./myplugin1'),
require('./myplugin2'),
require('./myplugin3')
];
See the "load multiple plugins" example under Loading a Plugin for more info.
Alternate directory structure
MyPlugins/
|- index.js
|- myplugin1.js
|- myplugin2.js
|- myplugin3.js
|- MyOtherPlugins/
|- index.js
|- mypluginA.js
|- mypluginB.js
|- mypluginC.js
Which would present as:
module.exports = [
require('./mypluginA'),
require('./mypluginB'),
require('./mypluginC'),
require('./myplugin1'),
require('./myplugin2'),
require('./myplugin3')
];
API
reqHapiPluginDir(module[, options]);
module
Node's module
object contains a property named filename
, thus it is important to pass this object from the index.js
file which is being called.
options
optional options (haha!) object.
include
- An array of hapi plugins to include manually.flat
- If set to true, the above directory structure would only include files fromMyPlugins
and completely ignore theMyOtherPlugins
directory. Default: false.