An open API service indexing awesome lists of open source software.

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.

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~}}