-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils): validation in loadFilesFromDir
adding more validation for cwd.
- Loading branch information
Showing
9 changed files
with
2,162 additions
and
818 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# hapi-octopus | ||
|
||
[![travis build](https://img.shields.io/travis/ar4mirez/hapi-octopus.svg?style=flat-square)](https://travis-ci.org/ar4mirez/hapi-octopus) | ||
[![codecov coverage](https://img.shields.io/codecov/c/github/ar4mirez/hapi-octopus.svg?style=flat-square)](https://codecov.io/github/ar4mirez/hapi-octopus) | ||
[![version](https://img.shields.io/npm/v/hapi-octopus.svg?style=flat-square)](http://npm.im/hapi-octopus) | ||
[![downloads](https://img.shields.io/npm/dm/hapi-octopus.svg?style=flat-square)](http://npm-stat.com/charts.html?package=hapi-octopus&from=2015-08-01) | ||
[![MIT License](https://img.shields.io/npm/l/hapi-octopus.svg?style=flat-square)](http://opensource.org/licenses/MIT) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) | ||
|
||
HAPI plugin to auto-load routes, methods, pres, handlers and more. | ||
|
||
## Installation | ||
|
||
## Usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
'use strict'; | ||
|
||
const Glob = require('glob'); | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const _ = require('lodash'); | ||
const Fs = require('fs'); | ||
|
||
const internals = { | ||
options: {} | ||
options: Joi.object().keys({ | ||
cwd: Joi.string().required() | ||
}) | ||
}; | ||
|
||
exports.loadFilesFromDir = (pattern, options) => { | ||
|
||
const validation = Joi.validate(options, Joi.object().keys({ | ||
cwd: Joi.string() | ||
})); | ||
const validation = Joi.validate(options, internals.options); | ||
|
||
if (validation.error) { | ||
throw new Error(validation.error.annotate()); | ||
} | ||
|
||
const files = Glob.sync(pattern, Hoek.applyToDefaults(internals.options, options)); | ||
if (!Fs.statSync(options.cwd).isDirectory()) { | ||
throw new Error('options.cwd: must be a valid directory.'); | ||
} | ||
|
||
const files = Glob.sync(pattern, options); | ||
|
||
return _.map(files, (file) => (`${options.cwd}/${file}`)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,69 @@ | ||
{ | ||
"name": "hapi-octopus", | ||
"version": "0.0.0-semantically-released", | ||
"description": "HAPI plugin to auto-load routes, methods, pres, handlers and more.", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"test": "lab -a code -c -C -l -L -S -t 100", | ||
"test:cov": "lab -r html -o .coverage/coverage.html -r lcov -o .coverage/lcov.info", | ||
"commit": "git-cz", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ar4mirez/hapi-octopus.git" | ||
}, | ||
"keywords": [ | ||
"hapijs", | ||
"plugin", | ||
"routes", | ||
"handlers", | ||
"pres", | ||
"methods" | ||
], | ||
"version": "0.0.0-semantically-released", | ||
"author": "Angel Ramirez <[email protected]>", | ||
"license": "SEE LICENSE IN <LICENSE.md>", | ||
"bugs": { | ||
"url": "https://github.com/ar4mirez/hapi-octopus/issues" | ||
}, | ||
"homepage": "https://github.com/ar4mirez/hapi-octopus#readme", | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run validate" | ||
}, | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"dependencies": { | ||
"async": "^2.1.4", | ||
"glob": "^7.1.1", | ||
"joi": "10.2.1" | ||
}, | ||
"devDependencies": { | ||
"code": "4.0.0", | ||
"codecov": "^1.0.1", | ||
"commitizen": "2.9.5", | ||
"cz-conventional-changelog": "1.2.0", | ||
"eslint": "^3.15.0", | ||
"eslint-config-hapi": "^10.0.0", | ||
"eslint-plugin-hapi": "^4.0.0", | ||
"fixpack": "^2.3.1", | ||
"ghooks": "^2.0.0", | ||
"lab": "12.1.0", | ||
"npm-run-all": "^4.0.1", | ||
"rimraf": "^2.5.4", | ||
"semantic-release": "6.3.2" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
} | ||
"files": [ | ||
"lib", | ||
"README.md" | ||
], | ||
"homepage": "https://github.com/ar4mirez/hapi-octopus#readme", | ||
"keywords": [ | ||
"handlers", | ||
"hapijs", | ||
"methods", | ||
"plugin", | ||
"pres", | ||
"routes" | ||
], | ||
"license": "SEE LICENSE IN <LICENSE.md>", | ||
"main": "dist/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ar4mirez/hapi-octopus.git" | ||
}, | ||
"dependencies": { | ||
"joi": "10.2.1" | ||
"scripts": { | ||
"build": "npm-run-all --parallel build:*", | ||
"build:main": "babel --copy-files --out-dir dist lib", | ||
"commit": "git-cz", | ||
"coverage": "lab -r lcov -o coverage/lcov.info && npm t", | ||
"coverage:check": "lab -t 100", | ||
"coverage:report": "lab -r lcov | codecov", | ||
"prebuild": "rimraf dist", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"setup": "npm install && npm run validate", | ||
"test": "lab -c -C -L -S -t 100 -a code", | ||
"validate": "npm run coverage && npm run coverage:check" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.