Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
first blood
Browse files Browse the repository at this point in the history
  • Loading branch information
genediazjr committed May 11, 2016
0 parents commit 6b1e88c
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Indentation override for all JS under lib directory
[server/**.js, server/**.json]
curly_bracket_next_line = false
spaces_around_operators = true
spaces_around_brackets = true
indent_style = space
quote_type = single
indent_size = 2
tab_width = 2
charset = utf-8
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# fs
.DS_Store
Thumbs.db

# logs
*.log

# libs
node_modules/*

# ide
.idea

# dropbox
Icon?
.dropbox
85 changes: 85 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"excludeFiles": [
"node_modules/*"
],
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"function",
"typeof"
],
"disallowDanglingUnderscores": {
"allExcept": [
"_exception",
"_private"
]
},
"disallowImplicitTypeConversion": [
"numeric",
"boolean",
"binary",
"string"
],
"disallowKeywords": [
"with"
],
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireCamelCaseOrUpperCaseIdentifiers": {
"ignoreProperties": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterObjectKeys": true,
"disallowQuotedKeysInObjects": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"disallowTrailingComma": true,
"disallowUnusedParams": true,
"disallowEmptyBlocks": true,
"disallowTabs": true,
"disallowVar": true,
"requireSpacesInsideImportedObjectBraces": true,
"requireSpacesInConditionalExpression": true,
"requirePaddingNewLinesAfterUseStrict": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpacesInsideObjectBrackets": "all",
"requireSpaceAfterBinaryOperators": true,
"requireCapitalizedConstructors": true,
"requireParenthesesAroundIIFE": true,
"requireLineFeedAtFileEnd": true,
"requireBlocksOnNewline": 1,
"validateIndentation": 4,
"validateQuoteMarks": "'",
"requireDotNotation": true,
"requireUseStrict": true
}
4 changes: 4 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.md
*.log
*.json
node_modules/*
17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"predef": [
"JSON"
],
"strict": "global",
"esversion": 6,
"plusplus": false,
"eqeqeq": true,
"unused": true,
"nonew": true,
"noarg": true,
"undef": true,
"curly": true,
"forin": true,
"mocha": true,
"node": true
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "4"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Gene Diaz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
155 changes: 155 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# acquaint
Hapi plugin to load routes, handlers, and methods through [globs] (https://github.com/isaacs/node-glob).

[![Build Status](https://travis-ci.org/genediazjr/acquaint.svg)](https://travis-ci.org/genediazjr/acquaint)
[![Coverage Status](https://coveralls.io/repos/genediazjr/acquaint/badge.svg)](https://coveralls.io/r/genediazjr/acquaint)
[![Code Climate](https://codeclimate.com/github/genediazjr/acquaint/badges/gpa.svg)](https://codeclimate.com/github/genediazjr/acquaint)

## Usage

```js
server.register({
register: require('acquaint'),
options: {
relativeTo: __dirname,
routes: [
'path/to/user/**/*Routes.js',
'path/to/sample/**/*Routes.js'
],
handlers: [
{
includes: 'path/to/**/*Handlers.js',
ignores: 'TestHandler.js'
}
],
methods: [
{
prefix: 'model',
includes: [
'path/to/user/*Models.js',
'path/to/sample/*Models.js'
],
},
{
prefix: 'util',
includes: 'path/to/**/*Utils.js'
}
]
}
}, (err) => {
...
});
```
[Glue] (https://github.com/hapijs/glue) manifest
```js
registrations: [
{
plugin: {
register: 'acquaint',
options: [
...
]
}
}
]
```

## Options
* **relativeTo** - `string` of the current working directory in which to search. Defaults to `process.cwd()`.
* **routes**, **handlers**, and **methods** - `array` of [inject objects] (#inject-object) or glob `string` pattern/s to be included.

#### Inject Object
* **includes** `string`/`array` - glob file pattern/s to be injected
* **ignores** `string`/`array` - glob file pattern/s to be ignored
* **prefix** `string` - method usage prefix. only for methods.

## Examples

#### route
```js
module.exports = [
{
path: '/',
method: 'get',
handler: (request, reply) => {
...
return reply('hello');
}
}
];
```

#### handler
```js
module.exports = (route, options) => {

return (request, reply) => {
...
return reply('hello');
};
};
```

Use on route
```js
module.exports = [
{
path: '/',
method: 'get',
handler: {
handlerFilename: {
someOption: 'options parameter on handler'
}
}
}
];
```

#### method
```js
module.export.createOrUpdate = (user, next) => {
...
return next(err, userFromDb);
};
```

Use on server
```js
server.methods.methodPrefix.FileName.exportedFunction(user, (err, data) => {
...
});
```

Use on handler
```js
module.exports = (route, options) => {

return (request, reply) => {

request.server.methods.methodPrefix.FileName.exportedFunction(user, (err, data) => {
...
return reply('hello');
});
};
};
```

Use on other method
```js
const context = require('acquaint');

module.export.createOrUpdate = (user, next) => {
const sample = context.methods.prefix.filename.exportedFunction;
...
return next(err, userFromDb);
};
```

## Contributing
* Include 100% test coverage
* Follow the [Hapi coding conventions] (http://hapijs.com/styleguide)

## Credits
* [hapi-router] (https://github.com/bsiddiqui/hapi-router) - Auto route loading for Hapi
* [hapi-handlers] (https://github.com/ar4mirez/hapi-handlers) - Autoload handlers for Hapi
* [hapi-methods-injection] (https://github.com/amgohan/hapi-methods-injection) - Scan and register automatically your hapi methods
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';

41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "acquaint",
"version": "0.1.0",
"author": "Gene Diaz <genediazjr@gmail.com> (http://genediazjr.com/)",
"description": "Routes, Handlers, and Methods Autoloader",
"keywords": [
"hapi",
"route",
"handler",
"method",
"plugin",
"loader",
"autoload",
"autoloader"
],
"license": "MIT",
"repository": "git://github.com/genediazjr/acquaint",
"bugs": "https://github.com/genediazjr/acquaint/issues",
"main": "lib/index.js",
"engines": {
"node": ">=4.0.0"
},
"scripts": {
"test": "jscs ./ && jshint ./ && lab -c -v -L",
"test-cov-html": "lab -r html -o coverage.html -a code -L"
},
"dependencies": {
"glob": "7.0.x",
"async": "1.5.x",
"lodash": "4.12.x",
"hoek": "4.0.x",
"joi": "8.1.x"
},
"devDependencies": {
"jshint": "2.9.x",
"hapi": "13.4.x",
"jscs": "3.0.x",
"code": "2.3.x",
"lab": "10.5.x"
}
}
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';

0 comments on commit 6b1e88c

Please sign in to comment.