Skip to content

Commit

Permalink
Merge pull request #6643 from Charizard/cli-info
Browse files Browse the repository at this point in the history
feat(cli): Add info command to backstage-cli
  • Loading branch information
Rugvip committed Sep 29, 2021
2 parents 2751a24 + 951112c commit 9aa3d98
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ postpack Restores the changes made by the prepack command
create-github-app Create new GitHub App in your organization (experimental)
info Show helpful information for debugging and reporting bugs
help [command] display help for command
```

Expand Down Expand Up @@ -647,3 +648,15 @@ YAML file that can be referenced in the GitHub integration configuration.
```text
Usage: backstage-cli create-github-app <github-org>
```

## info

Scope: `root`

Outputs debug information which is useful when opening an issue. Outputs system
information, node.js and npm versions, CLI version and type (inside backstage
repo or a created app), all `@backstage/*` package dependency versions.

```text
Usage: backstage-cli info
```
5 changes: 5 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export function registerCommands(program: CommanderStatic) {
.command('create-github-app <github-org>')
.description('Create new GitHub App in your organization.')
.action(lazy(() => import('./create-github-app').then(m => m.default)));

program
.command('info')
.description('Show helpful information for debugging and reporting bugs')
.action(lazy(() => import('./info').then(m => m.default)));
}

// Wraps an action function so that it always exits and handles errors
Expand Down
46 changes: 46 additions & 0 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { version as cliVersion } from '../../package.json';
import os from 'os';
import { runPlain } from '../lib/run';
import { paths } from '../lib/paths';
import { Lockfile } from '../lib/versioning';

export default async () => {
await new Promise(async () => {
const yarnVersion = await runPlain('yarn --version');
// eslint-disable-next-line no-restricted-syntax
const isLocal = require('fs').existsSync(paths.resolveOwn('./src'));

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()].filter(n => n.startsWith('@backstage/'));
const maxLength = Math.max(...deps.map(d => d.length));

for (const dep of deps) {
const versions = new Set(lockfile.get(dep)!.map(i => i.version));
console.log(` ${dep.padEnd(maxLength)} ${[...versions].join(', ')}`);
}
});
};

0 comments on commit 9aa3d98

Please sign in to comment.