Skip to content

Commit

Permalink
feat(cli): add skip and only category filters
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-skryl authored Oct 4, 2024
1 parent 9d75682 commit 149f54b
Show file tree
Hide file tree
Showing 23 changed files with 1,049 additions and 775 deletions.
22 changes: 13 additions & 9 deletions e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ Commands:
Global Options:
--progress Show progress bar in stdout.
--progress Show progress bar in stdout.
[boolean] [default: true]
--verbose When true creates more verbose output. This is helpful when
debugging. [boolean] [default: false]
--config Path to config file. By default it loads code-pushup.config
.(ts|mjs|js). [string]
--tsconfig Path to a TypeScript config, to be used when loading config
file. [string]
-p, --onlyPlugins List of plugins to run. If not set all plugins are run.
--verbose When true creates more verbose output. This is helpful w
hen debugging. [boolean] [default: false]
--config Path to config file. By default it loads code-pushup.con
fig.(ts|mjs|js). [string]
--tsconfig Path to a TypeScript config, to be used when loading con
fig file. [string]
--skipCategories List of categories to skip. If not set all categories ar
e run. [array] [default: []]
--onlyCategories List of categories to run. If not set all categories are
run. [array] [default: []]
-P, --skipPlugins List of plugins to skip. If not set all plugins are run.
[array] [default: []]
-P, --skipPlugins List of plugins to skip. If not set all plugins are run.
-p, --onlyPlugins List of plugins to run. If not set all plugins are run.
[array] [default: []]
Persist Options:
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/lib/history/history-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
ui,
} from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import { yargsOnlyPluginsOptionsDefinition } from '../implementation/only-plugins.options';
import { yargsSkipPluginsOptionsDefinition } from '../implementation/skip-plugins.options';
import { yargsFilterOptionsDefinition } from '../implementation/filter.options';
import type { HistoryCliOptions } from './history.model';
import { yargsHistoryOptionsDefinition } from './history.options';
import { normalizeHashOptions } from './utils';
Expand Down Expand Up @@ -65,8 +64,7 @@ export function yargsHistoryCommandObject() {
builder: yargs => {
yargs.options({
...yargsHistoryOptionsDefinition(),
...yargsOnlyPluginsOptionsDefinition(),
...yargsSkipPluginsOptionsDefinition(),
...yargsFilterOptionsDefinition(),
});
yargs.group(
Object.keys(yargsHistoryOptionsDefinition()),
Expand Down
12 changes: 3 additions & 9 deletions packages/cli/src/lib/implementation/core-config.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ import {
uploadConfigSchema,
} from '@code-pushup/models';
import type { CoreConfigCliOptions } from './core-config.model';
import type { FilterOptions } from './filter.model';
import type { GeneralCliOptions } from './global.model';
import type { OnlyPluginsOptions } from './only-plugins.model';
import type { SkipPluginsOptions } from './skip-plugins.model';

export type CoreConfigMiddlewareOptions = GeneralCliOptions &
CoreConfigCliOptions &
OnlyPluginsOptions &
SkipPluginsOptions;
FilterOptions;

export async function coreConfigMiddleware<
T extends CoreConfigMiddlewareOptions,
>(
processArgs: T,
): Promise<
GeneralCliOptions & CoreConfig & OnlyPluginsOptions & SkipPluginsOptions
> {
>(processArgs: T): Promise<GeneralCliOptions & CoreConfig & FilterOptions> {
const {
config,
tsconfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {
normalizeFormats,
} from './core-config.middleware';
import type { CoreConfigCliOptions } from './core-config.model';
import type { FilterOptions } from './filter.model';
import type { GeneralCliOptions } from './global.model';
import type { OnlyPluginsOptions } from './only-plugins.model';
import type { SkipPluginsOptions } from './skip-plugins.model';

vi.mock('@code-pushup/core', async () => {
const { CORE_CONFIG_MOCK }: typeof import('@code-pushup/test-utils') =
Expand Down Expand Up @@ -41,18 +40,15 @@ describe('normalizeFormats', () => {
describe('coreConfigMiddleware', () => {
it('should attempt to load code-pushup.config.(ts|mjs|js) by default', async () => {
await coreConfigMiddleware(
{} as GeneralCliOptions &
CoreConfigCliOptions &
OnlyPluginsOptions &
SkipPluginsOptions,
{} as GeneralCliOptions & CoreConfigCliOptions & FilterOptions,
);
expect(autoloadRc).toHaveBeenCalled();
});

it('should directly attempt to load passed config', async () => {
await coreConfigMiddleware({
config: 'cli/custom-config.mjs',
} as GeneralCliOptions & CoreConfigCliOptions & OnlyPluginsOptions & SkipPluginsOptions);
} as GeneralCliOptions & CoreConfigCliOptions & FilterOptions);
expect(autoloadRc).not.toHaveBeenCalled();
expect(readRcByPath).toHaveBeenCalledWith(
'cli/custom-config.mjs',
Expand All @@ -63,15 +59,15 @@ describe('coreConfigMiddleware', () => {
it('should forward --tsconfig option to config autoload', async () => {
await coreConfigMiddleware({
tsconfig: 'tsconfig.base.json',
} as GeneralCliOptions & CoreConfigCliOptions & OnlyPluginsOptions & SkipPluginsOptions);
} as GeneralCliOptions & CoreConfigCliOptions & FilterOptions);
expect(autoloadRc).toHaveBeenCalledWith('tsconfig.base.json');
});

it('should forward --tsconfig option to custom config load', async () => {
await coreConfigMiddleware({
config: 'apps/website/code-pushup.config.ts',
tsconfig: 'apps/website/tsconfig.json',
} as GeneralCliOptions & CoreConfigCliOptions & OnlyPluginsOptions & SkipPluginsOptions);
} as GeneralCliOptions & CoreConfigCliOptions & FilterOptions);
expect(readRcByPath).toHaveBeenCalledWith(
'apps/website/code-pushup.config.ts',
'apps/website/tsconfig.json',
Expand Down
64 changes: 0 additions & 64 deletions packages/cli/src/lib/implementation/filter-plugins.middleware.ts

This file was deleted.

Loading

0 comments on commit 149f54b

Please sign in to comment.