From 26be10f70b8734be18bd57ee47e70395bdcf5968 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 31 Aug 2022 21:58:50 +0200 Subject: [PATCH 01/15] feat(nuxi): show versions in dev and build commands --- packages/nuxi/src/commands/build.ts | 2 ++ packages/nuxi/src/commands/dev.ts | 4 +++- packages/nuxi/src/utils/banner.ts | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/nuxi/src/commands/build.ts b/packages/nuxi/src/commands/build.ts index ddb7d8bf11c..3a410ded4b3 100644 --- a/packages/nuxi/src/commands/build.ts +++ b/packages/nuxi/src/commands/build.ts @@ -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) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index aa8edeb4509..d7fa5270586 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -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, { diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 13410e1eb8a..4b6c1a0fac1 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -1,8 +1,23 @@ +import { createRequire } from 'node:module' import clear from 'clear' -import { green } from 'colorette' +import { 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(green(`Nuxi ${version}`)) +} + +export function showVersions (cwd: string) { + const _require = createRequire(cwd) + const versions = [] + for (const pkg of ['nuxt', 'nitropack', 'vite', 'webpack']) { + try { + const { version } = _require(`${pkg}/package.json`) + versions.push(pkg + '@' + version) + } catch { + // Not found + } + } + console.log(gray(versions.join(' '))) } From 52a0570f06a2d2400b67676d093b015a74ae1718 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 31 Aug 2022 22:14:47 +0200 Subject: [PATCH 02/15] add nitro for info --- packages/nuxi/src/commands/info.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nuxi/src/commands/info.ts b/packages/nuxi/src/commands/info.ts index 06ce952edd4..8dac49d71b0 100644 --- a/packages/nuxi/src/commands/info.ts +++ b/packages/nuxi/src/commands/info.ts @@ -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(', '), From 9b9aaff95d22095e2b924e5a93e55dad2ff9ef36 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 31 Aug 2022 22:20:57 +0200 Subject: [PATCH 03/15] make casing consistent --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 4b6c1a0fac1..4f6d58ec90f 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -5,7 +5,7 @@ import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(green(`Nuxi ${version}`)) + console.log(green(`nuxi ${version}`)) } export function showVersions (cwd: string) { From 355769237a98e841a2c636a877d6e32521fb97da Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 31 Aug 2022 22:23:22 +0200 Subject: [PATCH 04/15] better colors --- packages/nuxi/src/utils/banner.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 4f6d58ec90f..effa8838272 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -5,7 +5,7 @@ import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(green(`nuxi ${version}`)) + console.log(gray(`nuxi ${version}`)) } export function showVersions (cwd: string) { @@ -14,7 +14,8 @@ export function showVersions (cwd: string) { for (const pkg of ['nuxt', 'nitropack', 'vite', 'webpack']) { try { const { version } = _require(`${pkg}/package.json`) - versions.push(pkg + '@' + version) + const fullName = pkg + '@' + version + versions.push(pkg === 'nuxt' ? green(fullName) : gray(fullName)) } catch { // Not found } From f904ac0da624d396f618a8025128a703148fc536 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 31 Aug 2022 22:24:40 +0200 Subject: [PATCH 05/15] remove extra color format --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index effa8838272..f6374f03b8f 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -20,5 +20,5 @@ export function showVersions (cwd: string) { // Not found } } - console.log(gray(versions.join(' '))) + console.log(versions.join(' ')) } From d2d4a16a566aabc24d09a69962af9e9d11d76fae Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:07:17 +0200 Subject: [PATCH 06/15] update style --- packages/nuxi/src/utils/banner.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index f6374f03b8f..15db2091b86 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -5,20 +5,24 @@ import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(gray(`nuxi ${version}`)) + console.log(gray(`nuxi@${version}`)) } export function showVersions (cwd: string) { const _require = createRequire(cwd) - const versions = [] - for (const pkg of ['nuxt', 'nitropack', 'vite', 'webpack']) { + const getPkgWithVersion = (pkg: string) => { try { const { version } = _require(`${pkg}/package.json`) - const fullName = pkg + '@' + version - versions.push(pkg === 'nuxt' ? green(fullName) : gray(fullName)) - } catch { - // Not found - } + if (version) { + return pkg + '@' + version + } + } catch { /* not found */ } + return '' } - console.log(versions.join(' ')) + const pkgs = ['vue', 'nitropack', 'vite', 'webpack'] + console.log( + green(getPkgWithVersion('nuxt')), + gray('running with'), + gray(pkgs.map(pkg => getPkgWithVersion(pkg)).filter(Boolean).join(' ')) + ) } From 7b031d9c29a855098f775cf46db84dad227fd207 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:09:29 +0200 Subject: [PATCH 07/15] add nuxt-edge and fallback strings --- packages/nuxi/src/utils/banner.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 15db2091b86..f7c43b17004 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -21,8 +21,8 @@ export function showVersions (cwd: string) { } const pkgs = ['vue', 'nitropack', 'vite', 'webpack'] console.log( - green(getPkgWithVersion('nuxt')), + green(getPkgWithVersion('nuxt') || getPkgWithVersion('nuxt-edge') /* bridge */ || 'nuxt'), gray('running with'), - gray(pkgs.map(pkg => getPkgWithVersion(pkg)).filter(Boolean).join(' ')) + gray(pkgs.map(pkg => getPkgWithVersion(pkg)).filter(Boolean).join(' ') || '-') ) } From 2b905435db8ee5c429127eb79d938c6025bb06ae Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:12:55 +0200 Subject: [PATCH 08/15] reorder --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index f7c43b17004..495c33703e5 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -19,7 +19,7 @@ export function showVersions (cwd: string) { } catch { /* not found */ } return '' } - const pkgs = ['vue', 'nitropack', 'vite', 'webpack'] + const pkgs = ['nitropacl', 'vite', 'webpack', 'vue'] console.log( green(getPkgWithVersion('nuxt') || getPkgWithVersion('nuxt-edge') /* bridge */ || 'nuxt'), gray('running with'), From ca0c6d4bc3ae274fbc8c6ec39e9130e56ab7764c Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:13:14 +0200 Subject: [PATCH 09/15] fix typo --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 495c33703e5..4c9876724ba 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -19,7 +19,7 @@ export function showVersions (cwd: string) { } catch { /* not found */ } return '' } - const pkgs = ['nitropacl', 'vite', 'webpack', 'vue'] + const pkgs = ['nitropack', 'vite', 'webpack', 'vue'] console.log( green(getPkgWithVersion('nuxt') || getPkgWithVersion('nuxt-edge') /* bridge */ || 'nuxt'), gray('running with'), From e76d4e5d620ad509cbd6c853b3ccce6aeddf191e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:16:38 +0200 Subject: [PATCH 10/15] simplify --- packages/nuxi/src/utils/banner.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 4c9876724ba..a328e4052e4 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -17,12 +17,11 @@ export function showVersions (cwd: string) { return pkg + '@' + version } } catch { /* not found */ } - return '' + return pkg } - const pkgs = ['nitropack', 'vite', 'webpack', 'vue'] console.log( - green(getPkgWithVersion('nuxt') || getPkgWithVersion('nuxt-edge') /* bridge */ || 'nuxt'), + green(getPkgWithVersion('nuxt')), gray('running with'), - gray(pkgs.map(pkg => getPkgWithVersion(pkg)).filter(Boolean).join(' ') || '-') + gray(getPkgWithVersion('nitropack')) ) } From f281bbc6a81a1254c20d630b7df42296eb631a61 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 10:18:08 +0200 Subject: [PATCH 11/15] make it more readable --- packages/nuxi/src/utils/banner.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index a328e4052e4..2029084302e 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -5,23 +5,23 @@ import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(gray(`nuxi@${version}`)) + console.log(gray(`Nuxi ${version}`)) } export function showVersions (cwd: string) { const _require = createRequire(cwd) - const getPkgWithVersion = (pkg: string) => { + const getPkgWithVersion = (pkg: string, name: string) => { try { const { version } = _require(`${pkg}/package.json`) if (version) { - return pkg + '@' + version + return name + ' ' + version } } catch { /* not found */ } return pkg } console.log( - green(getPkgWithVersion('nuxt')), + green(getPkgWithVersion('nuxt', 'Nuxt')), gray('running with'), - gray(getPkgWithVersion('nitropack')) + gray(getPkgWithVersion('nitropack', 'Nitro')) ) } From 92b488478bb1ccb63c1275692f2eca99fb8330b6 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 11:02:39 +0200 Subject: [PATCH 12/15] add protection fallbacks back --- packages/nuxi/src/utils/banner.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 2029084302e..58e2ea7df9c 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -10,18 +10,17 @@ export function showBanner (_clear?: boolean) { export function showVersions (cwd: string) { const _require = createRequire(cwd) - const getPkgWithVersion = (pkg: string, name: string) => { + const getPkgVersion = (pkg: string) => { try { const { version } = _require(`${pkg}/package.json`) - if (version) { - return name + ' ' + version - } + return version || '' } catch { /* not found */ } - return pkg + return '' } + const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge') + const nitroVersion = getPkgVersion('nitropack') console.log( - green(getPkgWithVersion('nuxt', 'Nuxt')), - gray('running with'), - gray(getPkgWithVersion('nitropack', 'Nitro')) + green(`Nuxt ${nuxtVersion}`), + nitroVersion ? gray(`running with Nitro ${nitroVersion}`) : '' ) } From d017ba135002659f30563100aacd605f49fd52ec Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 11:06:17 +0200 Subject: [PATCH 13/15] remove verbosity --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 58e2ea7df9c..0a84b730625 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -21,6 +21,6 @@ export function showVersions (cwd: string) { const nitroVersion = getPkgVersion('nitropack') console.log( green(`Nuxt ${nuxtVersion}`), - nitroVersion ? gray(`running with Nitro ${nitroVersion}`) : '' + nitroVersion ? gray(`with Nitro ${nitroVersion}`) : '' ) } From bc67813a6cbda8cf19fceab168611786f6072771 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 11:14:16 +0200 Subject: [PATCH 14/15] try another version --- packages/nuxi/src/utils/banner.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 0a84b730625..ded7e0f5308 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -1,11 +1,11 @@ import { createRequire } from 'node:module' import clear from 'clear' -import { gray, green } from 'colorette' +import { bold, gray, green } from 'colorette' import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(gray(`Nuxi ${version}`)) + console.log(gray(`Nuxi ${(bold(version))}`)) } export function showVersions (cwd: string) { @@ -19,8 +19,8 @@ export function showVersions (cwd: string) { } const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge') const nitroVersion = getPkgVersion('nitropack') - console.log( - green(`Nuxt ${nuxtVersion}`), - nitroVersion ? gray(`with Nitro ${nitroVersion}`) : '' - ) + console.log(gray( + `${green('Nuxt')} ${bold(nuxtVersion)}` + + (nitroVersion ? ` with Nitro ${(bold(nitroVersion))}` : '') + )) } From cb4c16bffbf378832223e00bcaf68b2826cebd61 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Sep 2022 11:24:57 +0200 Subject: [PATCH 15/15] update --- packages/nuxi/src/utils/banner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index ded7e0f5308..0fc480f31ab 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -20,7 +20,7 @@ export function showVersions (cwd: string) { const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge') const nitroVersion = getPkgVersion('nitropack') console.log(gray( - `${green('Nuxt')} ${bold(nuxtVersion)}` + + green(`Nuxt ${bold(nuxtVersion)}`) + (nitroVersion ? ` with Nitro ${(bold(nitroVersion))}` : '') )) }