feat: replace --output-file with --format

Signed-off-by: Renas <renash@spotify.com>
This commit is contained in:
Renas
2026-01-12 14:26:51 +01:00
parent cc8e5f52b5
commit 4399328c37
5 changed files with 28 additions and 17 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/cli': patch
---
Added `--include` and `--output-file` options to `backstage-cli info` command for including additional packages via glob patterns and exporting output to JSON.
Added `--include` and `--format` options to `backstage-cli info` command for including additional packages via glob patterns and outputting as JSON or Text.
+17 -5
View File
@@ -444,7 +444,7 @@ Usage: backstage-cli info [options]
Options:
--include <patterns...> Glob patterns for additional packages to include
(e.g., @mycompany/backstage-*)
--output-file <path> Write the info output to a JSON file instead of stdout
--format <text|json> Output format (default: text)
-h, --help display help for command
```
@@ -462,21 +462,33 @@ Include additional packages matching a glob pattern:
yarn backstage-cli info --include "@mycompany/*"
```
Export information to a JSON file for further processing:
Output as JSON:
```bash
yarn backstage-cli info --output-file backstage-info.json
yarn backstage-cli info --format json
```
Export JSON to a file for further processing:
```bash
yarn backstage-cli info --format json > backstage-info.json
```
Combine options to include custom packages and export to JSON:
```bash
yarn backstage-cli info --include "@mycompany/backstage-*" --include "@internal/*" --output-file debug-info.json
yarn backstage-cli info --include "@mycompany/backstage-*" --include "@internal/*" --format json > debug-info.json
```
Export text output to a file:
```bash
yarn backstage-cli info --format text > backstage-info.txt
```
### JSON Output Format
When using `--output-file`, the output is structured as follows:
When using `--format json`, the output is structured as follows:
```json
{
+1 -1
View File
@@ -148,9 +148,9 @@ Options:
Usage: <none>
Options:
--format
--help
--include
--output-file
--version
```
@@ -25,7 +25,7 @@ import fs from 'fs-extra';
interface InfoOptions {
include: string[];
outputFile?: string;
format: 'text' | 'json';
}
/**
@@ -65,7 +65,7 @@ export default async (options: InfoOptions) => {
const backstageJson = await fs.readJSON(backstageFile);
backstageVersion = backstageJson.version ?? 'N/A';
} catch (error) {
if (!options.outputFile) {
if (options.format !== 'json') {
console.warn(
'The "backstage.json" file is not in the expected format',
);
@@ -160,8 +160,8 @@ export default async (options: InfoOptions) => {
const sortedInstalled = [...installedDeps].sort();
const sortedLocal = [...localDeps].sort();
// If outputFile is specified, write JSON to file
if (options.outputFile) {
// If format is json, output JSON to stdout
if (options.format === 'json') {
const output = {
system: systemInfo,
dependencies: Object.fromEntries(
@@ -175,9 +175,7 @@ export default async (options: InfoOptions) => {
),
};
const outputPath = paths.resolveTargetRoot(options.outputFile);
await fs.writeFile(outputPath, JSON.stringify(output, null, 2));
console.log(`Info exported to ${outputPath}`);
process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
return;
}
+4 -3
View File
@@ -33,10 +33,11 @@ export default createCliPlugin({
description:
'Glob patterns for additional packages to include (e.g., @spotify/backstage*)',
},
'output-file': {
format: {
type: 'string',
description:
'Write the info output to a JSON file instead of stdout',
choices: ['text', 'json'],
default: 'text',
description: 'Output format (text or json)',
},
})
.help()