@flexshopper/hapi-methods
Advanced tools
@@ -7,5 +7,5 @@ 'use strict'; | ||
const Filesystem = require('fs'); | ||
const Glob = require('glob'); | ||
const glob = require('glob'); | ||
const Path = require('path'); | ||
const CamelCase = require('camelcase'); | ||
const _ = require('lodash'); | ||
@@ -58,8 +58,7 @@ const internals = module.exports = {}; | ||
const glob = data.glob; | ||
let files = []; | ||
for (let i = glob.includes.length - 1; i >= 0; i--) { | ||
const pattern = glob.includes[i]; | ||
files = Hoek.merge(files, Glob.sync(pattern, glob.options)); | ||
for (let i = data.glob.includes.length - 1; i >= 0; i--) { | ||
const pattern = data.glob.includes[i]; | ||
files = Hoek.merge(files, glob.sync(pattern, data.glob.options)); | ||
} | ||
@@ -70,3 +69,2 @@ return callback(null, files); | ||
const glob = data.glob; | ||
const files = data.files; | ||
@@ -76,3 +74,3 @@ | ||
const methodPath = Path.join(glob.options.cwd, file); | ||
const methodPath = Path.join(data.glob.options.cwd, file); | ||
const methodFile = require(methodPath); | ||
@@ -85,8 +83,19 @@ const methods = Object.keys(methodFile); | ||
const originFileName = Path.basename(file).replace(/.js/, ''); | ||
const formattedFileName = CamelCase(originFileName); | ||
const chain = formattedFileName + '.' + methodName; | ||
const formattedFileName = _.camelCase(originFileName); | ||
const chain = `${formattedFileName}.${methodName}`; | ||
// Use option.bind = server by default | ||
const options = Hoek.applyToDefaults({ bind: server }, method.options); | ||
server.method(chain, method.method, options); | ||
// Get options object or default to empty | ||
const options = Hoek.reach(method, 'options', { default: {} }); | ||
// try to 'reach' for options.bind, default to server if not supplied | ||
const toBind = Hoek.reach(method, 'options.bind', { default: server }); | ||
// bind to whatever was supplied or server | ||
const methodToAdd = method.method.bind(toBind); | ||
// specify bind in options | ||
options.bind = toBind; | ||
// register the method | ||
server.method(chain, methodToAdd, options); | ||
} | ||
@@ -93,0 +102,0 @@ }); |
{ | ||
"name": "@flexshopper/hapi-methods", | ||
"description": "Hapi plugin to autoload methods.", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"author": "Angel Ramirez <angel.ramirez@flexshopper.com>", | ||
@@ -9,22 +9,28 @@ "bugs": { | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "James Choi", | ||
"email": "james.choi@flexshopper.com", | ||
"url": "https://github.com/kizzlebot" | ||
} | ||
], | ||
"dependencies": { | ||
"async": "^2.0.0-rc.6", | ||
"camelcase": "^3.0.0", | ||
"glob": "^7.0.3", | ||
"hoek": "^4.0.1", | ||
"joi": "^9.0.4" | ||
"joi": "^9.0.4", | ||
"lodash": "^4.17.4" | ||
}, | ||
"devDependencies": { | ||
"@flexshopper/eslint-config-flexshopper": "^3.0.3", | ||
"code": "^3.0.2", | ||
"eslint": "^2.13.1", | ||
"eslint-config-yandex": "^1.0.6", | ||
"estraverse-fb": "^1.3.1", | ||
"@flexshopper/eslint-config-flexshopper": "^5.0.0", | ||
"code": "^4.0.0", | ||
"eslint": "^3.8.1", | ||
"fixpack": "^2.3.1", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^2.0.0", | ||
"hapi": "^14.2.0", | ||
"lab": "^11.0.0", | ||
"nodemon": "^1.9.2" | ||
"lab": "^11.2.0", | ||
"nodemon": "^1.11.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@flexshopper/flexshopper" | ||
}, | ||
"homepage": "https://github.com/FlexShopper/hapi-methods#readme", | ||
@@ -42,9 +48,7 @@ "keywords": [ | ||
"scripts": { | ||
"dev": "nodemon lib/index.js -i logs", | ||
"fix": "fixpack", | ||
"standards": "gulp eslint", | ||
"start": "node lib/index.js", | ||
"test": "lab -t 100 -C -S -v -a code && npm run standards", | ||
"lint": "eslint --ignore-path .gitignore --fix .", | ||
"test": "lab -t 100 -C -S -v -a code && npm run lint", | ||
"test-cov-html": "lab -r html -o coverage/coverage.html" | ||
} | ||
} |
7
-36.36%7733
-5.07%3
-25%82
-25.45%