From 951112c45c5ba4c44e4c474a631f243ae0010024 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 28 Sep 2021 22:48:30 +0200 Subject: [PATCH] cli: fix build issue and tweak info output format Signed-off-by: Patrik Oldsberg --- docs/cli/commands.md | 2 +- packages/cli/src/commands/index.ts | 2 +- packages/cli/src/commands/info.ts | 45 ++++++++---------------------- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/docs/cli/commands.md b/docs/cli/commands.md index b5bb73949e..a27cc62712 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -57,7 +57,7 @@ postpack Restores the changes made by the prepack command create-github-app Create new GitHub App in your organization (experimental) -info Outputs versions of all dependencies for debugging purposes +info Show helpful information for debugging and reporting bugs help [command] display help for command ``` diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index efade740a3..bcd1509f58 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -227,7 +227,7 @@ export function registerCommands(program: CommanderStatic) { program .command('info') - .description('Debug info of all dependencies.') + .description('Show helpful information for debugging and reporting bugs') .action(lazy(() => import('./info').then(m => m.default))); } diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/commands/info.ts index 6035bbbb02..4042d2cb8e 100644 --- a/packages/cli/src/commands/info.ts +++ b/packages/cli/src/commands/info.ts @@ -19,51 +19,28 @@ import os from 'os'; import { runPlain } from '../lib/run'; import { paths } from '../lib/paths'; import { Lockfile } from '../lib/versioning'; -import path from 'path'; export default async () => { await new Promise(async () => { const yarnVersion = await runPlain('yarn --version'); - const npmVersion = await runPlain('npm --version'); - - console.log( - `Operating System - ${os.type}(${os.release}) - ${os.platform}/${os.arch}`, - ); - - console.log('\n------------------\n'); - - console.log('Node.js environment:\n'); - console.log(`Node.js - ${process.version}`); - console.log(`@backstage/cli- ${cliVersion}`); - - console.log('\n------------------\n'); - - console.log('Global environment:\n'); - console.log(`yarn - ${yarnVersion}`); - console.log(`npm - ${npmVersion}`); - - console.log('\n------------------\n'); - - console.log('Backstage CLI type :\n'); // eslint-disable-next-line no-restricted-syntax const isLocal = require('fs').existsSync(paths.resolveOwn('./src')); - console.log( - isLocal - ? 'CLI is running in backstage repo' - : 'CLI is running as a dependency', - ); - console.log('\n------------------\n'); - - console.log('Backstage deps:\n'); + console.log(`OS: ${os.type} ${os.release} - ${os.platform}/${os.arch}`); + console.log(`node: ${process.version}`); + console.log(`yarn: ${yarnVersion}`); + console.log(`cli: ${cliVersion} (${isLocal ? 'local' : 'installed'})`); + console.log(); + console.log('Dependencies:'); const lockfilePath = paths.resolveTargetRoot('yarn.lock'); const lockfile = await Lockfile.load(lockfilePath); - const deps = lockfile.keys(); + + const deps = [...lockfile.keys()].filter(n => n.startsWith('@backstage/')); + const maxLength = Math.max(...deps.map(d => d.length)); for (const dep of deps) { - if (dep.indexOf('@backstage/') !== -1) { - console.log(dep, lockfile.get(dep)![0].version); - } + const versions = new Set(lockfile.get(dep)!.map(i => i.version)); + console.log(` ${dep.padEnd(maxLength)} ${[...versions].join(', ')}`); } }); };