@code-pushup/cli 0.8.8 → 0.8.10

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.
Files changed (2) hide show
  1. package/index.js +72 -27
  2. package/package.json +43 -3
package/index.js CHANGED
@@ -816,13 +816,13 @@ function getGroupWithAudits(refSlug, refPlugin, plugins) {
816
816
  },
817
817
  []
818
818
  );
819
- const audits = groupAudits.sort(sortCategoryAudits);
819
+ const audits = groupAudits.sort(compareCategoryAudits);
820
820
  return {
821
821
  ...groupWithAudits,
822
822
  audits
823
823
  };
824
824
  }
825
- function sortCategoryAudits(a, b) {
825
+ function compareCategoryAudits(a, b) {
826
826
  if (a.weight !== b.weight) {
827
827
  return b.weight - a.weight;
828
828
  }
@@ -834,7 +834,7 @@ function sortCategoryAudits(a, b) {
834
834
  }
835
835
  return a.title.localeCompare(b.title);
836
836
  }
837
- function sortAudits(a, b) {
837
+ function compareAudits(a, b) {
838
838
  if (a.score !== b.score) {
839
839
  return a.score - b.score;
840
840
  }
@@ -1128,23 +1128,18 @@ function reportToCategoriesSection(report) {
1128
1128
  category.score
1129
1129
  )} Score: ${style(formatReportScore(category.score))}`;
1130
1130
  const categoryDocs = getDocsAndDescription(category);
1131
- const auditsAndGroups = category.refs.reduce(
1132
- (acc2, ref) => ({
1133
- ...acc2,
1134
- ...ref.type === "group" ? {
1135
- groups: [
1136
- ...acc2.groups,
1137
- getGroupWithAudits(ref.slug, ref.plugin, plugins)
1138
- ]
1139
- } : {
1140
- audits: [...acc2.audits, getAuditByRef(ref, plugins)]
1141
- }
1142
- }),
1143
- { groups: [], audits: [] }
1144
- );
1145
- const audits = auditsAndGroups.audits.sort(sortCategoryAudits).map((audit) => auditItemToCategorySection(audit, plugins)).join(NEW_LINE);
1146
- const groups = auditsAndGroups.groups.map((group) => groupItemToCategorySection(group, plugins)).join("");
1147
- return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + groups + NEW_LINE + audits;
1131
+ const categoryMDItems = category.refs.reduce((acc2, ref) => {
1132
+ if (ref.type === "group") {
1133
+ const group = getGroupWithAudits(ref.slug, ref.plugin, plugins);
1134
+ const mdGroupItem = groupItemToCategorySection(group, plugins);
1135
+ return acc2 + mdGroupItem + NEW_LINE;
1136
+ } else {
1137
+ const audit = getAuditByRef(ref, plugins);
1138
+ const mdAuditItem = auditItemToCategorySection(audit, plugins);
1139
+ return acc2 + mdAuditItem + NEW_LINE;
1140
+ }
1141
+ }, "");
1142
+ return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + categoryMDItems;
1148
1143
  }, "");
1149
1144
  return h2("\u{1F3F7} Categories") + NEW_LINE + categoryDetails;
1150
1145
  }
@@ -1183,7 +1178,7 @@ function groupItemToCategorySection(group, plugins) {
1183
1178
  }
1184
1179
  function reportToAuditsSection(report) {
1185
1180
  const auditsSection = report.plugins.reduce((acc, plugin) => {
1186
- const auditsData = plugin.audits.sort(sortAudits).reduce((acc2, audit) => {
1181
+ const auditsData = plugin.audits.reduce((acc2, audit) => {
1187
1182
  const auditTitle = `${audit.title} (${getPluginNameFromSlug(
1188
1183
  audit.plugin,
1189
1184
  report.plugins
@@ -1206,7 +1201,7 @@ function reportToAuditsSection(report) {
1206
1201
  }
1207
1202
  const detailsTableData = [
1208
1203
  detailsTableHeaders,
1209
- ...audit.details.issues.sort(compareIssues).map((issue) => {
1204
+ ...audit.details.issues.map((issue) => {
1210
1205
  const severity = `${getSeverityIcon(issue.severity)} <i>${issue.severity}</i>`;
1211
1206
  const message = issue.message;
1212
1207
  if (!issue.source) {
@@ -1310,7 +1305,7 @@ function reportToDetailSection(report) {
1310
1305
  output += addLine(chalk3.magentaBright.bold(`${title} audits`));
1311
1306
  output += addLine();
1312
1307
  const ui = cliui({ width: 80 });
1313
- audits.sort(sortAudits).forEach(({ score, title: title2, displayValue, value }) => {
1308
+ audits.forEach(({ score, title: title2, displayValue, value }) => {
1314
1309
  ui.div(
1315
1310
  {
1316
1311
  text: withColor({ score, text: "\u25CF" }),
@@ -1473,6 +1468,56 @@ var verboseUtils = (verbose) => ({
1473
1468
  exec: getExecVerbose(verbose)
1474
1469
  });
1475
1470
 
1471
+ // packages/utils/src/lib/sort-report.ts
1472
+ function sortReport(report) {
1473
+ const { categories, plugins } = report;
1474
+ const sortedCategories = categories.map((category) => {
1475
+ const { audits, groups } = category.refs.reduce(
1476
+ (acc, ref) => ({
1477
+ ...acc,
1478
+ ...ref.type === "group" ? {
1479
+ groups: [
1480
+ ...acc.groups,
1481
+ getGroupWithAudits(ref.slug, ref.plugin, plugins)
1482
+ ]
1483
+ } : {
1484
+ audits: [...acc.audits, getAuditByRef(ref, plugins)]
1485
+ }
1486
+ }),
1487
+ { groups: [], audits: [] }
1488
+ );
1489
+ const sortedAuditsAndGroups = [
1490
+ ...groups,
1491
+ ...audits.sort(compareCategoryAudits)
1492
+ ];
1493
+ const sortedRefs = category.refs.slice().sort((a, b) => {
1494
+ const aIndex = sortedAuditsAndGroups.findIndex(
1495
+ (ref) => ref.slug === a.slug
1496
+ );
1497
+ const bIndex = sortedAuditsAndGroups.findIndex(
1498
+ (ref) => ref.slug === b.slug
1499
+ );
1500
+ return aIndex - bIndex;
1501
+ });
1502
+ return { ...category, refs: sortedRefs };
1503
+ });
1504
+ const sortedPlugins = plugins.map((plugin) => ({
1505
+ ...plugin,
1506
+ audits: plugin.audits.sort(compareAudits).map((audit) => ({
1507
+ ...audit,
1508
+ details: {
1509
+ ...audit.details,
1510
+ issues: audit?.details?.issues.slice().sort(compareIssues) || []
1511
+ }
1512
+ }))
1513
+ }));
1514
+ return {
1515
+ ...report,
1516
+ categories: sortedCategories,
1517
+ plugins: sortedPlugins
1518
+ };
1519
+ }
1520
+
1476
1521
  // packages/core/src/lib/implementation/persist.ts
1477
1522
  var PersistDirError = class extends Error {
1478
1523
  constructor(outputDir) {
@@ -1486,8 +1531,8 @@ var PersistError = class extends Error {
1486
1531
  };
1487
1532
  async function persistReport(report, options2) {
1488
1533
  const { outputDir, filename, format } = options2;
1489
- const scoredReport = scoreReport(report);
1490
- console.info(reportToStdout(scoredReport));
1534
+ const sortedScoredReport = sortReport(scoreReport(report));
1535
+ console.info(reportToStdout(sortedScoredReport));
1491
1536
  const results = [];
1492
1537
  if (format.includes("json")) {
1493
1538
  results.push({
@@ -1500,7 +1545,7 @@ async function persistReport(report, options2) {
1500
1545
  validateCommitData(commitData);
1501
1546
  results.push({
1502
1547
  format: "md",
1503
- content: reportToMd(scoredReport, commitData)
1548
+ content: reportToMd(sortedScoredReport, commitData)
1504
1549
  });
1505
1550
  }
1506
1551
  if (!existsSync(outputDir)) {
@@ -1645,7 +1690,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1645
1690
 
1646
1691
  // packages/core/package.json
1647
1692
  var name = "@code-pushup/core";
1648
- var version = "0.8.8";
1693
+ var version = "0.8.10";
1649
1694
 
1650
1695
  // packages/core/src/lib/implementation/collect.ts
1651
1696
  async function collect(options2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/cli",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "bin": {
5
5
  "code-pushup": "index.js"
6
6
  },
@@ -10,5 +10,45 @@
10
10
  "yargs": "^17.7.2",
11
11
  "chalk": "^5.3.0",
12
12
  "@code-pushup/utils": "*"
13
- }
14
- }
13
+ },
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/code-pushup/cli#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/code-pushup/cli/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/code-pushup/cli.git",
22
+ "directory": "packages/cli"
23
+ },
24
+ "contributors": [
25
+ {
26
+ "name": "Igor Katsuba",
27
+ "email": "igor@katsuba.dev",
28
+ "url": "https://katsuba.dev"
29
+ },
30
+ {
31
+ "name": "Kateřina Pilátová",
32
+ "email": "katerina.pilatova@flowup.cz",
33
+ "url": "https://github.com/Tlacenka"
34
+ },
35
+ {
36
+ "name": "Matěj Chalk",
37
+ "email": "matej.chalk@flowup.cz",
38
+ "url": "https://github.com/matejchalk"
39
+ },
40
+ {
41
+ "name": "Michael Hladky",
42
+ "email": "michael.hladky@push-based.io",
43
+ "url": "https://push-based.io"
44
+ },
45
+ {
46
+ "name": "Michael Seredenko",
47
+ "email": "misha.seredenko@push-based.io",
48
+ "url": "https://github.com/MishaSeredenkoPushBased"
49
+ }
50
+ ],
51
+ "type": "module",
52
+ "main": "./index.js",
53
+ "types": "./src/index.d.ts"
54
+ }