https://github.com/ozum/hapi-plugins-dir
Traverse directory recursively and get array of Hapi plugins ready to feed Hapi's server.register(plugins, [options]) function.
https://github.com/ozum/hapi-plugins-dir
Last synced: about 2 months ago
JSON representation
Traverse directory recursively and get array of Hapi plugins ready to feed Hapi's server.register(plugins, [options]) function.
- Host: GitHub
- URL: https://github.com/ozum/hapi-plugins-dir
- Owner: ozum
- License: mit
- Created: 2018-05-29T12:17:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-29T12:49:27.000Z (almost 7 years ago)
- Last Synced: 2025-02-09T18:24:41.122Z (3 months ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.hbs
- License: LICENSE
Awesome Lists containing this project
README
# hapi-plugins-dir
# Description
Traverse directory recursively and get array of Hapi plugins ready to feed Hapi's
[`server.register(plugins, [options])`](https://github.com/hapijs/hapi/blob/master/API.md#server.register()) function.# Synopsis
**Plugins in same directory with file**
```js
const getHapiPlugins = require("hapi-plugins-dir");
const plugins = getHapiPlugins();
await server.register(plugins); // Hapi server object...
```**Custom directory**
```js
const getHapiPlugins = require("hapi-plugins-dir");
const plugins = getHapiPlugins({ dir: "plugins" }); // Dir may be relative or absolute
await server.register(plugins); // Hapi server object...
```**With [haute-couture](https://github.com/hapipal/haute-couture): plugins/index.js**
```js
module.exports = require("hapi-plugins-dir")();
```# Details
* Traverses recursively given directory. (Defaults to caller file's directory)
* If a plugin isn't specified in `plugins` key, it will be required using filename.
* If a directory name starts with `@`, it is treated as package scope. (i.e. `plugins/@name/some-plugin.js` -> `@name/some-plugin`)
* Files can be ordered using number prefixes appended dot or dash (. or -). Numbers are stripped when requesting plugin. (i.e. `plugins/001-hapi-auth-basic` requires `hapi-auth-basic`).
* Scope directory names can be prefixed with numbers too. (i.e. `plugins/001-@scope/001-module.js` requires `@scope/module`).
* Result array must be registered using [`server.register(plugins, [options])`](https://github.com/hapijs/hapi/blob/master/API.md#server.register()). It is not automatically registered.# API
{{>main~}}