Skip to content

Commit

Permalink
feat: use consola for cli messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Apr 2, 2018
1 parent 1cdd028 commit 1db2b2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
})
Expand All @@ -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
}
Expand All @@ -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`.')
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1db2b2e

Please sign in to comment.