Skip to content

Commit ca6be2c

Browse files
committed
refactor(utils): move and rename ansis link utility
1 parent 84cf595 commit ca6be2c

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type CollectAndPersistReportsOptions,
55
collectAndPersistReports,
66
} from '@code-pushup/core';
7-
import { link, logger, ui } from '@code-pushup/utils';
7+
import { formatAsciiLink, logger, ui } from '@code-pushup/utils';
88
import { CLI_NAME } from '../constants.js';
99
import {
1010
collectSuccessfulLog,
@@ -51,15 +51,15 @@ export function renderUploadAutorunHint(): void {
5151
)}`,
5252
)
5353
.add(
54-
` ${link(
54+
` ${formatAsciiLink(
5555
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command',
5656
)}`,
5757
)
5858
.add(
5959
`${ansis.gray('❯')} npx code-pushup autorun - ${ansis.gray('Run collect & upload')}`,
6060
)
6161
.add(
62-
` ${link(
62+
` ${formatAsciiLink(
6363
'https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command',
6464
)}`,
6565
)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import ansis from 'ansis';
2-
import { link, logger, ui } from '@code-pushup/utils';
2+
import { formatAsciiLink, logger, ui } from '@code-pushup/utils';
33

44
export function renderConfigureCategoriesHint(): void {
55
logger.debug(
6-
`💡 Configure categories to see the scores in an overview table. See: ${link(
6+
`💡 Configure categories to see the scores in an overview table. See: ${formatAsciiLink(
77
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md',
88
)}`,
99
{ force: true },
1010
);
1111
}
1212
export function uploadSuccessfulLog(url: string): void {
1313
logger.info(ansis.green('Upload successful!'));
14-
logger.info(link(url));
14+
logger.info(formatAsciiLink(url));
1515
}
1616

1717
export function collectSuccessfulLog(): void {
@@ -30,17 +30,17 @@ export function renderIntegratePortalHint(): void {
3030
)}`,
3131
)
3232
.add(
33-
` ${link(
33+
` ${formatAsciiLink(
3434
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command',
3535
)}`,
3636
)
3737
.add(
38-
`${ansis.gray('❯')} ${ansis.gray('Portal Integration')} - ${link(
38+
`${ansis.gray('❯')} ${ansis.gray('Portal Integration')} - ${formatAsciiLink(
3939
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration',
4040
)}`,
4141
)
4242
.add(
43-
`${ansis.gray('❯')} ${ansis.gray('Upload Command')} - ${link(
43+
`${ansis.gray('❯')} ${ansis.gray('Upload Command')} - ${formatAsciiLink(
4444
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration',
4545
)}`,
4646
)

packages/plugin-lighthouse/src/lib/runner/runner.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import type { AuditOutputs, RunnerFunction } from '@code-pushup/models';
55
import {
66
addIndex,
77
ensureDirectoryExists,
8-
link,
8+
formatAsciiLink,
99
logger,
1010
shouldExpandForUrls,
1111
stringifyError,
12-
ui,
1312
} from '@code-pushup/utils';
1413
import type { LighthouseOptions } from '../types.js';
1514
import { DEFAULT_CLI_FLAGS } from './constants.js';
@@ -82,7 +81,7 @@ async function runLighthouseForUrl(
8281

8382
if (runnerResult == null) {
8483
throw new Error(
85-
`Lighthouse did not produce a result for URL: ${link(url)}`,
84+
`Lighthouse did not produce a result for URL: ${formatAsciiLink(url)}`,
8685
);
8786
}
8887

packages/utils/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export {
8888
export { interpolate } from './lib/interpolate.js';
8989
export { logMultipleResults } from './lib/log-results.js';
9090
export { Logger, logger } from './lib/logger.js';
91-
export { link, ui, type CliUi } from './lib/logging.js';
91+
export { ui, type CliUi } from './lib/logging.js';
9292
export { mergeConfigs } from './lib/merge-configs.js';
9393
export {
9494
addIndex,
@@ -144,6 +144,9 @@ export {
144144
formatReportScore,
145145
} from './lib/reports/utils.js';
146146
export { isSemver, normalizeSemver, sortSemvers } from './lib/semver.js';
147+
export { formatAsciiLink } from './lib/text-formats/ascii/link.js';
148+
export { formatAsciiTable } from './lib/text-formats/ascii/table.js';
149+
export { formatAsciiTree } from './lib/text-formats/ascii/tree.js';
147150
export * from './lib/text-formats/index.js';
148151
export {
149152
countOccurrences,

packages/utils/src/lib/logging.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { cliui } from '@poppinss/cliui';
2-
import ansis from 'ansis';
32

43
// TODO: remove once logger is used everywhere
54

@@ -12,7 +11,3 @@ export function ui(): CliUi {
1211
cliUISingleton ??= cliui();
1312
return cliUISingleton;
1413
}
15-
16-
export function link(text: string) {
17-
return ansis.underline.blueBright(text);
18-
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ansis from 'ansis';
2+
3+
export function formatAsciiLink(url: string): string {
4+
return ansis.underline.blueBright(url);
5+
}

0 commit comments

Comments
 (0)