mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
chore: remove unnecessary scopes
This commit is contained in:
parent
f14ac05ce4
commit
0ca99426c9
6
bin/nuxt
6
bin/nuxt
@ -4,11 +4,9 @@ const semver = require('semver')
|
||||
const consola = require('consola')
|
||||
const { name, engines } = require('../package.json')
|
||||
|
||||
const logger = consola.withScope('nuxt')
|
||||
|
||||
// Global error handler
|
||||
process.on('unhandledRejection', _error => {
|
||||
logger.error(_error)
|
||||
consola.error(_error)
|
||||
})
|
||||
|
||||
// Exit process on fatal errors
|
||||
@ -22,7 +20,7 @@ consola.add({
|
||||
})
|
||||
|
||||
if (!semver.satisfies(process.version, engines.node)) {
|
||||
logger.fatal(
|
||||
consola.fatal(
|
||||
`The engine "node" is incompatible with ${name}. Expected version "${
|
||||
engines.node
|
||||
}".`
|
||||
|
@ -4,8 +4,6 @@ const consola = require('consola')
|
||||
const { Nuxt, Builder, Generator } = require('..')
|
||||
const { loadNuxtConfig } = require('./common/utils')
|
||||
|
||||
const logger = consola.withScope('nuxt:build')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -53,7 +51,7 @@ const nuxt = new Nuxt(options)
|
||||
const builder = new Builder(nuxt)
|
||||
|
||||
// Setup hooks
|
||||
nuxt.hook('error', (_err) => logger.fatal(_err))
|
||||
nuxt.hook('error', (_err) => consola.fatal(_err))
|
||||
|
||||
// Close function
|
||||
const close = () => {
|
||||
@ -71,7 +69,7 @@ if (!argv.generate) {
|
||||
builder
|
||||
.build()
|
||||
.then(() => close())
|
||||
.catch(error => logger.fatal(error))
|
||||
.catch(error => consola.fatal(error))
|
||||
} else {
|
||||
// Generate dist for SPA static deployment
|
||||
new Generator(nuxt, builder).generate({ build: true }).then(() => {
|
||||
|
10
bin/nuxt-dev
10
bin/nuxt-dev
@ -7,8 +7,6 @@ const { version } = require('../package.json')
|
||||
const { Nuxt, Builder } = require('..')
|
||||
const { loadNuxtConfig, getLatestHost, nuxtConfigFile } = require('./common/utils')
|
||||
|
||||
const logger = consola.withScope('nuxt:dev')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -32,7 +30,7 @@ if (argv.version) {
|
||||
}
|
||||
|
||||
if (argv.hostname === '') {
|
||||
logger.fatal('Provided hostname argument has no value')
|
||||
consola.fatal('Provided hostname argument has no value')
|
||||
}
|
||||
|
||||
if (argv.help) {
|
||||
@ -65,14 +63,14 @@ let needToRestart = false
|
||||
chokidar
|
||||
.watch(nuxtConfigFile(argv), nuxtConfig.watchers.chokidar)
|
||||
.on('all', () => {
|
||||
logger.debug('[nuxt.config.js] changed')
|
||||
consola.debug('[nuxt.config.js] changed')
|
||||
needToRestart = true
|
||||
|
||||
dev = dev.then(instance => {
|
||||
if (needToRestart === false) return instance
|
||||
needToRestart = false
|
||||
|
||||
logger.debug('Rebuilding the app...')
|
||||
consola.debug('Rebuilding the app...')
|
||||
return startDev(instance)
|
||||
})
|
||||
})
|
||||
@ -83,7 +81,7 @@ function startDev(oldInstance) {
|
||||
|
||||
// Error handler
|
||||
const onError = (err, instance) => {
|
||||
logger.error(err)
|
||||
consola.error(err)
|
||||
return Promise.resolve(instance) // Wait for next reload
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@ const consola = require('consola')
|
||||
const { Nuxt, Builder, Generator } = require('..')
|
||||
const { loadNuxtConfig } = require('./common/utils')
|
||||
|
||||
const logger = consola.withScope('nuxt:generate')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -55,4 +53,4 @@ generator
|
||||
.then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(error => logger.fatal(error))
|
||||
.catch(error => consola.fatal(error))
|
||||
|
@ -6,8 +6,6 @@ const consola = require('consola')
|
||||
const { Nuxt } = require('..')
|
||||
const { loadNuxtConfig, getLatestHost } = require('./common/utils')
|
||||
|
||||
const logger = consola.withScope('nuxt:start')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -25,7 +23,7 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
})
|
||||
|
||||
if (argv.hostname === '') {
|
||||
logger.fatal('Provided hostname argument has no value')
|
||||
consola.fatal('Provided hostname argument has no value')
|
||||
}
|
||||
|
||||
if (argv.help) {
|
||||
@ -54,7 +52,7 @@ options.dev = false
|
||||
const nuxt = new Nuxt(options)
|
||||
|
||||
// Setup hooks
|
||||
nuxt.hook('error', (_err) => logger.fatal(_err))
|
||||
nuxt.hook('error', (_err) => consola.fatal(_err))
|
||||
|
||||
// Check if project is built for production
|
||||
const distDir = resolve(
|
||||
@ -63,7 +61,7 @@ const distDir = resolve(
|
||||
'dist'
|
||||
)
|
||||
if (!fs.existsSync(distDir)) {
|
||||
logger.fatal(
|
||||
consola.fatal(
|
||||
'No build files found, please run `nuxt build` before launching `nuxt start`'
|
||||
)
|
||||
}
|
||||
@ -72,7 +70,7 @@ if (!fs.existsSync(distDir)) {
|
||||
if (nuxt.options.render.ssr === true) {
|
||||
const ssrBundlePath = resolve(distDir, 'server-bundle.json')
|
||||
if (!fs.existsSync(ssrBundlePath)) {
|
||||
logger.fatal(
|
||||
consola.fatal(
|
||||
'No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`'
|
||||
)
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import ServerWebpackConfig from './webpack/server'
|
||||
|
||||
const glob = util.promisify(Glob)
|
||||
|
||||
const logger = consola.withScope('nuxt:builder')
|
||||
|
||||
export default class Builder {
|
||||
constructor(nuxt) {
|
||||
this.nuxt = nuxt
|
||||
@ -99,7 +97,7 @@ export default class Builder {
|
||||
}
|
||||
this._buildStatus = STATUS.BUILDING
|
||||
|
||||
logger.info({
|
||||
consola.info({
|
||||
message: 'Building project',
|
||||
badge: true,
|
||||
clear: true
|
||||
@ -128,9 +126,9 @@ export default class Builder {
|
||||
}
|
||||
}
|
||||
|
||||
logger.success('Builder initialized')
|
||||
consola.success('Builder initialized')
|
||||
|
||||
logger.debug(`App root: ${this.options.srcDir}`)
|
||||
consola.debug(`App root: ${this.options.srcDir}`)
|
||||
|
||||
// Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
||||
await fsExtra.remove(r(this.options.buildDir))
|
||||
@ -155,7 +153,7 @@ export default class Builder {
|
||||
}
|
||||
|
||||
async generateRoutesAndFiles() {
|
||||
logger.debug(`Generating nuxt files`)
|
||||
consola.debug(`Generating nuxt files`)
|
||||
|
||||
// -- Templates --
|
||||
let templatesFiles = [
|
||||
@ -250,7 +248,7 @@ export default class Builder {
|
||||
}
|
||||
|
||||
// -- Routes --
|
||||
logger.debug('Generating routes...')
|
||||
consola.debug('Generating routes...')
|
||||
// If user defined a custom method to create routes
|
||||
if (this._nuxtPages) {
|
||||
// Use nuxt.js createRoutes bases on pages/
|
||||
@ -418,7 +416,7 @@ export default class Builder {
|
||||
})
|
||||
)
|
||||
|
||||
logger.success('Nuxt files generated')
|
||||
consola.success('Nuxt files generated')
|
||||
}
|
||||
|
||||
async webpackBuild() {
|
||||
@ -467,9 +465,9 @@ export default class Builder {
|
||||
|
||||
// Warmup perfLoader before build
|
||||
if (this.options.build.parallel) {
|
||||
logger.start('Warming up worker pools')
|
||||
consola.start('Warming up worker pools')
|
||||
this.perfLoader.warmup()
|
||||
logger.success('Worker pools ready')
|
||||
consola.success('Worker pools ready')
|
||||
}
|
||||
|
||||
// Start Builds
|
||||
@ -535,7 +533,7 @@ export default class Builder {
|
||||
}
|
||||
|
||||
webpackDev(compiler) {
|
||||
logger.debug('Adding webpack middleware...')
|
||||
consola.debug('Adding webpack middleware...')
|
||||
|
||||
// Create webpack dev middleware
|
||||
this.webpackDevMiddleware = util.promisify(
|
||||
|
@ -6,8 +6,6 @@ import fsExtra from 'fs-extra'
|
||||
import consola from 'consola'
|
||||
import { isUrl, promisifyRoute, waitFor, flatRoutes } from '../common/utils'
|
||||
|
||||
const logger = consola.withScope('nuxt:generator')
|
||||
|
||||
export default class Generator {
|
||||
constructor(nuxt, builder) {
|
||||
this.nuxt = nuxt
|
||||
@ -25,15 +23,15 @@ export default class Generator {
|
||||
}
|
||||
|
||||
async generate({ build = true, init = true } = {}) {
|
||||
logger.debug('Initializing generator...')
|
||||
consola.debug('Initializing generator...')
|
||||
|
||||
await this.initiate({ build, init })
|
||||
|
||||
logger.debug('Preparing routes for generate...')
|
||||
consola.debug('Preparing routes for generate...')
|
||||
|
||||
const routes = await this.initRoutes()
|
||||
|
||||
logger.info({
|
||||
consola.info({
|
||||
message: 'Generating pages',
|
||||
badge: true,
|
||||
clear: true
|
||||
@ -80,7 +78,7 @@ export default class Generator {
|
||||
...args
|
||||
)
|
||||
} catch (e) {
|
||||
logger.error('Could not resolve routes')
|
||||
consola.error('Could not resolve routes')
|
||||
throw e // eslint-disable-line no-unreachable
|
||||
}
|
||||
}
|
||||
@ -150,7 +148,7 @@ export default class Generator {
|
||||
|
||||
// Prevent conflicts
|
||||
if (fsExtra.existsSync(fallbackPath)) {
|
||||
logger.warn(`SPA fallback was configured, but the configured path (${fallbackPath}) already exists.`)
|
||||
consola.warn(`SPA fallback was configured, but the configured path (${fallbackPath}) already exists.`)
|
||||
return
|
||||
}
|
||||
|
||||
@ -278,10 +276,10 @@ export default class Generator {
|
||||
})
|
||||
|
||||
if (pageErrors.length) {
|
||||
logger.error('Error generating ' + route)
|
||||
consola.error('Error generating ' + route)
|
||||
Array.prototype.push.apply(errors, pageErrors)
|
||||
} else {
|
||||
logger.success('Generated ' + route)
|
||||
consola.success('Generated ' + route)
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -4,8 +4,6 @@ import consola from 'consola'
|
||||
import Youch from '@nuxtjs/youch'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
const logger = consola.withScope('nuxt:error')
|
||||
|
||||
export default function errorMiddleware(err, req, res, next) {
|
||||
// ensure statusCode, message and name fields
|
||||
err.statusCode = err.statusCode || 500
|
||||
@ -14,7 +12,7 @@ export default function errorMiddleware(err, req, res, next) {
|
||||
|
||||
// We hide actual errors from end users, so show them on server logs
|
||||
if (err.statusCode !== 404) {
|
||||
logger.error(err)
|
||||
consola.error(err)
|
||||
}
|
||||
|
||||
const sendResponse = (content, type = 'text/html') => {
|
||||
|
@ -4,8 +4,6 @@ import consola from 'consola'
|
||||
|
||||
import { getContext } from '../../common/utils'
|
||||
|
||||
const logger = consola.withScope('nuxt:middleware')
|
||||
|
||||
export default async function nuxtMiddleware(req, res, next) {
|
||||
// Get context
|
||||
const context = getContext(req, res)
|
||||
@ -106,7 +104,7 @@ export default async function nuxtMiddleware(req, res, next) {
|
||||
} catch (err) {
|
||||
/* istanbul ignore if */
|
||||
if (context && context.redirected) {
|
||||
logger.error(err)
|
||||
consola.error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,6 @@ import moduleUtil from '../common/module'
|
||||
import ModuleContainer from './module'
|
||||
import Renderer from './renderer'
|
||||
|
||||
const logger = consola.withScope('nuxt')
|
||||
|
||||
export default class Nuxt {
|
||||
constructor(options = {}) {
|
||||
this.options = Options.from(options)
|
||||
@ -40,7 +38,7 @@ export default class Nuxt {
|
||||
)
|
||||
|
||||
this._ready = this.ready().catch(err => {
|
||||
logger.fatal(err)
|
||||
consola.fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
@ -86,11 +84,11 @@ export default class Nuxt {
|
||||
if (!this._hooks[name]) {
|
||||
return
|
||||
}
|
||||
logger.debug(`Call ${name} hooks (${this._hooks[name].length})`)
|
||||
consola.debug(`Call ${name} hooks (${this._hooks[name].length})`)
|
||||
try {
|
||||
await sequence(this._hooks[name], fn => fn(...args))
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
consola.error(err)
|
||||
this.callHook('error', err)
|
||||
}
|
||||
}
|
||||
@ -111,7 +109,7 @@ export default class Nuxt {
|
||||
return
|
||||
}
|
||||
|
||||
logger.ready({
|
||||
consola.ready({
|
||||
message: this.readyMessage,
|
||||
badge: true,
|
||||
clear
|
||||
@ -138,7 +136,7 @@ export default class Nuxt {
|
||||
new Promise((resolve, reject) => {
|
||||
// Destroy server by forcing every connection to be closed
|
||||
server.destroy(err => {
|
||||
logger.debug('server closed')
|
||||
consola.debug('server closed')
|
||||
/* istanbul ignore if */
|
||||
if (err) {
|
||||
return reject(err)
|
||||
|
@ -18,8 +18,6 @@ import MetaRenderer from './meta'
|
||||
import errorMiddleware from './middleware/error'
|
||||
import nuxtMiddleware from './middleware/nuxt'
|
||||
|
||||
const logger = consola.withScope('nuxt:render')
|
||||
|
||||
let jsdom = null
|
||||
|
||||
export default class Renderer {
|
||||
@ -289,7 +287,7 @@ export default class Renderer {
|
||||
}
|
||||
|
||||
// Log rendered url
|
||||
logger.debug(`Rendering url ${url}`)
|
||||
consola.debug(`Rendering url ${url}`)
|
||||
|
||||
// Add url and isSever to the context
|
||||
context.url = url
|
||||
|
Loading…
Reference in New Issue
Block a user