Skip to content

TypeScript plugin setup wizard #1256

@matejchalk

Description

@matejchalk

User story

Our setup wizard should be able to configure a basic working version of each of our official plugins. Each plugin may prompt for its own specific configuration options and infer smart defaults from the user's repo. The resulting configuration code adds the plugin to the user's config and sets up some basic categories.

This issue is about @code-pushup/typescript-plugin specifically.

Output example

import typescriptPlugin from '@code-pushup/typescript-plugin';
import type { CoreConfig } from '@code-pushup/models';

const config: CoreConfig = {
  plugins: [
    typescriptPlugin({ tsconfig: 'tsconfig.json' }),
  ],
  categories: [
    {
      slug: 'bug-prevention',
      title: 'Bug prevention',
      description: 'Type checks that find **potential bugs** in your code.',
      refs: [
        { type: 'group', plugin: 'typescript', slug: 'problems', weight: 1 },
      ],
    },
  ],
};

export default config;

Category merging

import eslintPlugin from '@code-pushup/eslint-plugin';
import typescriptPlugin from '@code-pushup/typescript-plugin';
import type { CoreConfig } from '@code-pushup/models';

const config: CoreConfig = {
  plugins: [
    await eslintPlugin(),
    typescriptPlugin(),
  ],
  categories: [
    {
      slug: 'bug-prevention',
      title: 'Bug prevention',
      description: 'Type checks and lint rules that find **potential bugs** in your code.',
      refs: [
        { type: 'group', plugin: 'typescript', slug: 'problems', weight: 1 },
        { type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 },
      ],
    },
  ],
};

export default config;

Acceptance criteria

  • The TypeScript plugin is auto-selected if a tsconfig.json or tsconfig.base.json file exists in the root directory. Otherwise, it is unselected by default.
  • The user is prompted (or provides a CLI argument) for their TypeScript config file.
    • Any tsconfig.json file in the project directory is suggested as the default option.
  • The user should confirm (via prompt or CLI argument) if they want to also generate basic categories.
    • The default answer is yes (create the categories).
    • If confirmed, 1 category is created - Bug prevention (from problems group).
    • If denied, no categories are created.
  • All of the above logic lives in @code-pushup/typescript-plugin. The core of the setup wizard in @code-pushup/create-cli orchestrates plugin selection and generation, but doesn't know any specifics about individual plugins.
  • In general, it's possible for plugins to create the same category. This needs to be handled by the core logic in @code-pushup/create-cli - the refs are merged into 1 category.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions