Skip to content

Commit

Permalink
Updated dependencies, tests are re-written with lab v15 and hapi v17
Browse files Browse the repository at this point in the history
Library linted
  • Loading branch information
Y-LyN-10 committed Nov 13, 2017
1 parent 0143f72 commit 241dae5
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 237 deletions.
79 changes: 37 additions & 42 deletions lib/index.js
Expand Up @@ -7,7 +7,7 @@ const Joi = require('joi');
const Pkg = require('../package.json');

// Declare internals
var internals = {
const internals = {
schema: {
showAuth: Joi.boolean().default(false),
showStart: Joi.boolean().default(true)
Expand All @@ -16,35 +16,35 @@ var internals = {

exports.register = function (server, options) {

var result = Joi.validate(options, internals.schema);
const result = Joi.validate(options, internals.schema);
Hoek.assert(!result.error, result.error && result.error.annotate());
options = result.value;

server.expose('text', function () {
var info = this.info();

const info = this.info();
return internals.printableInfo(info, options);
});

server.expose('info', function () {
server.expose('info', () => {

return internals.getRouteInfo(server, options);
});

if (options.showStart) {
server.events.on('start', function () {
var out = server.plugins[Pkg.name].text();
server.events.on('start', () => {

const out = server.plugins[Pkg.name].text();
console.log(out);
});
}
};

internals.printableInfo = function (connections, options) {

var out = '';
for (var i = 0, il = connections.length; i < il; ++i) {
var connection = connections[i];
let out = '';
for (let i = 0; i < connections.length; ++i) {
const connection = connections[i];

out += internals.printableConnection(connection, options);
}
Expand All @@ -54,26 +54,27 @@ internals.printableInfo = function (connections, options) {

internals.printableConnection = function (connection, options) {

var out = internals.printableTitle(connection, options) + '\n';
let out = internals.printableTitle(connection, options) + '\n';
out += internals.printableRoutes(connection.routes, options);
return out;
};


internals.printableRoutes = function (routes, options) {

var out = '';
for (var i = 0, il = routes.length; i < il; ++i) {
var show = routes[i];
let out = '';
for (let i = 0; i < routes.length; ++i) {
const show = routes[i];

var method = internals.formatMethod(show.method);
var description = internals.formatDescription(show.description);
var auth = internals.formatAuth(show.auth);
var path = internals.formatPath(show.path);
const method = internals.formatMethod(show.method);
const description = internals.formatDescription(show.description);
const auth = internals.formatAuth(show.auth);
const path = internals.formatPath(show.path);

if (options.showAuth) {
out += [method, path, auth, description].join(' ') + '\n';
} else {
}
else {
out += [method, path, description].join(' ') + '\n';
}
}
Expand All @@ -83,42 +84,39 @@ internals.printableRoutes = function (routes, options) {


internals.printableTitle = function (connection) {
var title = Chalk.underline(connection.uri);

const title = Chalk.underline(connection.uri);
return Chalk.cyan(title);
};


internals.getRouteInfo = function (server, options) {

var connections = [];
const routingTable = server.table();

var routingTable = server.table();

var connectionInfo = {
const connectionInfo = {
uri: server.info.uri,
routes: []
};

internals.connectionInfo(routingTable, options, connectionInfo);
connections.push(connectionInfo);

return connections;
return [connectionInfo];
};

internals.connectionInfo = function (routes, options, connectionInfo) {

for (var i = 0, il = routes.length; i < il; ++i) {
var route = routes[i];
for (let i = 0; i < routes.length; ++i) {
const route = routes[i];

var defaultStrategy = Hoek.reach(route, 'connection.auth.settings.default.strategies');
var authStrategy = route.settings.auth ? route.settings.auth.strategies.toString() : false;
const defaultStrategy = Hoek.reach(route, 'server.auth.settings.default.strategies');
let authStrategy = route.settings.auth ? route.settings.auth.strategies.toString() : false;

if (route.settings.auth === undefined) {
authStrategy = defaultStrategy ? String(defaultStrategy) : false;
}

var show = {
const show = {
method: route.method.toUpperCase(),
path: route.path,
description: route.settings.description || ''
Expand All @@ -131,10 +129,7 @@ internals.connectionInfo = function (routes, options, connectionInfo) {
connectionInfo.routes.push(show);
}

connectionInfo.routes.sort(function (a, b) {

return a.path.localeCompare(b.path);
});
connectionInfo.routes.sort((a, b) => a.path.localeCompare(b.path));
};


Expand All @@ -148,8 +143,7 @@ internals.formatPath = function (path) {

internals.ljust = function (string, amount) {

var padding = ' ';
var currentLength = string.length;
const padding = ' ';

while (string.length < amount) {
string = string + padding;
Expand All @@ -171,7 +165,8 @@ internals.formatAuth = function (auth) {

if (auth === false) {
auth = Chalk.red('none');
} else {
}
else {
auth = Chalk.green(auth);
}
auth = internals.ljust(auth, 20);
Expand All @@ -182,7 +177,7 @@ internals.formatDescription = function (description) {

description = description || '';
description = Chalk.yellow(description);

return description;
};

Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -18,14 +18,14 @@
"author": "Daniel Bretoi",
"license": "BSD",
"dependencies": {
"chalk": "0.5.x",
"hoek": "3.x.x",
"joi": "7.x.x"
"chalk": "^2.3.0",
"hoek": "^5.0.2",
"joi": "^13.0.1"
},
"devDependencies": {
"code": "1.x.x",
"hapi": "8.x.x",
"hapi-auth-basic": "2.x.x",
"lab": "5.x.x"
"code": "^5.1.2",
"hapi": "^17.0.1",
"hapi-auth-basic": "4.2.x",
"lab": "^15.1.2"
}
}

0 comments on commit 241dae5

Please sign in to comment.