@code-pushup/utils 0.8.11 → 0.8.13

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // packages/utils/src/lib/execute-process.ts
2
2
  import { spawn } from "node:child_process";
3
3
 
4
- // packages/utils/src/lib/report.ts
4
+ // packages/utils/src/lib/reports/utils.ts
5
5
  import { join as join2 } from "node:path";
6
6
 
7
7
  // packages/models/src/lib/audit.ts
@@ -557,12 +557,6 @@ var reportSchema = packageVersionSchema({
557
557
  })
558
558
  );
559
559
 
560
- // packages/utils/src/lib/constants.ts
561
- var SCORE_COLOR_RANGE = {
562
- GREEN_MIN: 0.9,
563
- YELLOW_MIN: 0.5
564
- };
565
-
566
560
  // packages/utils/src/lib/file-system.ts
567
561
  import { bundleRequire } from "bundle-require";
568
562
  import chalk from "chalk";
@@ -746,7 +740,14 @@ function findLineNumberInText(content, pattern) {
746
740
  return lineNumber === 0 ? null : lineNumber;
747
741
  }
748
742
 
749
- // packages/utils/src/lib/report.ts
743
+ // packages/utils/src/lib/reports/constants.ts
744
+ var NEW_LINE = "\n";
745
+ var SCORE_COLOR_RANGE = {
746
+ GREEN_MIN: 0.9,
747
+ YELLOW_MIN: 0.5
748
+ };
749
+
750
+ // packages/utils/src/lib/reports/utils.ts
750
751
  var FOOTER_PREFIX = "Made with \u2764 by";
751
752
  var CODE_PUSHUP_DOMAIN = "code-pushup.dev";
752
753
  var README_LINK = "https://github.com/flowup/quality-metrics-cli#readme";
@@ -1029,83 +1030,6 @@ function groupByStatus(results) {
1029
1030
  );
1030
1031
  }
1031
1032
 
1032
- // packages/utils/src/lib/md/details.ts
1033
- function details(title, content, cfg = { open: false }) {
1034
- return `<details${cfg.open ? " open" : ""}>
1035
- <summary>${title}</summary>
1036
- ${content}
1037
- </details>
1038
- `;
1039
- }
1040
-
1041
- // packages/utils/src/lib/md/headline.ts
1042
- function headline(text, hierarchy = 1) {
1043
- return `${new Array(hierarchy).fill("#").join("")} ${text}`;
1044
- }
1045
- function h2(text) {
1046
- return headline(text, 2);
1047
- }
1048
- function h3(text) {
1049
- return headline(text, 3);
1050
- }
1051
-
1052
- // packages/utils/src/lib/md/constants.ts
1053
- var NEW_LINE = "\n";
1054
-
1055
- // packages/utils/src/lib/md/table.ts
1056
- var alignString = /* @__PURE__ */ new Map([
1057
- ["l", ":--"],
1058
- ["c", ":--:"],
1059
- ["r", "--:"]
1060
- ]);
1061
- function tableMd(data, align) {
1062
- if (data.length === 0) {
1063
- throw new Error("Data can't be empty");
1064
- }
1065
- align = align || data[0]?.map(() => "c");
1066
- const _data = data.map((arr) => "|" + arr.join("|") + "|");
1067
- const secondRow = "|" + align?.map((s) => alignString.get(s)).join("|") + "|";
1068
- return _data.shift() + NEW_LINE + secondRow + NEW_LINE + _data.join(NEW_LINE);
1069
- }
1070
- function tableHtml(data) {
1071
- if (data.length === 0) {
1072
- throw new Error("Data can't be empty");
1073
- }
1074
- const _data = data.map((arr, index) => {
1075
- if (index === 0) {
1076
- return "<tr>" + arr.map((s) => `<th>${s}</th>`).join("") + "</tr>";
1077
- }
1078
- return "<tr>" + arr.map((s) => `<td>${s}</td>`).join("") + "</tr>";
1079
- });
1080
- return "<table>" + _data.join("") + "</table>";
1081
- }
1082
-
1083
- // packages/utils/src/lib/md/font-style.ts
1084
- var stylesMap = {
1085
- i: "_",
1086
- // italic
1087
- b: "**",
1088
- // bold
1089
- s: "~",
1090
- // strike through
1091
- c: "`"
1092
- // code
1093
- };
1094
- function style(text, styles = ["b"]) {
1095
- return styles.reduce((t, s) => `${stylesMap[s]}${t}${stylesMap[s]}`, text);
1096
- }
1097
-
1098
- // packages/utils/src/lib/md/link.ts
1099
- function link(href, text) {
1100
- return `[${text || href}](${href})`;
1101
- }
1102
-
1103
- // packages/utils/src/lib/md/list.ts
1104
- function li(text, order = "unordered") {
1105
- const style2 = order === "unordered" ? "-" : "- [ ]";
1106
- return `${style2} ${text}`;
1107
- }
1108
-
1109
1033
  // packages/utils/src/lib/progress.ts
1110
1034
  import chalk2 from "chalk";
1111
1035
  import { MultiProgressBars } from "multi-progress-bars";
@@ -1160,8 +1084,82 @@ function getProgressBar(taskName) {
1160
1084
  };
1161
1085
  }
1162
1086
 
1163
- // packages/utils/src/lib/report-to-md.ts
1164
- function reportToMd(report, commitData) {
1087
+ // packages/utils/src/lib/reports/md/details.ts
1088
+ function details(title, content, cfg = { open: false }) {
1089
+ return `<details${cfg.open ? " open" : ""}>
1090
+ <summary>${title}</summary>
1091
+ ${content}
1092
+ </details>
1093
+ `;
1094
+ }
1095
+
1096
+ // packages/utils/src/lib/reports/md/font-style.ts
1097
+ var stylesMap = {
1098
+ i: "_",
1099
+ // italic
1100
+ b: "**",
1101
+ // bold
1102
+ s: "~",
1103
+ // strike through
1104
+ c: "`"
1105
+ // code
1106
+ };
1107
+ function style(text, styles = ["b"]) {
1108
+ return styles.reduce((t, s) => `${stylesMap[s]}${t}${stylesMap[s]}`, text);
1109
+ }
1110
+
1111
+ // packages/utils/src/lib/reports/md/headline.ts
1112
+ function headline(text, hierarchy = 1) {
1113
+ return `${new Array(hierarchy).fill("#").join("")} ${text}`;
1114
+ }
1115
+ function h2(text) {
1116
+ return headline(text, 2);
1117
+ }
1118
+ function h3(text) {
1119
+ return headline(text, 3);
1120
+ }
1121
+
1122
+ // packages/utils/src/lib/reports/md/link.ts
1123
+ function link(href, text) {
1124
+ return `[${text || href}](${href})`;
1125
+ }
1126
+
1127
+ // packages/utils/src/lib/reports/md/list.ts
1128
+ function li(text, order = "unordered") {
1129
+ const style2 = order === "unordered" ? "-" : "- [ ]";
1130
+ return `${style2} ${text}`;
1131
+ }
1132
+
1133
+ // packages/utils/src/lib/reports/md/table.ts
1134
+ var alignString = /* @__PURE__ */ new Map([
1135
+ ["l", ":--"],
1136
+ ["c", ":--:"],
1137
+ ["r", "--:"]
1138
+ ]);
1139
+ function tableMd(data, align) {
1140
+ if (data.length === 0) {
1141
+ throw new Error("Data can't be empty");
1142
+ }
1143
+ align = align || data[0]?.map(() => "c");
1144
+ const _data = data.map((arr) => "|" + arr.join("|") + "|");
1145
+ const secondRow = "|" + align?.map((s) => alignString.get(s)).join("|") + "|";
1146
+ return _data.shift() + NEW_LINE + secondRow + NEW_LINE + _data.join(NEW_LINE);
1147
+ }
1148
+ function tableHtml(data) {
1149
+ if (data.length === 0) {
1150
+ throw new Error("Data can't be empty");
1151
+ }
1152
+ const _data = data.map((arr, index) => {
1153
+ if (index === 0) {
1154
+ return "<tr>" + arr.map((s) => `<th>${s}</th>`).join("") + "</tr>";
1155
+ }
1156
+ return "<tr>" + arr.map((s) => `<td>${s}</td>`).join("") + "</tr>";
1157
+ });
1158
+ return "<table>" + _data.join("") + "</table>";
1159
+ }
1160
+
1161
+ // packages/utils/src/lib/reports/generate-md-report.ts
1162
+ function generateMdReport(report, commitData) {
1165
1163
  let md = reportToHeaderSection() + NEW_LINE;
1166
1164
  md += reportToOverviewSection(report) + NEW_LINE + NEW_LINE;
1167
1165
  md += reportToCategoriesSection(report) + NEW_LINE + NEW_LINE;
@@ -1342,14 +1340,14 @@ function getAuditResult(audit, isHtml = false) {
1342
1340
  return isHtml ? `<b>${displayValue || value}</b>` : style(String(displayValue || value));
1343
1341
  }
1344
1342
 
1345
- // packages/utils/src/lib/report-to-stdout.ts
1343
+ // packages/utils/src/lib/reports/generate-stdout-summary.ts
1346
1344
  import cliui from "@isaacs/cliui";
1347
1345
  import chalk3 from "chalk";
1348
1346
  import Table from "cli-table3";
1349
1347
  function addLine(line = "") {
1350
1348
  return line + NEW_LINE;
1351
1349
  }
1352
- function reportToStdout(report) {
1350
+ function generateStdoutSummary(report) {
1353
1351
  let output = "";
1354
1352
  output += addLine(reportToHeaderSection2(report));
1355
1353
  output += addLine();
@@ -1506,7 +1504,7 @@ function toUnixPath(path, options) {
1506
1504
  return unixPath;
1507
1505
  }
1508
1506
 
1509
- // packages/utils/src/lib/scoring.ts
1507
+ // packages/utils/src/lib/reports/scoring.ts
1510
1508
  function calculateScore(refs, scoreFn) {
1511
1509
  const { numerator, denominator } = refs.reduce(
1512
1510
  (acc, ref) => {
@@ -1574,27 +1572,7 @@ function scoreReport(report) {
1574
1572
  return scoredReport;
1575
1573
  }
1576
1574
 
1577
- // packages/utils/src/lib/verbose-utils.ts
1578
- function getLogVerbose(verbose) {
1579
- return (...args) => {
1580
- if (verbose) {
1581
- console.info(...args);
1582
- }
1583
- };
1584
- }
1585
- function getExecVerbose(verbose) {
1586
- return (fn) => {
1587
- if (verbose) {
1588
- fn();
1589
- }
1590
- };
1591
- }
1592
- var verboseUtils = (verbose) => ({
1593
- log: getLogVerbose(verbose),
1594
- exec: getExecVerbose(verbose)
1595
- });
1596
-
1597
- // packages/utils/src/lib/sort-report.ts
1575
+ // packages/utils/src/lib/reports/sorting.ts
1598
1576
  function sortReport(report) {
1599
1577
  const { categories, plugins } = report;
1600
1578
  const sortedCategories = categories.map((category) => {
@@ -1643,10 +1621,29 @@ function sortReport(report) {
1643
1621
  plugins: sortedPlugins
1644
1622
  };
1645
1623
  }
1624
+
1625
+ // packages/utils/src/lib/verbose-utils.ts
1626
+ function getLogVerbose(verbose) {
1627
+ return (...args) => {
1628
+ if (verbose) {
1629
+ console.info(...args);
1630
+ }
1631
+ };
1632
+ }
1633
+ function getExecVerbose(verbose) {
1634
+ return (fn) => {
1635
+ if (verbose) {
1636
+ fn();
1637
+ }
1638
+ };
1639
+ }
1640
+ var verboseUtils = (verbose) => ({
1641
+ log: getLogVerbose(verbose),
1642
+ exec: getExecVerbose(verbose)
1643
+ });
1646
1644
  export {
1647
1645
  CODE_PUSHUP_DOMAIN,
1648
1646
  FOOTER_PREFIX,
1649
- NEW_LINE,
1650
1647
  ProcessError,
1651
1648
  README_LINK,
1652
1649
  calcDuration,
@@ -1661,6 +1658,8 @@ export {
1661
1658
  findLineNumberInText,
1662
1659
  formatBytes,
1663
1660
  formatDuration,
1661
+ generateMdReport,
1662
+ generateStdoutSummary,
1664
1663
  getLatestCommit,
1665
1664
  getProgressBar,
1666
1665
  git,
@@ -1679,8 +1678,6 @@ export {
1679
1678
  pluralizeToken,
1680
1679
  readJsonFile,
1681
1680
  readTextFile,
1682
- reportToMd,
1683
- reportToStdout,
1684
1681
  scoreReport,
1685
1682
  slugify,
1686
1683
  sortReport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.8.11",
3
+ "version": "0.8.13",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
package/src/index.d.ts CHANGED
@@ -5,12 +5,11 @@ export { getLatestCommit, git } from './lib/git';
5
5
  export { groupByStatus } from './lib/group-by-status';
6
6
  export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
7
7
  export { logMultipleResults } from './lib/log-results';
8
- export { NEW_LINE } from './lib/md';
9
8
  export { ProgressBar, getProgressBar } from './lib/progress';
10
- export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, calcDuration, compareIssueSeverity, loadReport, } from './lib/report';
11
- export { reportToMd } from './lib/report-to-md';
12
- export { reportToStdout } from './lib/report-to-stdout';
13
- export { ScoredReport, scoreReport } from './lib/scoring';
9
+ export { generateMdReport } from './lib/reports/generate-md-report';
10
+ export { generateStdoutSummary } from './lib/reports/generate-stdout-summary';
11
+ export { ScoredReport, scoreReport } from './lib/reports/scoring';
12
+ export { sortReport } from './lib/reports/sorting';
13
+ export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, calcDuration, compareIssueSeverity, loadReport, } from './lib/reports/utils';
14
14
  export { CliArgsObject, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toUnixPath, } from './lib/transform';
15
15
  export { verboseUtils } from './lib/verbose-utils';
16
- export { sortReport } from './lib/sort-report';
@@ -1,3 +1,4 @@
1
+ export declare const NEW_LINE = "\n";
1
2
  export declare const SCORE_COLOR_RANGE: {
2
3
  GREEN_MIN: number;
3
4
  YELLOW_MIN: number;
@@ -0,0 +1,3 @@
1
+ import { CommitData } from '../git';
2
+ import { ScoredReport } from './scoring';
3
+ export declare function generateMdReport(report: ScoredReport, commitData: CommitData | null): string;
@@ -0,0 +1,2 @@
1
+ import { ScoredReport } from './scoring';
2
+ export declare function generateStdoutSummary(report: ScoredReport): string;
@@ -1,7 +1,6 @@
1
1
  export * from './details';
2
- export * from './headline';
3
- export * from './table';
4
- export * from './constants';
5
2
  export * from './font-style';
3
+ export * from './headline';
6
4
  export * from './link';
7
5
  export * from './list';
6
+ export * from './table';
@@ -1 +0,0 @@
1
- export declare const NEW_LINE = "\n";
@@ -1,3 +0,0 @@
1
- import { CommitData } from './git';
2
- import { ScoredReport } from './scoring';
3
- export declare function reportToMd(report: ScoredReport, commitData: CommitData | null): string;
@@ -1,2 +0,0 @@
1
- import { ScoredReport } from './scoring';
2
- export declare function reportToStdout(report: ScoredReport): string;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes