@code-pushup/cli

中文文档
0.126.4发布于 2026/09/11MITTypeScriptES Module构建来源已验证近 30 天下载 6320

A CLI to run all kinds of code quality measurements to align your team with company goals

原始使用文档
文档目录11 节
  1. Getting started
  2. Set up categories (optional)
  3. Portal integration
  4. 🛠 CI automation
  5. Configuration
  6. Custom Plugins
  7. CLI commands and options
  8. Global Options
  9. Common Command Options
  10. Commands
  11. Caching

@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
Getting started cover imagePortal integration cover imageCI Automation cover

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:

    Installation command for npm, yarn and pnpm
    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, you can enable report uploads by installing the @code-pushup/portal-client package.

Installation command for npm, yarn and pnpm
npm install --save-dev @code-pushup/portal-client
yarn add --dev @code-pushup/portal-client
pnpm add --save-dev @code-pushup/portal-client

Once the package is installed, update your configuration file to include your portal credentials:

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
--verbosebooleanprocess.env['CP_VERBOSE'] if set, otherwise falseToggles whether to print debug logs.
--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

Global Options

OptionTypeDefaultDescription
--onlyPluginsstring[][]Only run the specified plugins. Applicable to all commands except upload.
--skipPluginsstring[][]Skip the specified plugins. Applicable to all commands except upload.
--onlyCategoriesstring[][]Only run the specified categories. Applicable to all commands except upload.
--skipCategoriesstring[][]Skip the specified categories. Applicable to all commands except upload.

Cache Options

OptionTypeDefaultDescription
--cachebooleanfalseCache runner outputs (both read and write).
--cache.readbooleanfalseIf plugin audit outputs should be read from file system cache.
--cache.writebooleanfalseIf plugin audit outputs should be written to file system cache.

Persist 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.
--persist.skipReportsbooleanfalseSkip generating report files. (useful in combination with caching)

Upload Options

OptionTypeDefaultDescription
--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.

[!NOTE]
All common options, except --onlyPlugins and --skipPlugins, 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

example of code-pushup terminal output

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 recognized by the compare command:

OptionTypeDefaultDescription
--beforestring.code-pushup/report-before.json [^1]Path to source report.json.
--afterstring.code-pushup/report-after.json [^1]Path to target report.json.
--labelstringn/a [^2]Label for diff (e.g. project name).

[^1]: Uses persist config to determine report paths, so default file paths are actually ${persist.outputDir}/${persist.filename}-before.json and ${persist.outputDir}/${persist.filename}-after.json.

[^2]: Uses label from input report.json files is they both have the same value.

print-config command

Usage: code-pushup print-config [options]

Description: Print the resolved configuration.

In addition to the Common Command Options, the following options are recognized by the print-config command:

OptionRequiredTypeDescription
--outputyesstringPath to output file to print config.

merge-diffs command

Usage: code-pushup merge-diffs --files PATH_1 PATH_2 ... [options]

Description: Combine multiple report diffs into a single report-diff.md.

In addition to the Common Command Options, the following options are recognized by the merge-diffs command:

OptionRequiredTypeDescription
--filesyesstring[]List of report-diff.json paths.

Caching

The CLI supports caching to speed up subsequent runs and is compatible with Nx and Turborepo.

Depending on your strategy, you can cache the generated reports files or plugin runner output. For fine-grained caching, we suggest caching plugin runner output.

The detailed example for Nx caching and Turborepo caching is available in the docs.

版本与发布记录

@code-pushup/cli 共发布 256 个版本,首次发布于 2023/12/01;过去 12 个月发布了 62 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.126.4latest2026/09/111 个月前
0.126.32026/05/195 个月前
0.126.22026/03/317 个月前
0.126.12026/03/317 个月前
0.126.02026/03/307 个月前
0.125.02026/03/277 个月前

关于 @code-pushup/cli 的常见问题

@code-pushup/cli 是什么?

A CLI to run all kinds of code quality measurements to align your team with company goals

如何安装 @code-pushup/cli?

在项目目录运行 npm install @code-pushup/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 code-pushup,可以用 npx code-pushup 直接运行。

@code-pushup/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@code-pushup/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@code-pushup/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@code-pushup/cli 可以商用吗?

@code-pushup/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@code-pushup/cli 的下载量有多少?

根据 npm 官方下载统计,@code-pushup/cli 在 2026/10/10 – 2026/11/08 这 30 天内被下载 6,320 次,日均约 211 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@code-pushup/cli 还在维护吗?

最新版本 0.126.4 发布于 2026/09/11(1 个月前);至今共发布 256 个版本,其中过去 12 个月发布了 62 个;首次发布于 2023/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。