1
1
import { join } from 'node:path' ;
2
2
import {
3
3
AuditReport ,
4
+ CategoryConfig ,
4
5
CategoryRef ,
5
6
IssueSeverity as CliIssueSeverity ,
6
7
Format ,
7
8
Group ,
8
9
Issue ,
9
10
PersistConfig ,
11
+ PluginReport ,
10
12
Report ,
11
13
reportSchema ,
12
14
} from '@code-pushup/models' ;
@@ -16,11 +18,32 @@ import {
16
18
readTextFile ,
17
19
} from '../file-system' ;
18
20
import { SCORE_COLOR_RANGE } from './constants' ;
19
- import {
20
- EnrichedScoredGroupWithAudits ,
21
- ScoredReport ,
22
- WeighedAuditReport ,
23
- } from './scoring' ;
21
+
22
+ export type WeighedScoredGroup = EnrichedScoredGroupWithAudits & {
23
+ weight : number ;
24
+ } ;
25
+
26
+ export type WeighedAuditReport = AuditReport & {
27
+ weight : number ;
28
+ plugin : string ;
29
+ } ;
30
+ export type EnrichedScoredGroupWithAudits = EnrichedScoredGroup & {
31
+ audits : AuditReport [ ] ;
32
+ } ;
33
+ export type ScoredCategoryConfig = CategoryConfig & { score : number } ;
34
+
35
+ export type EnrichedScoredGroup = Group & {
36
+ plugin : string ;
37
+ score : number ;
38
+ } ;
39
+
40
+ export type ScoredReport = Omit < Report , 'plugins' | 'categories' > & {
41
+ plugins : ( Omit < PluginReport , 'audits' | 'groups' > & {
42
+ audits : AuditReport [ ] ;
43
+ groups : EnrichedScoredGroup [ ] ;
44
+ } ) [ ] ;
45
+ categories : ScoredCategoryConfig [ ] ;
46
+ } ;
24
47
25
48
export const FOOTER_PREFIX = 'Made with ❤ by' ; // replace ❤️ with ❤, because of ❤️ has output issues
26
49
export const CODE_PUSHUP_DOMAIN = 'code-pushup.dev' ;
@@ -152,44 +175,46 @@ export function getAuditByRef(
152
175
return {
153
176
...audit ,
154
177
weight,
178
+ plugin,
155
179
} ;
156
180
}
157
181
158
182
export function getGroupWithAudits (
159
- refSlug : string ,
160
- refPlugin : string ,
183
+ ref : CategoryRef ,
161
184
plugins : ScoredReport [ 'plugins' ] ,
162
- ) : EnrichedScoredGroupWithAudits {
163
- const plugin = plugins . find ( ( { slug } ) => slug === refPlugin ) ;
185
+ ) : WeighedScoredGroup {
186
+ const plugin = plugins . find ( ( { slug } ) => slug === ref . plugin ) ;
164
187
if ( ! plugin ) {
165
- throwIsNotPresentError ( `Plugin ${ refPlugin } ` , 'report' ) ;
188
+ throwIsNotPresentError ( `Plugin ${ ref . plugin } ` , 'report' ) ;
166
189
}
167
- const groupWithAudits = plugin . groups ?. find ( ( { slug } ) => slug === refSlug ) ;
190
+ const groupWithAudits = plugin . groups ?. find ( ( { slug } ) => slug === ref . slug ) ;
168
191
169
192
if ( ! groupWithAudits ) {
170
- throwIsNotPresentError ( `Group ${ refSlug } ` , plugin . slug ) ;
193
+ throwIsNotPresentError ( `Group ${ ref . slug } ` , plugin . slug ) ;
171
194
}
172
195
const groupAudits = groupWithAudits . refs . reduce < WeighedAuditReport [ ] > (
173
- ( acc : WeighedAuditReport [ ] , ref ) => {
196
+ ( acc : WeighedAuditReport [ ] , groupRef ) => {
174
197
const audit = getAuditByRef (
175
- { ...ref , plugin : refPlugin , type : 'audit' } ,
198
+ { ...groupRef , plugin : ref . plugin , type : 'audit' } ,
176
199
plugins ,
177
200
) ;
178
201
return [ ...acc , audit ] ;
179
202
} ,
180
203
[ ] ,
181
204
) ;
182
- const audits = [ ...groupAudits ] . sort ( compareCategoryAudits ) ;
205
+ const audits = [ ...groupAudits ] . sort ( compareCategoryAuditsAndGroups ) ;
183
206
184
207
return {
185
208
...groupWithAudits ,
186
209
audits,
210
+ weight : ref . weight ,
211
+ plugin : ref . plugin ,
187
212
} ;
188
213
}
189
214
190
- export function compareCategoryAudits (
191
- a : WeighedAuditReport ,
192
- b : WeighedAuditReport ,
215
+ export function compareCategoryAuditsAndGroups (
216
+ a : WeighedAuditReport | WeighedScoredGroup ,
217
+ b : WeighedAuditReport | WeighedScoredGroup ,
193
218
) : number {
194
219
if ( a . weight !== b . weight ) {
195
220
return b . weight - a . weight ;
@@ -199,7 +224,7 @@ export function compareCategoryAudits(
199
224
return a . score - b . score ;
200
225
}
201
226
202
- if ( a . value !== b . value ) {
227
+ if ( 'value' in a && 'value' in b && a . value !== b . value ) {
203
228
return b . value - a . value ;
204
229
}
205
230
0 commit comments