diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..92615f6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: Build And Test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['14.21.3', '21.7.3'] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + - run: npm install + - run: npm test \ No newline at end of file diff --git a/.gitignore b/.gitignore index dfe93fa..f952e67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ node_modules/ coverage.html *.log diff --git a/CHANGELOG.md b/CHANGELOG.md index ba532c4..567c6b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,25 +2,12 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +This project adheres to [Semantic Versioning](http://semver.org/). -### 2.0.3 - -- Fix issues [#10](https://github.com/sitrakary/hapi-auto-route/issues/10). -- Fix lint errors. - -### 2.0.2 - -- Fix issues [#5](https://github.com/sitrakary/hapi-auto-route/issues/5). -### 2.0.3 - -- Update dependencies. - -## 3.0.0 +### 3.1.0 -- `routes_dir` requires an absolute path and must set in plugin registration. -- Updates dependencies. +- `routes_dir` accepts an array of parameters. - Updates documentation. ### 3.0.1 @@ -39,7 +26,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fix unpublished version -### 3.1.0 +## 3.0.0 -- `routes_dir` accepts an array of parameters. +- `routes_dir` requires an absolute path and must set in plugin registration. +- Updates dependencies. - Updates documentation. + +### 2.0.3 + +- Fix issues [#10](https://github.com/sitrakary/hapi-auto-route/issues/10). +- Fix lint errors. + +### 2.0.2 + +- Fix issues [#5](https://github.com/sitrakary/hapi-auto-route/issues/5). + +### 2.0.1 + +- Update dependencies. \ No newline at end of file diff --git a/lib/auto-route.js b/lib/auto-route.js index 8ae4ffd..444d88f 100644 --- a/lib/auto-route.js +++ b/lib/auto-route.js @@ -2,7 +2,7 @@ const Glob = require('glob'); const Hoek = require('@hapi/hoek'); -const Joi = require('@hapi/joi'); +const Joi = require('joi'); const Path = require('path'); const Util = require('util'); const Prefix = require('./prefix'); @@ -10,12 +10,11 @@ const Prefix = require('./prefix'); module.exports.getFiles = (baseDir, pattern) => { if (Array.isArray(baseDir)) { - const promise = new Promise((resolve, reject) => { + return new Promise((resolve) => { Promise.all(baseDir.map((d) => this.getFiles(d, pattern))) .then((value) => resolve(Hoek.flatten(value))); }); - return promise; } const absolutePattern = Path.join(baseDir, pattern); @@ -37,8 +36,8 @@ module.exports.getRoutes = (filepaths) => { const routes = files.filter((file) => { - const { error } = Joi.validate(file, multipleRoutesAllowed); - return error === null; + const result = multipleRoutesAllowed.validate(file); + return !Object.keys(result).includes('error'); }); return routes.map((file) => Hoek.clone(file)); @@ -89,12 +88,14 @@ module.exports.updatePaths = (prefixes, routes, stripTrailingSlash) => { module.exports.validateOptions = (options) => { const optionsSchema = Joi.object().keys({ - routes_dir: Joi.alternatives(Joi.string(), Joi.array().items(Joi.string())).required(), + routes_dir: Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.string())).required(), pattern: Joi.string().default('**/!(_)*.js'), use_prefix: Joi.boolean().default(false) }); - const { error, value } = Joi.validate(options, optionsSchema); - Hoek.assert(error === null, 'Invalid options are passed to hapi-auto-route'); - return value; + const result = optionsSchema.validate(options); + + Hoek.assert(!Object.keys(result).includes('error'), 'Invalid options are passed to hapi-auto-route'); + + return result.value; }; diff --git a/package.json b/package.json index 61aa15a..ecbb7eb 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,17 @@ "name": "hapi-auto-route", "version": "3.1.0", "description": "Autoloads hapi routes", - "author": "Sitraka Ratsimba ", + "author": "Sitraka Ratsimba ", "main": "index.js", "keywords": [ "hapi", "route", "autoload" ], - "repository": "https://github.com/cooxe/hapi-auto-route.git", + "repository": { + "type": "git", + "url": "git+https://github.com/cooxe/hapi-auto-route.git" + }, "bugs": "https://github.com/cooxe/hapi-auto-route/issues", "license": "MIT", "scripts": { @@ -23,14 +26,14 @@ "README.md" ], "devDependencies": { - "@hapi/code": "6.x.x", - "@hapi/hapi": "18.x.x", - "@hapi/eslint-plugin-hapi": "4.x.x", - "@hapi/lab": "20.x.x" + "@hapi/code": "9.x.x", + "@hapi/hapi": "21.x.x", + "@hapi/eslint-plugin": "6.x.x", + "@hapi/lab": "25.x.x" }, "dependencies": { - "@hapi/hoek": "8.x.x", - "@hapi/joi": "15.x.x", + "@hapi/hoek": "11.x.x", + "joi": "17.x.x", "glob": "7.x.x" } }