Skip to content

Commit d6270a5

Browse files
authored
fix(cli): set terminal output to full width (#362)
1 parent f350148 commit d6270a5

File tree

9 files changed

+29
-12
lines changed

9 files changed

+29
-12
lines changed

e2e/cli-e2e/tests/collect.e2e.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
33

44
describe('CLI collect', () => {
55
const exampleCategoryTitle = 'Code style';
6-
const exampleAuditTitle = 'Require `const` declarations for variables';
6+
const exampleAuditTitle = 'Disallow unused variables';
77

88
/* eslint-disable @typescript-eslint/no-unused-vars */
99
const omitVariableData = ({

examples/plugins/project.json

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
"^build",
5454
{ "projects": ["cli"], "target": "build" }
5555
]
56+
},
57+
"run-help": {
58+
"command": "npx dist/packages/cli help",
59+
"dependsOn": [
60+
"build",
61+
"^build",
62+
{ "projects": ["cli"], "target": "build" }
63+
]
5664
}
5765
},
5866
"tags": ["scope:internal", "type:feature"]

packages/cli/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"dependsOn": ["build"]
5151
},
5252
"run-collect": {
53-
"command": "npx ../../dist/packages/cli collect --persist.format=stdout --persist.format=md",
53+
"command": "npx ../../dist/packages/cli collect --persist.format=json --persist.format=md",
5454
"options": {
5555
"cwd": "examples/react-todos-app"
5656
},

packages/cli/src/lib/yargs-cli.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import yargs, {
88
ParserConfigurationOptions,
99
} from 'yargs';
1010
import { PersistConfig, formatSchema } from '@code-pushup/models';
11+
import { TERMINAL_WIDTH } from '@code-pushup/utils';
1112
import { logErrorBeforeThrow } from './implementation/global.utils';
1213

1314
/**
@@ -53,7 +54,9 @@ export function yargsCli<T = unknown>(
5354
.coerce('config', (config: string | string[]) =>
5455
Array.isArray(config) ? config.at(-1) : config,
5556
)
56-
.options(options);
57+
.options(options)
58+
// take full width of the terminal `cli.terminalWidth()`
59+
.wrap(TERMINAL_WIDTH);
5760

5861
// usage message
5962
if (usageMessage) {

packages/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export {
5151
compareIssueSeverity,
5252
loadReport,
5353
} from './lib/reports/utils';
54+
export { TERMINAL_WIDTH } from './lib/reports/constants';
5455
export {
5556
CliArgsObject,
5657
countOccurrences,

packages/utils/src/lib/progress.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk';
22
import { CtorOptions, MultiProgressBars } from 'multi-progress-bars';
3+
import { TERMINAL_WIDTH } from './reports/constants';
34

45
type BarStyles = 'active' | 'done' | 'idle';
56
type StatusStyles = Record<BarStyles, (s: string) => string>;
@@ -30,6 +31,7 @@ export function getSingletonProgressBars(
3031
): MultiProgressBars {
3132
if (!mpb) {
3233
mpb = new MultiProgressBars({
34+
progressWidth: TERMINAL_WIDTH,
3335
initMessage: '',
3436
border: true,
3537
...options,

packages/utils/src/lib/reports/__snapshots__/generate-stdout-summary.integration.test.ts.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ Lighthouse audits
7575
7676
Categories
7777
78-
┌────────────────┬───────┬────────┐
79-
│ Category │ Score │ Audits │
80-
├────────────────┼───────┼────────┤
81-
│ Performance │ 92 │ 6 │
82-
├────────────────┼───────┼────────┤
83-
│ Bug prevention │ 68 │ 16 │
84-
├────────────────┼───────┼────────┤
85-
│ Code style │ 54 │ 13 │
86-
└────────────────┴───────┴────────┘
78+
┌─────────────────────────────────────────────────────────────┬───────┬────────┐
79+
│ Category │ Score │ Audits │
80+
├─────────────────────────────────────────────────────────────┼───────┼────────┤
81+
│ Performance │ 92 │ 6 │
82+
├─────────────────────────────────────────────────────────────┼───────┼────────┤
83+
│ Bug prevention │ 68 │ 16 │
84+
├─────────────────────────────────────────────────────────────┼───────┼────────┤
85+
│ Code style │ 54 │ 13 │
86+
└─────────────────────────────────────────────────────────────┴───────┴────────┘
8787
8888
Made with ❤ by code-pushup.dev
8989
"

packages/utils/src/lib/reports/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// https://stackoverflow.com/questions/4651012/why-is-the-default-terminal-width-80-characters/4651037#4651037
12
export const TERMINAL_WIDTH = 80;
23
export const NEW_LINE = '\n';
34

packages/utils/src/lib/reports/generate-stdout-summary.ts

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function reportToOverviewSection({
7373
plugins,
7474
}: ScoredReport): string {
7575
const table = new CliTable3({
76+
// eslint-disable-next-line no-magic-numbers
77+
colWidths: [TERMINAL_WIDTH - 7 - 8 - 4, 7, 8],
7678
head: reportRawOverviewTableHeaders,
7779
colAligns: ['left', 'right', 'right'],
7880
style: {

0 commit comments

Comments
 (0)