chore(nuxi): use consola for consistency (#686)

This commit is contained in:
Daniel Roe 2021-10-07 12:15:15 +02:00 committed by GitHub
parent cc2279bd8a
commit abfaaa97eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 20 deletions

View File

@ -32,6 +32,7 @@
"clear": "^0.1.0",
"clipboardy": "^2.3.0",
"colorette": "^2.0.14",
"consola": "^2.15.3",
"debounce-promise": "^3.1.2",
"deep-object-diff": "^1.1.0",
"degit": "^2.8.4",

View File

@ -1,6 +1,6 @@
import { resolve } from 'pathe'
import consola from 'consola'
import { importModule } from '../utils/cjs'
import { error } from '../utils/log'
import { defineNuxtCommand } from './index'
@ -19,7 +19,7 @@ export default defineNuxtCommand({
const nuxt = await loadNuxt({ rootDir })
nuxt.hook('error', (err) => {
error('Nuxt Build Error:', err)
consola.error('Nuxt Build Error:', err)
process.exit(1)
})

View File

@ -2,10 +2,10 @@ import { resolve, relative } from 'pathe'
import chokidar from 'chokidar'
import debounce from 'debounce-promise'
import type { Nuxt } from '@nuxt/kit'
import consola from 'consola'
import { createServer, createLoadingHandler } from '../utils/server'
import { showBanner } from '../utils/banner'
import { importModule } from '../utils/cjs'
import { error } from '../utils/log'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -47,7 +47,7 @@ export default defineNuxtCommand({
listener.showURL()
}
} catch (err) {
error(`Cannot ${isRestart ? 'restart' : 'start'} nuxt: `, err)
consola.error(`Cannot ${isRestart ? 'restart' : 'start'} nuxt: `, err)
server.setApp(createLoadingHandler(
'Error while loading nuxt. Please check console and fix errors.'
))

View File

@ -2,7 +2,7 @@ import { existsSync, readdirSync } from 'fs'
import createDegit from 'degit'
import { relative, resolve } from 'pathe'
import superb from 'superb'
import { warn, info, error } from '../utils/log'
import consola from 'consola'
import { defineNuxtCommand } from './index'
const rpath = p => relative(process.cwd(), p)
@ -26,12 +26,12 @@ export default defineNuxtCommand({
const dstDir = resolve(process.cwd(), args._[0] || 'nuxt-app')
const degit = createDegit(src, { cache: false /* TODO: buggy */, verbose: (args.verbose || args.v) })
if (existsSync(dstDir) && readdirSync(dstDir).length) {
error(`Directory ${dstDir} is not empty. Please pick another name or remove it first. Aborting.`)
consola.error(`Directory ${dstDir} is not empty. Please pick another name or remove it first. Aborting.`)
process.exit(1)
}
const formatArgs = msg => msg.replace('options.', '--')
degit.on('warn', event => warn(formatArgs(event.message)))
degit.on('info', event => info(formatArgs(event.message)))
degit.on('warn', event => consola.warn(formatArgs(event.message)))
degit.on('info', event => consola.info(formatArgs(event.message)))
await degit.clone(dstDir)
// Show neet steps

View File

@ -2,8 +2,8 @@ import { promises as fsp } from 'fs'
import { relative, resolve } from 'pathe'
import { cyan } from 'colorette'
import { TSReference } from '@nuxt/kit'
import consola from 'consola'
import { importModule, getModulePaths, getNearestPackage } from '../utils/cjs'
import { success } from '../utils/log'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -53,7 +53,7 @@ export default defineNuxtCommand({
await fsp.writeFile(declarationPath, declaration)
success('Generated', cyan(relative(process.cwd(), declarationPath)))
consola.success('Generated', cyan(relative(process.cwd(), declarationPath)))
}
})

View File

@ -1,9 +1,9 @@
import mri from 'mri'
import { red, cyan } from 'colorette'
import consola from 'consola'
import { commands, Command, NuxtCommand } from './commands'
import { showHelp } from './utils/help'
import { showBanner } from './utils/banner'
import { error } from './utils/log'
async function _main () {
const _argv = process.argv.slice(2)
@ -41,12 +41,15 @@ async function _main () {
}
function onFatalError (err: unknown) {
error(err)
consola.error(err)
process.exit(1)
}
process.on('unhandledRejection', err => error('[unhandledRejection]', err))
process.on('uncaughtException', err => error('[uncaughtException]', err))
// Wrap all console logs with consola for better DX
consola.wrapConsole()
process.on('unhandledRejection', err => consola.error('[unhandledRejection]', err))
process.on('uncaughtException', err => consola.error('[uncaughtException]', err))
export function main () {
_main().catch(onFatalError)

View File

@ -1,6 +0,0 @@
import { green, red, yellow, cyan } from 'colorette'
export const error = (...args: any[]) => console.error(red('[error]'), ...args)
export const warn = (...args: any[]) => console.warn(yellow('[warn]'), ...args)
export const info = (...args: any[]) => console.info(cyan('[info]'), ...args)
export const success = (...args: any[]) => console.log(green('[success]'), ...args)

View File

@ -13677,6 +13677,7 @@ fsevents@~2.3.2:
clear: ^0.1.0
clipboardy: ^2.3.0
colorette: ^2.0.14
consola: ^2.15.3
debounce-promise: ^3.1.2
deep-object-diff: ^1.1.0
degit: ^2.8.4