feat(nuxi): display nuxt and nitro versions for dev and build commands (#7118)

This commit is contained in:
pooya parsa 2022-09-01 11:34:56 +02:00 committed by GitHub
parent 6fbbf8c5bc
commit 2d30a1db8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import { writeTypes } from '../utils/prepare'
import { loadKit } from '../utils/kit'
import { clearDir } from '../utils/fs'
import { overrideEnv } from '../utils/env'
import { showVersions } from '../utils/banner'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -16,6 +17,7 @@ export default defineNuxtCommand({
overrideEnv('production')
const rootDir = resolve(args._[0] || '.')
showVersions(rootDir)
const { loadNuxt, buildNuxt } = await loadKit(rootDir)

View File

@ -7,7 +7,7 @@ import type { Nuxt } from '@nuxt/schema'
import consola from 'consola'
import { withTrailingSlash } from 'ufo'
import { setupDotenv } from 'c12'
import { showBanner } from '../utils/banner'
import { showBanner, showVersions } from '../utils/banner'
import { writeTypes } from '../utils/prepare'
import { loadKit } from '../utils/kit'
import { importModule } from '../utils/cjs'
@ -38,6 +38,8 @@ export default defineNuxtCommand({
}
const rootDir = resolve(args._[0] || '.')
showVersions(rootDir)
await setupDotenv({ cwd: rootDir })
const listener = await listen(serverHandler, {

View File

@ -63,6 +63,7 @@ export default defineNuxtCommand({
OperatingSystem: os.type(),
NodeVersion: process.version,
NuxtVersion: nuxtVersion,
NitroVersion: getDepVersion('nitropack'),
PackageManager: packageManager,
Builder: builder,
UserConfig: Object.keys(nuxtConfig).map(key => '`' + key + '`').join(', '),

View File

@ -1,8 +1,26 @@
import { createRequire } from 'node:module'
import clear from 'clear'
import { green } from 'colorette'
import { bold, gray, green } from 'colorette'
import { version } from '../../package.json'
export function showBanner (_clear?: boolean) {
if (_clear) { clear() }
console.log(green(`Nuxt CLI v${version}`))
console.log(gray(`Nuxi ${(bold(version))}`))
}
export function showVersions (cwd: string) {
const _require = createRequire(cwd)
const getPkgVersion = (pkg: string) => {
try {
const { version } = _require(`${pkg}/package.json`)
return version || ''
} catch { /* not found */ }
return ''
}
const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge')
const nitroVersion = getPkgVersion('nitropack')
console.log(gray(
green(`Nuxt ${bold(nuxtVersion)}`) +
(nitroVersion ? ` with Nitro ${(bold(nitroVersion))}` : '')
))
}