Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions packages/angular/cli/src/commands/version/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,34 @@ export default class VersionCommandModule
* @returns The configured `yargs` instance.
*/
builder(localYargs: Argv): Argv {
return localYargs;
return localYargs.option('json', {
describe: 'Outputs version information in JSON format.',
type: 'boolean',
});
}

/**
* The main execution logic for the `ng version` command.
*/
async run(): Promise<void> {
async run(options: { json?: boolean }): Promise<void> {
const { logger } = this.context;
const versionInfo = gatherVersionInfo(this.context);

if (options.json) {
// eslint-disable-next-line no-console
console.log(JSON.stringify(versionInfo, null, 2));

return;
}

const {
ngCliVersion,
nodeVersion,
unsupportedNodeVersion,
packageManagerName,
packageManagerVersion,
os,
arch,
versions,
cli: { version: ngCliVersion },
system: {
node: { version: nodeVersion, unsupported: unsupportedNodeVersion },
os: { platform: os, architecture: arch },
packageManager: { name: packageManagerName, version: packageManagerVersion },
},
packages,
} = versionInfo;

const headerInfo = [
Expand All @@ -87,7 +97,7 @@ export default class VersionCommandModule
)
.join('\n');

const packageTable = this.formatPackageTable(versions);
const packageTable = this.formatPackageTable(packages);

logger.info([ASCII_ART, header, packageTable].join('\n\n'));

Expand Down
56 changes: 38 additions & 18 deletions packages/angular/cli/src/commands/version/version-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ interface PartialPackageInfo {
* An object containing all the version information that will be displayed by the command.
*/
export interface VersionInfo {
ngCliVersion: string;
versions: Record<string, string>;
unsupportedNodeVersion: boolean;
nodeVersion: string;
packageManagerName: string;
packageManagerVersion: string | undefined;
os: string;
arch: string;
cli: {
version: string;
};
system: {
node: {
version: string;
unsupported: boolean;
};
os: {
platform: string;
architecture: string;
};
packageManager: {
name: string;
version: string | undefined;
};
};
packages: Record<string, string>;
}

/**
Expand Down Expand Up @@ -81,22 +91,32 @@ export function gatherVersionInfo(context: {
}),
);

const versions: Record<string, string> = {};
const packages: Record<string, string> = {};
for (const name of packageNames) {
if (PACKAGE_PATTERNS.some((p) => p.test(name))) {
versions[name] = getVersion(name, workspaceRequire);
packages[name] = getVersion(name, workspaceRequire);
}
}

return {
ngCliVersion: VERSION.full,
versions,
unsupportedNodeVersion,
nodeVersion: process.versions.node,
packageManagerName: context.packageManager.name,
packageManagerVersion: context.packageManager.version,
os: process.platform,
arch: process.arch,
cli: {
version: VERSION.full,
},
system: {
node: {
version: process.versions.node,
unsupported: unsupportedNodeVersion,
},
os: {
platform: process.platform,
architecture: process.arch,
},
packageManager: {
name: context.packageManager.name,
version: context.packageManager.version,
},
},
packages,
};
}

Expand Down