0.39.0 ā€¢ Published 13 days ago

@code-pushup/cli v0.39.0

Weekly downloads
-
License
MIT
Repository
github
Last release
13 days ago

@code-pushup/cli

npm downloads dependencies

šŸ”ŽšŸ”¬ Quality metrics for your software project. šŸ“‰šŸ”

  1. āš™ļø Configure what you want to track using your favourite tools.
  2. šŸ¤– Integrate it in your CI.
  3. šŸŒˆ Visualize reports in a beautiful dashboard.

šŸ“Š Getting StartedšŸŒ Portal IntegrationšŸ› ļø CI Automation
How to setup a basic projectSort, filter your goalsUpdates on every PR

The Code PushUp CLI serves to collect audit results, and optionally upload the report to the Code PushUp portal.

It can be used locally in your repository, or integrated in your CI environment.

If you're looking for programmatic usage, then refer to the underlying @code-pushup/core package instead.

Getting started

  1. Install as a dev dependency with your package manager:

    npm install --save-dev @code-pushup/cli
    yarn add --dev @code-pushup/cli
    pnpm add --save-dev @code-pushup/cli
  2. Create a code-pushup.config.ts configuration file (.js or .mjs extensions are also supported).

    import type { CoreConfig } from '@code-pushup/models';
    
    const config: CoreConfig = {
      plugins: [
        // ...
      ],
    };
    
    export default config;
  3. Add plugins as per your project needs (e.g. @code-pushup/eslint-plugin or @code-pushup/coverage-plugin).

    npm install --save-dev @code-pushup/eslint-plugin
    import eslintPlugin from '@code-pushup/eslint-plugin';
    import type { CoreConfig } from '@code-pushup/models';
    
    const config: CoreConfig = {
      // ...
      plugins: [
        // ...
        await eslintPlugin({ eslintrc: '.eslintrc.js', patterns: ['src/**/*.js'] }),
      ],
    };
    
    export default config;
  4. Run the CLI with npx code-pushup (see --help for list of commands and arguments).

  5. View report file(s) in output directory (specified by persist.outputDir configuration).
    This folder should be ignored in your .gitignore.

Set up categories (optional)

  1. Define your custom categories.

    const config: CoreConfig = {
      // ...
      categories: [
        {
          slug: 'performance',
          title: 'Performance',
          refs: [
            // reference to an existing audit or group from plugins
            {
              type: 'audit',
              plugin: 'eslint',
              slug: 'react-jsx-key',
              weight: 1,
            },
            // ...
          ],
        },
        // ...
      ],
    };
  2. Run the CLI with npx code-pushup.

  3. View report file(s) including category section in output directory.

Portal integration

If you have access to the Code PushUp portal, provide credentials in order to upload reports.

const config: CoreConfig = {
  // ...
  upload: {
    server: 'https://ip-or-domain/path/to/portal/api/graphql',
    apiKey: process.env.PORTAL_API_KEY,
    organization: 'my-org',
    project: 'my-project',
  },
};

šŸ›  CI automation

Example for GitHub Actions:

name: Code PushUp

on: push

jobs:
  collect-and-upload:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npx code-pushup autorun --upload.apiKey=${{ secrets.PORTAL_API_KEY }}

Configuration

For a comprehensive list of all options available in the config file, refer to CoreConfig docs.

The default locations for the config file are code-pushup.config.ts, code-pushup.config.mjs or code-pushup.config.js. Other locations require using the --config=<path> CLI option.

If your config file relies on some custom TypeScript project configuration - e.g. import aliases via compilerOptions.paths (common in Nx) - you can use the --tsconfig=<path> CLI option.

Custom Plugins

We provide comprehensive documentation on how to create a custom plugin.

The repository also maintains a set of plugin examples showcasing different scenarios.
Each example is fully tested to demonstrate best practices for plugin testing as well.

Example for custom plugins:

  • šŸ“ File Size - example of basic runner executor
  • šŸ“¦ Package Json - example of audits and groups
  • šŸ”„ Lighthouse (official implementation here) - example of a basic command executor

CLI commands and options

Global Options

OptionTypeDefaultDescription
--progressbooleantrueShow progress bar in stdout.
--verbosebooleanfalseWhen true creates more verbose output. This is helpful when debugging.
--configstringlooks for code-pushup.config.{ts\|mjs\|js}Path to config file.
--tsconfigstringn/aPath to a TypeScript config, used to load config file.

!NOTE
By default, the CLI loads code-pushup.config.(ts|mjs|js) if no config path is provided with --config.

Common Command Options

OptionTypeDefaultDescription
--persist.outputDirstringn/aDirectory for the produced reports.
--persist.filenamestringreportFilename for the produced reports without extension.
--persist.format('json' \| 'md')[]jsonFormat(s) of the report file.
--upload.organizationstringn/aOrganization slug from portal.
--upload.projectstringn/aProject slug from portal.
--upload.serverstringn/aURL to your portal server.
--upload.apiKeystringn/aAPI key for the portal server.
--onlyPluginsstring[][]Only run the specified plugins. Applicable to all commands except upload.

!NOTE
All common options, except --onlyPlugins, can be specified in the configuration file as well. CLI arguments take precedence over configuration file options.

!NOTE
The --upload.* group of options is applicable to all commands except collect.

Commands

collect command

Usage: code-pushup collect [options]

Description: The command initializes and executes the necessary plugins and collects the results. Based on the results it generates a comprehensive report.

Refer to the Common Command Options for the list of available options.

upload command

Usage: code-pushup upload [options]

Description: Upload reports to the Code PushUp portal.

Refer to the Common Command Options for the list of available options.

autorun command

Usage: code-pushup autorun [options]

Description: Run plugins, collect results and upload the report to the Code PushUp portal.

Refer to the Common Command Options for the list of available options.

history command

Usage: code-pushup history

Description: Run plugins, collect results and upload the report to the Code PushUp portal for a specified number of commits.

Refer to the Common Command Options for the list of available options.

OptionTypeDefaultDescription
--targetBranchstring'main'Branch to crawl history.
--forceCleanStatusbooleanfalseIf we reset the status to a clean git history forcefully or not.
--maxCountnumber5Number of commits.
--skipUploadsbooleanfalseUpload created reports
--fromstringn/aHash to start in history
--tostringn/aHash to end in history

compare command

Usage: code-pushup compare --before SOURCE_PATH --after TARGET_PATH [options]

Description: Compare 2 reports and produce a report diff file.

In addition to the Common Command Options, the following options are required:

OptionTypeDescription
--beforestringPath to source report.json.
--afterstringPath to target report.json.

print-config command

Usage: code-pushup print-config [options]

Description: Print the resolved configuration.

Refer to the Common Command Options for the list of available options.

0.39.0

13 days ago

0.35.0

1 month ago

0.34.0

1 month ago

0.30.0-alpha

1 month ago

0.29.0

2 months ago

0.28.0

2 months ago

0.27.1

2 months ago

0.26.1

2 months ago

0.26.0

2 months ago

0.25.7

2 months ago

0.25.6

2 months ago

0.23.1

2 months ago

0.23.0

3 months ago

0.22.8

3 months ago

0.22.7

3 months ago

0.22.6

3 months ago

0.22.5

3 months ago

0.22.4

3 months ago

0.22.3

3 months ago

0.22.2

3 months ago

0.21.1

3 months ago

0.20.1

3 months ago

0.20.0

3 months ago

0.21.0

3 months ago

0.18.1

3 months ago

0.19.0

3 months ago

0.20.2

3 months ago

0.18.0

3 months ago

0.17.0

3 months ago

0.16.8

3 months ago

0.16.4

3 months ago

0.16.5

3 months ago

0.16.6

3 months ago

0.16.7

3 months ago

0.16.3

3 months ago

0.16.2

3 months ago

0.16.0

3 months ago

0.16.1

3 months ago

0.15.0

3 months ago

0.14.2

3 months ago

0.14.3

3 months ago

0.14.4

3 months ago

0.14.1

3 months ago

0.13.0

3 months ago

0.13.1

3 months ago

0.13.2

3 months ago

0.14.0

3 months ago

0.12.10

3 months ago

0.12.7

3 months ago

0.12.8

3 months ago

0.12.9

3 months ago

0.12.3

3 months ago

0.12.4

3 months ago

0.12.5

3 months ago

0.12.6

3 months ago

0.12.1

3 months ago

0.12.2

3 months ago

0.11.2

3 months ago

0.12.0

3 months ago

0.11.1

4 months ago

0.11.0

4 months ago

0.9.0

4 months ago

0.10.1

4 months ago

0.10.2

4 months ago

0.10.3

4 months ago

0.10.4

4 months ago

0.10.5

4 months ago

0.10.6

4 months ago

0.10.7

4 months ago

0.10.0

4 months ago

0.8.25

4 months ago

0.8.24

4 months ago

0.8.23

4 months ago

0.8.22

4 months ago

0.8.21

4 months ago

0.8.20

4 months ago

0.8.19

4 months ago

0.8.16

4 months ago

0.8.15

4 months ago

0.8.18

4 months ago

0.8.17

4 months ago

0.8.12

4 months ago

0.8.11

4 months ago

0.8.14

4 months ago

0.8.13

4 months ago

0.8.10

4 months ago

0.8.9

4 months ago

0.8.8

4 months ago

0.8.5

4 months ago

0.8.4

4 months ago

0.8.7

4 months ago

0.8.6

4 months ago

0.8.3

4 months ago

0.8.2

4 months ago

0.8.1

4 months ago

0.8.0

4 months ago

0.7.0

4 months ago

0.6.6

4 months ago

0.6.3

4 months ago

0.6.5

4 months ago

0.6.4

4 months ago

0.6.2

4 months ago

0.5.7

4 months ago

0.6.1

4 months ago

0.6.0

4 months ago

0.5.6

4 months ago

0.5.5

5 months ago

0.5.4

5 months ago

0.5.3

5 months ago

0.5.2

5 months ago

0.5.1

5 months ago

0.5.0

5 months ago

0.4.5

5 months ago

0.4.4

5 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.4.1

5 months ago

0.3.2

5 months ago

0.4.0

5 months ago

0.3.0

5 months ago

0.2.0

5 months ago

0.3.1

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago