Skip to content

Commit 5063671

Browse files
committed
refactor(@angular/cli): improve output format for ng cache info command
This commit refactors the output to be more user-friendly and consistent with other commands like `ng version`. It introduces a clean, aligned, two-column layout with colors to improve readability. - Labels are now bolded for emphasis. - Values are colored for clarity (cyan for general info, green/red for statuses). - The layout is padded to ensure vertical alignment, making the information easier to scan.
1 parent 57075a3 commit 5063671

File tree

1 file changed

+39
-12
lines changed
  • packages/angular/cli/src/commands/cache/info

1 file changed

+39
-12
lines changed

packages/angular/cli/src/commands/cache/info/cli.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { tags } from '@angular-devkit/core';
109
import * as fs from 'node:fs/promises';
1110
import { join } from 'node:path';
1211
import { Argv } from 'yargs';
@@ -15,6 +14,7 @@ import {
1514
CommandModuleImplementation,
1615
CommandScope,
1716
} from '../../../command-builder/command-module';
17+
import { colors } from '../../../utilities/color';
1818
import { isCI } from '../../../utilities/environment-options';
1919
import { getCacheConfig } from '../utilities';
2020

@@ -29,15 +29,42 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu
2929
}
3030

3131
async run(): Promise<void> {
32-
const { path, environment, enabled } = getCacheConfig(this.context.workspace);
33-
34-
this.context.logger.info(tags.stripIndents`
35-
Enabled: ${enabled ? 'yes' : 'no'}
36-
Environment: ${environment}
37-
Path: ${path}
38-
Size on disk: ${await this.getSizeOfDirectory(path)}
39-
Effective status on current machine: ${this.effectiveEnabledStatus() ? 'enabled' : 'disabled'}
40-
`);
32+
const cacheConfig = getCacheConfig(this.context.workspace);
33+
const { path, environment, enabled } = cacheConfig;
34+
35+
const effectiveStatus = this.effectiveEnabledStatus(cacheConfig);
36+
const sizeOnDisk = await this.getSizeOfDirectory(path);
37+
38+
const info: { label: string; value: string }[] = [
39+
{
40+
label: 'Enabled',
41+
value: enabled ? colors.green('Yes') : colors.red('No'),
42+
},
43+
{
44+
label: 'Environment',
45+
value: colors.cyan(environment),
46+
},
47+
{
48+
label: 'Path',
49+
value: colors.cyan(path),
50+
},
51+
{
52+
label: 'Size on disk',
53+
value: colors.cyan(sizeOnDisk),
54+
},
55+
{
56+
label: 'Effective Status',
57+
value: effectiveStatus ? colors.green('Enabled') : colors.red('Disabled'),
58+
},
59+
];
60+
61+
const maxLabelLength = Math.max(...info.map((l) => l.label.length));
62+
63+
const output = info
64+
.map(({ label, value }) => `${colors.bold(label)}`.padEnd(maxLabelLength + 11) + `: ${value}`)
65+
.join('\n');
66+
67+
this.context.logger.info(`\n${colors.bold('Cache Information')}\n\n${output}\n`);
4168
}
4269

4370
private async getSizeOfDirectory(path: string): Promise<string> {
@@ -82,8 +109,8 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu
82109
return `${roundedSize.toFixed(fractionDigits)} ${abbreviations[index]}`;
83110
}
84111

85-
private effectiveEnabledStatus(): boolean {
86-
const { enabled, environment } = getCacheConfig(this.context.workspace);
112+
private effectiveEnabledStatus(cacheConfig: { enabled: boolean; environment: string }): boolean {
113+
const { enabled, environment } = cacheConfig;
87114

88115
if (enabled) {
89116
switch (environment) {

0 commit comments

Comments
 (0)