Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 15 commits into from
Sep 1, 2022
2 changes: 2 additions & 0 deletions packages/nuxi/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -16,6 +17,7 @@ export default defineNuxtCommand({
overrideEnv('production')

const rootDir = resolve(args._[0] || '.')
showVersions(rootDir)

const { loadNuxt, buildNuxt } = await loadKit(rootDir)

Expand Down
4 changes: 3 additions & 1 deletion packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -38,6 +38,8 @@ export default defineNuxtCommand({
}

const rootDir = resolve(args._[0] || '.')
showVersions(rootDir)

await setupDotenv({ cwd: rootDir })

const listener = await listen(serverHandler, {
Expand Down
1 change: 1 addition & 0 deletions packages/nuxi/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', '),
Expand Down
22 changes: 20 additions & 2 deletions packages/nuxi/src/utils/banner.ts
Original file line number Diff line number Diff line change
@@ -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))}` : '')
))
}