Skip to content

Commit db44dff

Browse files
committed
feat(cli): simplify sticker hints
1 parent f3cebd3 commit db44dff

File tree

5 files changed

+57
-65
lines changed

5 files changed

+57
-65
lines changed

e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Commands:
88
[default]
99
code-pushup autorun Shortcut for running collect followed by upload
1010
11-
code-pushup collect Run Plugins and collect results
11+
code-pushup collect Run plugins and collect results
1212
code-pushup upload Upload report results to the portal
1313
code-pushup history Collect reports for commit history
1414
code-pushup compare Compare 2 report files and create a diff file

packages/cli/src/lib/autorun/autorun-command.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { logger } from '@code-pushup/utils';
99
import {
1010
collectSuccessfulLog,
1111
printCliCommand,
12-
renderConfigureCategoriesHint,
13-
renderIntegratePortalHint,
12+
renderCategoriesHint,
13+
renderPortalHint,
1414
uploadSuccessfulLog,
1515
} from '../implementation/logging.js';
1616

@@ -40,8 +40,10 @@ export function yargsAutorunCommandObject() {
4040
await collectAndPersistReports(optionsWithFormat);
4141
collectSuccessfulLog();
4242

43-
if (!options.categories || options.categories.length === 0) {
44-
renderConfigureCategoriesHint();
43+
if (!options.categories?.length) {
44+
logger.newline();
45+
renderCategoriesHint();
46+
logger.newline();
4547
}
4648

4749
if (options.upload) {
@@ -50,8 +52,9 @@ export function yargsAutorunCommandObject() {
5052
uploadSuccessfulLog(report.url);
5153
}
5254
} else {
53-
logger.warn('Upload skipped because configuration is not set.');
54-
renderIntegratePortalHint();
55+
logger.warn('Upload skipped because Portal is not configured.');
56+
logger.newline();
57+
renderPortalHint();
5558
}
5659
},
5760
} satisfies CommandModule;
Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
import ansis from 'ansis';
21
import type { ArgumentsCamelCase, CommandModule } from 'yargs';
32
import {
43
type CollectAndPersistReportsOptions,
54
collectAndPersistReports,
65
} from '@code-pushup/core';
7-
import {
8-
formatAsciiLink,
9-
formatAsciiSticker,
10-
logger,
11-
} from '@code-pushup/utils';
6+
import { logger } from '@code-pushup/utils';
127
import {
138
collectSuccessfulLog,
149
printCliCommand,
15-
renderConfigureCategoriesHint,
10+
renderCategoriesHint,
11+
renderPortalHint,
12+
renderUploadHint,
1613
} from '../implementation/logging.js';
1714

1815
export function yargsCollectCommandObject(): CommandModule {
1916
const command = 'collect';
2017
return {
2118
command,
22-
describe: 'Run Plugins and collect results',
19+
describe: 'Run plugins and collect results',
2320
handler: async <T>(args: ArgumentsCamelCase<T>) => {
2421
printCliCommand(command);
2522

@@ -28,36 +25,21 @@ export function yargsCollectCommandObject(): CommandModule {
2825
await collectAndPersistReports(options);
2926
collectSuccessfulLog();
3027

31-
if (!options.categories || options.categories.length === 0) {
32-
renderConfigureCategoriesHint();
28+
if (!options.categories?.length) {
29+
logger.newline();
30+
renderCategoriesHint();
3331
}
3432

35-
const { upload = {} } = args as unknown as Record<
33+
const { upload } = args as unknown as Record<
3634
'upload',
3735
object | undefined
3836
>;
39-
if (Object.keys(upload).length === 0) {
40-
renderUploadAutorunHint();
37+
logger.newline();
38+
if (upload) {
39+
renderUploadHint();
40+
} else {
41+
renderPortalHint();
4142
}
4243
},
4344
} satisfies CommandModule;
4445
}
45-
46-
export function renderUploadAutorunHint(): void {
47-
logger.info(
48-
formatAsciiSticker([
49-
ansis.bold.gray('💡 Visualize your reports'),
50-
'',
51-
`${ansis.gray('❯')} npx code-pushup upload - ${ansis.gray(
52-
'Run upload to upload the created report to the server',
53-
)}`,
54-
` ${formatAsciiLink(
55-
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command',
56-
)}`,
57-
`${ansis.gray('❯')} npx code-pushup autorun - ${ansis.gray('Run collect & upload')}`,
58-
` ${formatAsciiLink(
59-
'https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command',
60-
)}`,
61-
]),
62-
);
63-
}

packages/cli/src/lib/implementation/logging.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@ import {
66
} from '@code-pushup/utils';
77

88
export function printCliCommand(command: string): void {
9-
logger.debug(`Running ${ansis.bold(command)} command\n`);
9+
logger.debug(`Running ${ansis.bold(command)} command`);
1010
}
1111

12-
export function renderConfigureCategoriesHint(): void {
13-
logger.debug(
14-
`💡 Configure categories to see the scores in an overview table. See: ${formatAsciiLink(
15-
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md',
16-
)}`,
17-
{ force: true },
18-
);
19-
}
2012
export function uploadSuccessfulLog(url: string): void {
2113
logger.info(ansis.green('Upload successful!'));
2214
logger.info(formatAsciiLink(url));
@@ -26,23 +18,35 @@ export function collectSuccessfulLog(): void {
2618
logger.info(ansis.green('Collecting report successful!'));
2719
}
2820

29-
export function renderIntegratePortalHint(): void {
21+
export function renderCategoriesHint(): void {
22+
logger.info(
23+
formatAsciiSticker([
24+
ansis.bold.gray('💡 Configure categories'),
25+
'',
26+
ansis.gray('❯ Aggregate audit scores to get a high-level overview'),
27+
`${ansis.gray('❯')} ${formatAsciiLink('https://www.npmjs.com/package/@code-pushup/cli')}`,
28+
]),
29+
);
30+
}
31+
32+
export function renderPortalHint(): void {
33+
logger.info(
34+
formatAsciiSticker([
35+
ansis.bold.gray('💡 Upload report to Portal'),
36+
'',
37+
ansis.gray('❯ Visualize reports in an interactive UI'),
38+
ansis.gray('❯ Track long-term progress via reports history'),
39+
`${ansis.gray('❯')} ${formatAsciiLink('https://code-pushup.dev/')}`,
40+
]),
41+
);
42+
}
43+
44+
export function renderUploadHint(): void {
3045
logger.info(
3146
formatAsciiSticker([
32-
ansis.bold.gray('💡 Integrate the portal'),
47+
ansis.bold.gray('💡 Upload report to Portal'),
3348
'',
34-
`${ansis.gray('❯')} Upload a report to the server - ${ansis.gray(
35-
'npx code-pushup upload',
36-
)}`,
37-
` ${formatAsciiLink(
38-
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command',
39-
)}`,
40-
`${ansis.gray('❯')} ${ansis.gray('Portal Integration')} - ${formatAsciiLink(
41-
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration',
42-
)}`,
43-
`${ansis.gray('❯')} ${ansis.gray('Upload Command')} - ${formatAsciiLink(
44-
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration',
45-
)}`,
49+
`${ansis.gray('❯')} npx code-pushup upload`,
4650
]),
4751
);
4852
}

packages/cli/src/lib/upload/upload-command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { ArgumentsCamelCase, CommandModule } from 'yargs';
22
import { type UploadOptions, upload } from '@code-pushup/core';
3+
import { logger } from '@code-pushup/utils';
34
import {
45
printCliCommand,
5-
renderIntegratePortalHint,
6+
renderPortalHint,
67
uploadSuccessfulLog,
78
} from '../implementation/logging.js';
89

@@ -16,8 +17,10 @@ export function yargsUploadCommandObject() {
1617

1718
const options = args as unknown as UploadOptions;
1819
if (options.upload == null) {
19-
renderIntegratePortalHint();
20-
throw new Error('Upload configuration not set');
20+
logger.newline();
21+
renderPortalHint();
22+
logger.newline();
23+
throw new Error('Upload to Portal is missing configuration');
2124
}
2225
const report = await upload(options);
2326
if (report?.url) {

0 commit comments

Comments
 (0)