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