@code-pushup/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # @code-pushup/cli
2
+
3
+ 🔎🔬 **Quality metrics for your software project.** 📉🔍
4
+
5
+ 1. ⚙️ **Configure what you want to track using your favourite tools.**
6
+ 2. 🤖 **Integrate it in your CI.**
7
+ 3. 🌈 **Visualize reports in a beautiful dashboard.**
8
+
9
+ ---
10
+
11
+ The Code PushUp CLI serves to **collect audit results**, and optionally **upload the report** to the Code PushUp portal.
12
+
13
+ It can be used locally in your repository, or integrated in your CI environment.
14
+
15
+ _If you're looking for programmatic usage, then refer to the underlying [@code-pushup/core](../core/README.md) package instead._
16
+
17
+ ## Getting started
18
+
19
+ 1. Install as a dev dependency with your package manager:
20
+
21
+ ```sh
22
+ npm install --save-dev @code-pushup/cli
23
+ ```
24
+
25
+ ```sh
26
+ yarn add --dev @code-pushup/cli
27
+ ```
28
+
29
+ ```sh
30
+ pnpm add --save-dev @code-pushup/cli
31
+ ```
32
+
33
+ 2. Create a `code-pushup.config.js` configuration file (`.ts` or `.mjs` extensions are also supported).
34
+
35
+ ```js
36
+ export default {
37
+ persist: {
38
+ outputDir: '.code-pushup',
39
+ format: ['json', 'md'],
40
+ },
41
+ plugins: [
42
+ // ...
43
+ ],
44
+ categories: [
45
+ // ...
46
+ ],
47
+ };
48
+ ```
49
+
50
+ 3. Add plugins as per your project needs (e.g. [@code-pushup/eslint-plugin](../plugin-eslint/README.md)).
51
+
52
+ ```sh
53
+ npm install --save-dev @code-pushup/eslint-plugin
54
+ ```
55
+
56
+ ```js
57
+ import eslintPlugin from '@code-pushup/eslint-plugin';
58
+
59
+ export default {
60
+ // ...
61
+ plugins: [
62
+ // ...
63
+ await eslintPlugin({ eslintrc: '.eslintrc.js', patterns: ['src/**/*.js'] }),
64
+ ],
65
+ };
66
+ ```
67
+
68
+ 4. Define your custom categories.
69
+
70
+ ```js
71
+ export default {
72
+ // ...
73
+ categories: [
74
+ {
75
+ slug: 'performance',
76
+ title: 'Performance',
77
+ refs: [
78
+ {
79
+ type: 'audit',
80
+ plugin: 'eslint',
81
+ slug: 'react-jsx-key',
82
+ weight: 1,
83
+ },
84
+ // ...
85
+ ],
86
+ },
87
+ // ...
88
+ ],
89
+ };
90
+ ```
91
+
92
+ 5. Run the CLI with `npx code-pushup` (see `--help` for list of commands and arguments).
93
+
94
+ 6. View report file(s) in output directory (specified by `persist.outputDir` configuration).
95
+
96
+ ## Portal integration
97
+
98
+ If you have access to the Code PushUp portal, provide credentials in order to upload reports.
99
+
100
+ ```js
101
+ export default {
102
+ // ...
103
+ upload: {
104
+ server: 'https://ip-or-domain/path/to/portal/api/graphql',
105
+ apiKey: process.env.PORTAL_API_KEY,
106
+ organization: 'my-org',
107
+ project: 'my-project',
108
+ },
109
+ };
110
+ ```
111
+
112
+ ## CI automation
113
+
114
+ Example for GitHub Actions:
115
+
116
+ ```yml
117
+ name: Code PushUp
118
+
119
+ on: push
120
+
121
+ jobs:
122
+ collect-and-upload:
123
+ runs-on: ubuntu-latest
124
+ steps:
125
+ - uses: actions/checkout@v3
126
+ - uses: actions/setup-node@v3
127
+ - run: npm ci
128
+ - run: npx code-pushup autorun --upload.apiKey=${{ secrets.PORTAL_API_KEY }}
129
+ ```
130
+
131
+ ## CLI commands and options
132
+
133
+ ### Global Options
134
+
135
+ | Option | Type | Default | Description |
136
+ | ---------------- | --------- | ----------------------- | ---------------------------------------------------------------------- |
137
+ | **`--progress`** | `boolean` | `true` | Show progress bar in stdout. |
138
+ | **`--verbose`** | `boolean` | `false` | When true creates more verbose output. This is helpful when debugging. |
139
+ | **`--config`** | `string` | `code-pushup.config.js` | Path to the config file, e.g. code-pushup.config.js |
140
+
141
+ ### Common Command Options
142
+
143
+ | Option | Type | Default | Description |
144
+ | --------------------------- | -------------------- | -------- | --------------------------------------------------------------------------- |
145
+ | **`--persist.outputDir`** | `string` | n/a | Directory for the produced reports. |
146
+ | **`--persist.filename`** | `string` | `report` | Filename for the produced reports without extension. |
147
+ | **`--persist.format`** | `('json' \| 'md')[]` | `json` | Format(s) of the report file. |
148
+ | **`--upload.organization`** | `string` | n/a | Organization slug from portal. |
149
+ | **`--upload.project`** | `string` | n/a | Project slug from portal. |
150
+ | **`--upload.server`** | `string` | n/a | URL to your portal server. |
151
+ | **`--upload.apiKey`** | `string` | n/a | API key for the portal server. |
152
+ | **`--onlyPlugins`** | `string[]` | `[]` | Only run the specified plugins. Applicable to all commands except `upload`. |
153
+
154
+ > [!NOTE]
155
+ > All common options, expect `--onlyPlugins`, can be specified in the configuration file as well.
156
+ > CLI arguments take precedence over configuration file options.
157
+
158
+ > [!NOTE]
159
+ > The `--upload.*` group of options is applicable to all commands except `collect`.
160
+
161
+ ### Commands
162
+
163
+ #### `collect` command
164
+
165
+ Usage:
166
+ `code-pushup collect [options]`
167
+
168
+ Description:
169
+ The command initializes the necessary plugins, runs them, and then collects the results. After collecting the results, it generates a comprehensive report.
170
+
171
+ Refer to the [Common Command Options](#common-command-options) for the list of available options.
172
+
173
+ #### `upload` command
174
+
175
+ Usage:
176
+ `code-pushup upload [options]`
177
+
178
+ Description:
179
+ Upload reports to the Code PushUp portal.
180
+
181
+ Refer to the [Common Command Options](#common-command-options) for the list of available options.
182
+
183
+ #### `autorun` command
184
+
185
+ Usage:
186
+ `code-pushup autorun [options]`
187
+
188
+ Description:
189
+ Run plugins, collect results and upload report to the Code PushUp portal.
190
+
191
+ Refer to the [Common Command Options](#common-command-options) for the list of available options.
192
+
193
+ #### `print-config` command
194
+
195
+ Usage:
196
+ `code-pushup print-config [options]`
197
+
198
+ Description:
199
+ Print the resolved configuration.
200
+
201
+ Refer to the [Common Command Options](#common-command-options) for the list of available options.