@ar4mirez/hapi-pres 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +76 -0
- package/lib/index.js +36 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Angel Ramirez <angel@cuemby.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# hapi-pres
|
|
2
|
+
[![Npm Version][npm-badge]][npm-url]
|
|
3
|
+
[![Build Status][travis-badge]][travis-url]
|
|
4
|
+
[![Dependencies][david-badge]][david-url]
|
|
5
|
+
[![Dev dependencies][david-dev-badge]][david-url]
|
|
6
|
+
|
|
7
|
+
[](https://nodei.co/npm/hapi-pres/)
|
|
8
|
+
|
|
9
|
+
[npm-badge]: https://badge.fury.io/js/hapi-pres.svg
|
|
10
|
+
[npm-url]: https://badge.fury.io/js/hapi-pres
|
|
11
|
+
[travis-badge]: https://travis-ci.org/ar4mirez/hapi-pres.svg?branch=master
|
|
12
|
+
[travis-url]: https://travis-ci.org/ar4mirez/hapi-pres
|
|
13
|
+
[david-badge]: https://david-dm.org/ar4mirez/hapi-pres.svg
|
|
14
|
+
[david-dev-badge]: https://david-dm.org/ar4mirez/hapi-pres/dev-status.svg
|
|
15
|
+
[david-url]: https://david-dm.org/ar4mirez/hapi-pres
|
|
16
|
+
[david-dev-url]: https://david-dm.org/ar4mirez/hapi-pres#info=devDependencies
|
|
17
|
+
|
|
18
|
+
Plugin to autoload pre-requirements.
|
|
19
|
+
|
|
20
|
+
### How to use:
|
|
21
|
+
- Install `hapi-pres` npm package in your project our plugin.
|
|
22
|
+
`npm i hapi-pres`
|
|
23
|
+
- Register plugin in your hapi server:
|
|
24
|
+
|
|
25
|
+
### Registering
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const server = new Hapi.Server();
|
|
29
|
+
|
|
30
|
+
server.connection();
|
|
31
|
+
|
|
32
|
+
server.register({
|
|
33
|
+
register: require('hapi-pres'),
|
|
34
|
+
options: {
|
|
35
|
+
dirname: 'path/to/pres' // required
|
|
36
|
+
}
|
|
37
|
+
}, (err) => {
|
|
38
|
+
// continue application
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
manifest style:
|
|
43
|
+
```javascript
|
|
44
|
+
registrations: [
|
|
45
|
+
...
|
|
46
|
+
{
|
|
47
|
+
plugin: {
|
|
48
|
+
register: 'hapi-pres',
|
|
49
|
+
options: {
|
|
50
|
+
dirname: 'path/to/pres'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Your pre-requirements are available in your `server` object.
|
|
58
|
+
```javascript
|
|
59
|
+
|
|
60
|
+
server.pre.preFilename.preObjectKey
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Pre-requirement Signature
|
|
64
|
+
```javascript
|
|
65
|
+
'use strict';
|
|
66
|
+
|
|
67
|
+
exports.preA = {
|
|
68
|
+
assign: 'preA',
|
|
69
|
+
method: (request, reply) => {
|
|
70
|
+
|
|
71
|
+
return reply({
|
|
72
|
+
message: 'Hello World.'
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
```
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Joi = require('joi');
|
|
4
|
+
|
|
5
|
+
const Pkg = require('../package.json');
|
|
6
|
+
|
|
7
|
+
const schema = Joi.object({
|
|
8
|
+
cwd: Joi.string().default(process.cwd()),
|
|
9
|
+
dirname: Joi.string().default('/pre'),
|
|
10
|
+
filter: Joi.alternatives(Joi.string(), Joi.object()).default(/^(.+)\.js$/),
|
|
11
|
+
excludeDirs: Joi.alternatives(Joi.string(), Joi.object()).default(/^\.(git|svn)$/),
|
|
12
|
+
recursive: Joi.boolean().default(true),
|
|
13
|
+
prefix: Joi.string().default('pre')
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
exports.plugin = {
|
|
17
|
+
pkg: Pkg,
|
|
18
|
+
register: async (server, options) => {
|
|
19
|
+
|
|
20
|
+
const { error, value } = schema.validate(options, { allowUnknown: false });
|
|
21
|
+
|
|
22
|
+
if (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const pres = require('require-all')({
|
|
27
|
+
dirname: value.cwd + value.dirname,
|
|
28
|
+
filter: value.filter,
|
|
29
|
+
excludeDirs: value.excludeDirs,
|
|
30
|
+
recursive: value.recursive
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
server.decorate('server', value.prefix, pres);
|
|
34
|
+
server.log(['plugin', 'info', Pkg.name], 'pre-requirements loaded.');
|
|
35
|
+
}
|
|
36
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ar4mirez/hapi-pres",
|
|
3
|
+
"description": "Autoload pre-requirements for HapiJS.",
|
|
4
|
+
"version": "2.0.2",
|
|
5
|
+
"author": "Angel Ramirez <angel@cuemby.com>",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18.0.0"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/ar4mirez/hapi-pres/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/ar4mirez/hapi-pres#readme",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"joi": "^17.13.3",
|
|
17
|
+
"require-all": "^3.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@hapi/code": "^9.0.3",
|
|
21
|
+
"@hapi/hapi": "^21.4.4",
|
|
22
|
+
"@hapi/lab": "^26.0.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "lab -v -c"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/ar4mirez/hapi-pres.git"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"lib/",
|
|
33
|
+
"package.json",
|
|
34
|
+
"README.md"
|
|
35
|
+
]
|
|
36
|
+
}
|