Skip to content

Commit

Permalink
fix(cli): set terminal output to full width (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Jan 26, 2024
1 parent f350148 commit d6270a5
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';

describe('CLI collect', () => {
const exampleCategoryTitle = 'Code style';
const exampleAuditTitle = 'Require `const` declarations for variables';
const exampleAuditTitle = 'Disallow unused variables';

/* eslint-disable @typescript-eslint/no-unused-vars */
const omitVariableData = ({
Expand Down
8 changes: 8 additions & 0 deletions examples/plugins/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
"^build",
{ "projects": ["cli"], "target": "build" }
]
},
"run-help": {
"command": "npx dist/packages/cli help",
"dependsOn": [
"build",
"^build",
{ "projects": ["cli"], "target": "build" }
]
}
},
"tags": ["scope:internal", "type:feature"]
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dependsOn": ["build"]
},
"run-collect": {
"command": "npx ../../dist/packages/cli collect --persist.format=stdout --persist.format=md",
"command": "npx ../../dist/packages/cli collect --persist.format=json --persist.format=md",
"options": {
"cwd": "examples/react-todos-app"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/lib/yargs-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import yargs, {
ParserConfigurationOptions,
} from 'yargs';
import { PersistConfig, formatSchema } from '@code-pushup/models';
import { TERMINAL_WIDTH } from '@code-pushup/utils';
import { logErrorBeforeThrow } from './implementation/global.utils';

/**
Expand Down Expand Up @@ -53,7 +54,9 @@ export function yargsCli<T = unknown>(
.coerce('config', (config: string | string[]) =>
Array.isArray(config) ? config.at(-1) : config,
)
.options(options);
.options(options)
// take full width of the terminal `cli.terminalWidth()`
.wrap(TERMINAL_WIDTH);

// usage message
if (usageMessage) {
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
compareIssueSeverity,
loadReport,
} from './lib/reports/utils';
export { TERMINAL_WIDTH } from './lib/reports/constants';
export {
CliArgsObject,
countOccurrences,
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/src/lib/progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk';
import { CtorOptions, MultiProgressBars } from 'multi-progress-bars';
import { TERMINAL_WIDTH } from './reports/constants';

type BarStyles = 'active' | 'done' | 'idle';
type StatusStyles = Record<BarStyles, (s: string) => string>;
Expand Down Expand Up @@ -30,6 +31,7 @@ export function getSingletonProgressBars(
): MultiProgressBars {
if (!mpb) {
mpb = new MultiProgressBars({
progressWidth: TERMINAL_WIDTH,
initMessage: '',
border: true,
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ Lighthouse audits
Categories
┌────────────────┬───────┬────────┐
│ Category │ Score │ Audits │
├────────────────┼───────┼────────┤
│ Performance │ 92 │ 6 │
├────────────────┼───────┼────────┤
│ Bug prevention │ 68 │ 16 │
├────────────────┼───────┼────────┤
│ Code style │ 54 │ 13 │
└────────────────┴───────┴────────┘
┌─────────────────────────────────────────────────────────────┬───────┬────────┐
│ Category │ Score │ Audits │
├─────────────────────────────────────────────────────────────┼───────┼────────┤
│ Performance │ 92 │ 6 │
├─────────────────────────────────────────────────────────────┼───────┼────────┤
│ Bug prevention │ 68 │ 16 │
├─────────────────────────────────────────────────────────────┼───────┼────────┤
│ Code style │ 54 │ 13 │
└─────────────────────────────────────────────────────────────┴───────┴────────┘
Made with ❤ by code-pushup.dev
"
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/lib/reports/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// https://stackoverflow.com/questions/4651012/why-is-the-default-terminal-width-80-characters/4651037#4651037
export const TERMINAL_WIDTH = 80;
export const NEW_LINE = '\n';

Expand Down
2 changes: 2 additions & 0 deletions packages/utils/src/lib/reports/generate-stdout-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function reportToOverviewSection({
plugins,
}: ScoredReport): string {
const table = new CliTable3({
// eslint-disable-next-line no-magic-numbers
colWidths: [TERMINAL_WIDTH - 7 - 8 - 4, 7, 8],
head: reportRawOverviewTableHeaders,
colAligns: ['left', 'right', 'right'],
style: {
Expand Down

0 comments on commit d6270a5

Please sign in to comment.