From 1db2b2e6cd922244700c2e3f5d55f888e77ee7c7 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 2 Apr 2018 14:12:56 +0430 Subject: [PATCH] feat: use consola for cli messages --- lib/module/index.js | 20 +++++++------------- package.json | 1 + 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/module/index.js b/lib/module/index.js index a704c43ce..4932025f5 100644 --- a/lib/module/index.js +++ b/lib/module/index.js @@ -3,9 +3,12 @@ const { existsSync, readdirSync } = require('fs') const merge = require('lodash/merge') const uniq = require('lodash/uniq') const defaults = require('./defaults') +const consola = require('consola') const libRoot = resolve(__dirname, '..') +const logger = consola.withScope('nuxt:auth') + module.exports = function (moduleOptions) { // Merge all option sources const options = merge({}, defaults, moduleOptions, this.options.auth) @@ -24,7 +27,7 @@ module.exports = function (moduleOptions) { if (!options.defaultStrategy && strategies.length) { options.defaultStrategy = strategies[0]._name } else { - console.warn('no strategy defined!') + logger.warn('no strategy defined!') } // Copy plugin @@ -34,10 +37,7 @@ module.exports = function (moduleOptions) { function validateOptions (options) { if (options.endpoints) { // eslint-disable-next-line no-console - console.error( - '[DEPRECATED] [AUTH] ' + - '`auth.endpoints` has been moved into `auth.strategies.local`.' - ) + logger.error('`auth.endpoints` has been moved into `auth.strategies.local`.') options.strategies.local = merge({}, options.strategies.local, { endpoints: options.endpoints }) @@ -46,10 +46,7 @@ function validateOptions (options) { if (options.watchLoggedIn) { // eslint-disable-next-line no-console - console.error( - '[DEPRECATED] [AUTH] ' + - '`watchLoggedIn` has been deprecated. Use `redirect.logout` instead.' - ) + logger.error('`watchLoggedIn` has been deprecated. Use `redirect.logout` instead.') if (options.watchLoggedIn === false) { options.redirect.logout = false } @@ -58,10 +55,7 @@ function validateOptions (options) { // Enforce vuex store because auth depends on it if (!this.options.store) { - throw new Error( - '[ERR] [AUTH] ' + - 'Enable vuex store by creating `store/index.js`.' - ) + logger.fatal('Enable vuex store by creating `store/index.js`.') } } diff --git a/package.json b/package.json index 8c40a0010..f22a547f6 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dependencies": { "@nuxtjs/axios": "^5.3.1", "boom": "^7.2.0", + "consola": "^1.1.4", "cookie": "^0.3.1", "dotprop": "^1.0.2", "js-cookie": "^2.2.0",