@code-pushup/cli 0.14.4 → 0.16.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/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { hideBin } from "yargs/helpers";
5
5
 
6
6
  // packages/cli/src/lib/autorun/autorun-command.ts
7
- import chalk5 from "chalk";
7
+ import chalk7 from "chalk";
8
8
 
9
9
  // packages/models/src/lib/audit.ts
10
10
  import { z as z2 } from "zod";
@@ -919,6 +919,13 @@ function compareIssues(a, b) {
919
919
  }
920
920
  return 0;
921
921
  }
922
+ function portalCommitLink(config, commit) {
923
+ const { organization, project, baseUrl } = config;
924
+ return `${baseUrl}/portal/${organization}/${project}/commit/${commit}`;
925
+ }
926
+ function portalCommitDashboardLink(config, commit) {
927
+ return `${portalCommitLink(config, commit)}/dashboard`;
928
+ }
922
929
 
923
930
  // packages/utils/src/lib/execute-process.ts
924
931
  var ProcessError = class extends Error {
@@ -975,6 +982,19 @@ async function getLatestCommit() {
975
982
  });
976
983
  return log.latest;
977
984
  }
985
+ function validateCommitData(commitData, options2 = {}) {
986
+ const { throwError = false } = options2;
987
+ if (!commitData) {
988
+ const msg = "no commit data available";
989
+ if (throwError) {
990
+ throw new Error(msg);
991
+ } else {
992
+ console.warn(msg);
993
+ return false;
994
+ }
995
+ }
996
+ return true;
997
+ }
978
998
 
979
999
  // packages/utils/src/lib/group-by-status.ts
980
1000
  function groupByStatus(results) {
@@ -1311,9 +1331,9 @@ function reportToDetailSection(report) {
1311
1331
  const { plugins } = report;
1312
1332
  return plugins.reduce((acc, plugin) => {
1313
1333
  const { title, audits } = plugin;
1314
- const ui = cliui({ width: TERMINAL_WIDTH });
1334
+ const ui2 = cliui({ width: TERMINAL_WIDTH });
1315
1335
  audits.forEach((audit) => {
1316
- ui.div(
1336
+ ui2.div(
1317
1337
  {
1318
1338
  text: withColor({ score: audit.score, text: "\u25CF" }),
1319
1339
  width: 2,
@@ -1331,7 +1351,7 @@ function reportToDetailSection(report) {
1331
1351
  }
1332
1352
  );
1333
1353
  });
1334
- return acc + addLine() + addLine(chalk3.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui.toString()) + addLine();
1354
+ return acc + addLine() + addLine(chalk3.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui2.toString()) + addLine();
1335
1355
  }, "");
1336
1356
  }
1337
1357
  function reportToOverviewSection2({
@@ -1536,12 +1556,18 @@ var verboseUtils = (verbose = false) => ({
1536
1556
  exec: getExecVerbose(verbose)
1537
1557
  });
1538
1558
 
1559
+ // packages/utils/src/lib/logging.ts
1560
+ import chalk4 from "chalk";
1561
+ function link2(text) {
1562
+ return chalk4.underline(chalk4.blueBright(text));
1563
+ }
1564
+
1539
1565
  // packages/core/package.json
1540
1566
  var name = "@code-pushup/core";
1541
- var version = "0.14.4";
1567
+ var version = "0.16.0";
1542
1568
 
1543
1569
  // packages/core/src/lib/implementation/execute-plugin.ts
1544
- import chalk4 from "chalk";
1570
+ import chalk5 from "chalk";
1545
1571
 
1546
1572
  // packages/core/src/lib/implementation/runner.ts
1547
1573
  import { join as join2 } from "node:path";
@@ -1611,7 +1637,7 @@ async function executePlugins(plugins, options2) {
1611
1637
  const { progress = false } = options2 ?? {};
1612
1638
  const progressBar = progress ? getProgressBar("Run plugins") : null;
1613
1639
  const pluginsResult = await plugins.reduce(async (acc, pluginCfg) => {
1614
- progressBar?.updateTitle(`Executing ${chalk4.bold(pluginCfg.title)}`);
1640
+ progressBar?.updateTitle(`Executing ${chalk5.bold(pluginCfg.title)}`);
1615
1641
  try {
1616
1642
  const pluginReport = await executePlugin(pluginCfg);
1617
1643
  progressBar?.incrementInSteps(plugins.length);
@@ -1718,11 +1744,6 @@ async function persistReport(report, options2) {
1718
1744
  )
1719
1745
  );
1720
1746
  }
1721
- function validateCommitData(commitData) {
1722
- if (!commitData) {
1723
- console.warn("no commit data available");
1724
- }
1725
- }
1726
1747
  async function persistResult(reportPath, content) {
1727
1748
  return writeFile(reportPath, content).then(() => stat2(reportPath)).then((stats) => [reportPath, stats.size]).catch((error) => {
1728
1749
  console.warn(error);
@@ -1909,6 +1930,60 @@ async function upload(options2, uploadFn = uploadToPortal) {
1909
1930
  var CLI_NAME = "Code PushUp CLI";
1910
1931
  var CLI_SCRIPT_NAME = "code-pushup";
1911
1932
 
1933
+ // packages/cli/src/lib/implementation/logging.ts
1934
+ import { cliui as cliui2 } from "@poppinss/cliui";
1935
+ import chalk6 from "chalk";
1936
+ var singletonUiInstance;
1937
+ function ui() {
1938
+ if (singletonUiInstance === void 0) {
1939
+ singletonUiInstance = cliui2();
1940
+ }
1941
+ return singletonUiInstance;
1942
+ }
1943
+ function renderConfigureCategoriesHint() {
1944
+ ui().logger.info(
1945
+ chalk6.gray(
1946
+ `\u{1F4A1} Configure categories to see the scores in an overview table. See: ${link2(
1947
+ "https://github.com/code-pushup/cli/blob/main/packages/cli/README.md"
1948
+ )}`
1949
+ )
1950
+ );
1951
+ }
1952
+ function uploadSuccessfulLog(options2, commit) {
1953
+ ui().logger.success("Upload successful!");
1954
+ ui().logger.success(
1955
+ link2(
1956
+ // @TODO extend config to maintain baseUrl under upload
1957
+ portalCommitDashboardLink(
1958
+ { ...options2, baseUrl: "<YOUR_PORTAL_URL>" },
1959
+ commit
1960
+ )
1961
+ )
1962
+ );
1963
+ }
1964
+ function collectSuccessfulLog() {
1965
+ ui().logger.success("Collecting report successful!");
1966
+ }
1967
+ function renderIntegratePortalHint() {
1968
+ ui().sticker().add(chalk6.bold(chalk6.gray("\u{1F4A1} Integrate the portal"))).add("").add(
1969
+ `${chalk6.gray("\u276F")} Upload a report to the server - ${chalk6.gray(
1970
+ "npx code-pushup upload"
1971
+ )}`
1972
+ ).add(
1973
+ ` ${link2(
1974
+ "https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command"
1975
+ )}`
1976
+ ).add(
1977
+ `${chalk6.gray("\u276F")} ${chalk6.gray("Portal Integration")} - ${link2(
1978
+ "https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
1979
+ )}`
1980
+ ).add(
1981
+ `${chalk6.gray("\u276F")} ${chalk6.gray("Upload Command")} - ${link2(
1982
+ "https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
1983
+ )}`
1984
+ ).render();
1985
+ }
1986
+
1912
1987
  // packages/cli/src/lib/implementation/global.utils.ts
1913
1988
  function filterKebabCaseKeys(obj) {
1914
1989
  return Object.entries(obj).filter(([key]) => !key.includes("-")).reduce(
@@ -1957,8 +2032,8 @@ function yargsAutorunCommandObject() {
1957
2032
  describe: "Shortcut for running collect followed by upload",
1958
2033
  builder: yargsOnlyPluginsOptionsDefinition(),
1959
2034
  handler: async (args) => {
1960
- console.info(chalk5.bold(CLI_NAME));
1961
- console.info(chalk5.gray(`Run ${command}...`));
2035
+ ui().logger.log(chalk7.bold(CLI_NAME));
2036
+ ui().logger.info(chalk7.gray(`Run ${command}...`));
1962
2037
  const options2 = args;
1963
2038
  const optionsWithFormat = {
1964
2039
  ...options2,
@@ -1970,33 +2045,26 @@ function yargsAutorunCommandObject() {
1970
2045
  }
1971
2046
  };
1972
2047
  await collectAndPersistReports(optionsWithFormat);
2048
+ collectSuccessfulLog();
1973
2049
  if (options2.categories.length === 0) {
1974
- console.info(
1975
- chalk5.gray(
1976
- "\u{1F4A1} Configure categories to see the scores in an overview table. See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md"
1977
- )
1978
- );
2050
+ renderConfigureCategoriesHint();
1979
2051
  }
1980
2052
  if (options2.upload) {
1981
2053
  await upload(options2);
2054
+ const commitData = await getLatestCommit();
2055
+ if (validateCommitData(commitData, { throwError: true })) {
2056
+ uploadSuccessfulLog(options2.upload, commitData.hash);
2057
+ }
1982
2058
  } else {
1983
- console.warn("Upload skipped because configuration is not set.");
1984
- console.info(
1985
- [
1986
- "\u{1F4A1} Integrate the portal:",
1987
- "- npx code-pushup upload - Run upload to upload the created report to the server",
1988
- " https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command",
1989
- "- Portal Integration - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration",
1990
- "- Upload Command - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
1991
- ].join("\n")
1992
- );
2059
+ ui().logger.warning("Upload skipped because configuration is not set.");
2060
+ renderIntegratePortalHint();
1993
2061
  }
1994
2062
  }
1995
2063
  };
1996
2064
  }
1997
2065
 
1998
2066
  // packages/cli/src/lib/collect/collect-command.ts
1999
- import chalk6 from "chalk";
2067
+ import chalk8 from "chalk";
2000
2068
  function yargsCollectCommandObject() {
2001
2069
  const command = "collect";
2002
2070
  return {
@@ -2005,31 +2073,39 @@ function yargsCollectCommandObject() {
2005
2073
  builder: yargsOnlyPluginsOptionsDefinition(),
2006
2074
  handler: async (args) => {
2007
2075
  const options2 = args;
2008
- console.info(chalk6.bold(CLI_NAME));
2009
- console.info(chalk6.gray(`Run ${command}...`));
2076
+ ui().logger.log(chalk8.bold(CLI_NAME));
2077
+ ui().logger.info(chalk8.gray(`Run ${command}...`));
2010
2078
  await collectAndPersistReports(options2);
2079
+ collectSuccessfulLog();
2011
2080
  if (options2.categories.length === 0) {
2012
- console.info(
2013
- chalk6.gray(
2014
- "\u{1F4A1} Configure categories to see the scores in an overview table. See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md"
2015
- )
2016
- );
2081
+ renderConfigureCategoriesHint();
2017
2082
  }
2018
2083
  const { upload: upload2 = {} } = args;
2019
2084
  if (Object.keys(upload2).length === 0) {
2020
- console.info(
2021
- [
2022
- "\u{1F4A1} Visualize your reports:",
2023
- "- npx code-pushup upload - Run upload to upload the created report to the server",
2024
- " https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command",
2025
- "- npx code-pushup autorun - Run collect & upload",
2026
- " https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command"
2027
- ].join("\n")
2028
- );
2085
+ renderUploadAutorunHint();
2029
2086
  }
2030
2087
  }
2031
2088
  };
2032
2089
  }
2090
+ function renderUploadAutorunHint() {
2091
+ ui().sticker().add(chalk8.bold(chalk8.gray("\u{1F4A1} Visualize your reports"))).add("").add(
2092
+ `${chalk8.gray("\u276F")} npx code-pushup upload - ${chalk8.gray(
2093
+ "Run upload to upload the created report to the server"
2094
+ )}`
2095
+ ).add(
2096
+ ` ${link2(
2097
+ "https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command"
2098
+ )}`
2099
+ ).add(
2100
+ `${chalk8.gray("\u276F")} npx code-pushup autorun - ${chalk8.gray(
2101
+ "Run collect & upload"
2102
+ )}`
2103
+ ).add(
2104
+ ` ${link2(
2105
+ "https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command"
2106
+ )}`
2107
+ ).render();
2108
+ }
2033
2109
 
2034
2110
  // packages/cli/src/lib/print-config/print-config-command.ts
2035
2111
  function yargsConfigCommandObject() {
@@ -2043,35 +2119,31 @@ function yargsConfigCommandObject() {
2043
2119
  handler: (yargsArgs) => {
2044
2120
  const { _, $0, ...args } = yargsArgs;
2045
2121
  const cleanArgs = filterKebabCaseKeys(args);
2046
- console.info(JSON.stringify(cleanArgs, null, 2));
2122
+ ui().logger.log(JSON.stringify(cleanArgs, null, 2));
2047
2123
  }
2048
2124
  };
2049
2125
  }
2050
2126
 
2051
2127
  // packages/cli/src/lib/upload/upload-command.ts
2052
- import chalk7 from "chalk";
2128
+ import chalk9 from "chalk";
2053
2129
  function yargsUploadCommandObject() {
2054
2130
  const command = "upload";
2055
2131
  return {
2056
2132
  command,
2057
2133
  describe: "Upload report results to the portal",
2058
2134
  handler: async (args) => {
2059
- console.info(chalk7.bold(CLI_NAME));
2060
- console.info(chalk7.gray(`Run ${command}...`));
2135
+ ui().logger.log(chalk9.bold(CLI_NAME));
2136
+ ui().logger.info(chalk9.gray(`Run ${command}...`));
2061
2137
  const options2 = args;
2062
2138
  if (!options2.upload) {
2063
- console.info(
2064
- [
2065
- "\u{1F4A1} Integrate the portal:",
2066
- "- npx code-pushup upload - Run upload to upload the created report to the server",
2067
- " https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command",
2068
- "- Portal Integration - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration",
2069
- "- Upload Command - https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
2070
- ].join("\n")
2071
- );
2139
+ renderIntegratePortalHint();
2072
2140
  throw new Error("Upload configuration not set");
2073
2141
  }
2074
2142
  await upload(options2);
2143
+ const commitData = await getLatestCommit();
2144
+ if (validateCommitData(commitData, { throwError: true })) {
2145
+ uploadSuccessfulLog(options2.upload, commitData.hash);
2146
+ }
2075
2147
  }
2076
2148
  };
2077
2149
  }
@@ -2123,7 +2195,7 @@ async function coreConfigMiddleware(processArgs) {
2123
2195
  }
2124
2196
 
2125
2197
  // packages/cli/src/lib/implementation/only-plugins.utils.ts
2126
- import chalk8 from "chalk";
2198
+ import chalk10 from "chalk";
2127
2199
  function filterPluginsBySlug(plugins, { onlyPlugins }) {
2128
2200
  if (!onlyPlugins?.length) {
2129
2201
  return plugins;
@@ -2145,7 +2217,7 @@ function filterCategoryByPluginSlug(categories, {
2145
2217
  const isNotSkipped = onlyPlugins.includes(ref.slug);
2146
2218
  if (!isNotSkipped && verbose) {
2147
2219
  console.info(
2148
- `${chalk8.yellow("\u26A0")} Category "${category.title}" is ignored because it references audits from skipped plugin "${ref.slug}"`
2220
+ `${chalk10.yellow("\u26A0")} Category "${category.title}" is ignored because it references audits from skipped plugin "${ref.slug}"`
2149
2221
  );
2150
2222
  }
2151
2223
  return isNotSkipped;
@@ -2159,7 +2231,7 @@ function validateOnlyPluginsOption(plugins, {
2159
2231
  const missingPlugins = onlyPlugins?.length ? onlyPlugins.filter((plugin) => !plugins.some(({ slug }) => slug === plugin)) : [];
2160
2232
  if (missingPlugins.length > 0 && verbose) {
2161
2233
  console.warn(
2162
- `${chalk8.yellow(
2234
+ `${chalk10.yellow(
2163
2235
  "\u26A0"
2164
2236
  )} The --onlyPlugin argument references plugins with "${missingPlugins.join(
2165
2237
  '", "'
@@ -2264,7 +2336,7 @@ var options = {
2264
2336
  };
2265
2337
 
2266
2338
  // packages/cli/src/lib/yargs-cli.ts
2267
- import chalk9 from "chalk";
2339
+ import chalk11 from "chalk";
2268
2340
  import yargs from "yargs";
2269
2341
  function yargsCli(argv, cfg) {
2270
2342
  const { usageMessage, scriptName, noExitProcess } = cfg;
@@ -2282,7 +2354,7 @@ function yargsCli(argv, cfg) {
2282
2354
  (config) => Array.isArray(config) ? config.at(-1) : config
2283
2355
  ).options(options2).wrap(TERMINAL_WIDTH);
2284
2356
  if (usageMessage) {
2285
- cli2.usage(chalk9.bold(usageMessage));
2357
+ cli2.usage(chalk11.bold(usageMessage));
2286
2358
  }
2287
2359
  if (scriptName) {
2288
2360
  cli2.scriptName(scriptName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/cli",
3
- "version": "0.14.4",
3
+ "version": "0.16.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "code-pushup": "index.js"
@@ -10,7 +10,8 @@
10
10
  "@code-pushup/core": "*",
11
11
  "yargs": "^17.7.2",
12
12
  "chalk": "^5.3.0",
13
- "@code-pushup/utils": "*"
13
+ "@code-pushup/utils": "*",
14
+ "@poppinss/cliui": "^6.3.0"
14
15
  },
15
16
  "homepage": "https://github.com/code-pushup/cli#readme",
16
17
  "bugs": {
@@ -1,2 +1,3 @@
1
1
  import { CommandModule } from 'yargs';
2
2
  export declare function yargsCollectCommandObject(): CommandModule;
3
+ export declare function renderUploadAutorunHint(): void;
@@ -0,0 +1,9 @@
1
+ import { cliui } from '@poppinss/cliui';
2
+ import { UploadConfig } from '@code-pushup/models';
3
+ export type CliUi = ReturnType<typeof cliui>;
4
+ export declare let singletonUiInstance: CliUi | undefined;
5
+ export declare function ui(): CliUi;
6
+ export declare function renderConfigureCategoriesHint(): void;
7
+ export declare function uploadSuccessfulLog(options: UploadConfig, commit: string): void;
8
+ export declare function collectSuccessfulLog(): void;
9
+ export declare function renderIntegratePortalHint(): void;