Skip to content

Commit fb015f6

Browse files
committed
refactor: add various logs WIP
1 parent 7ce5067 commit fb015f6

File tree

8 files changed

+37
-5
lines changed

8 files changed

+37
-5
lines changed

packages/cli/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#! /usr/bin/env node
22
import { hideBin } from 'yargs/helpers';
3+
import { ui } from '@code-pushup/utils';
34
import { cli } from './lib/cli.js';
45

6+
ui().logger.log(`~~ cli: ${hideBin(process.argv)}`);
7+
58
// bootstrap Yargs, parse arguments and execute command
69
await cli(hideBin(process.argv)).argv;

packages/cli/src/lib/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export const cli = (args: string[]) =>
1717
],
1818
[
1919
'code-pushup collect --tsconfig=tsconfig.base.json',
20-
'Run collect using custom tsconfig to parse code-pushup.config.ts file.',
20+
'Run collect using a custom tsconfig to parse code-pushup.config.ts file.',
2121
],
2222
[
2323
'code-pushup collect --onlyPlugins=coverage',
2424
'Run collect with only coverage plugin, other plugins from config file will be skipped.',
2525
],
2626
[
2727
'code-pushup collect --skipPlugins=coverage',
28-
'Run collect skiping the coverage plugin, other plugins from config file will be included.',
28+
'Run collect & skip running the coverage plugin, other plugins from config file will be executed.',
2929
],
3030
[
3131
'code-pushup upload --persist.outputDir=dist --upload.apiKey=$CP_API_KEY',

packages/core/src/lib/collect-and-persist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function collectAndPersistReports(
2828

2929
const report = await collect(options);
3030
const sortedScoredReport = sortReport(scoreReport(report));
31+
3132
const persistResults = await persistReport(
3233
report,
3334
sortedScoredReport,

packages/core/src/lib/implementation/collect.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRequire } from 'node:module';
22
import type { CoreConfig, Report } from '@code-pushup/models';
3-
import { calcDuration, getLatestCommit } from '@code-pushup/utils';
3+
import { calcDuration, getLatestCommit, ui } from '@code-pushup/utils';
44
import type { GlobalOptions } from '../types.js';
55
import { executePlugins } from './execute-plugin.js';
66

@@ -12,7 +12,12 @@ export type CollectOptions = Pick<CoreConfig, 'plugins' | 'categories'> &
1212
* @param options
1313
*/
1414
export async function collect(options: CollectOptions): Promise<Report> {
15+
ui().logger.log('Running collect');
1516
const { plugins, categories } = options;
17+
console.log(
18+
'~~ plugin runners',
19+
plugins.map(({ runner }) => runner),
20+
);
1621
const date = new Date().toISOString();
1722
const start = performance.now();
1823
const commit = await getLatestCommit();

packages/core/src/lib/implementation/runner.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import { gray } from 'ansis';
12
import path from 'node:path';
23
import type {
34
OnProgress,
45
RunnerConfig,
56
RunnerFunction,
67
} from '@code-pushup/models';
7-
import { calcDuration, executeProcess, readJsonFile } from '@code-pushup/utils';
8+
import {
9+
calcDuration,
10+
executeProcess,
11+
readJsonFile,
12+
removeDirectoryIfExists,
13+
ui,
14+
} from '@code-pushup/utils';
815

916
export type RunnerResult = {
1017
date: string;
@@ -26,7 +33,8 @@ export async function executeRunnerConfig(
2633
});
2734

2835
// read process output from file system and parse it
29-
const outputs = await readJsonFile(path.join(process.cwd(), outputFile));
36+
const outputs = await readJsonFile(outputFile);
37+
await removeDirectoryIfExists(path.dirname(outputFile));
3038

3139
// transform unknownAuditOutputs to auditOutputs
3240
const audits = outputTransform ? await outputTransform(outputs) : outputs;

packages/plugin-eslint/src/bin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import process from 'node:process';
22
import { Parser } from 'yargs/helpers';
3+
import { ui } from '@code-pushup/utils';
34
import { executeRunner } from './lib/runner/index.js';
45

56
const { runnerConfigPath, runnerOutputPath } = Parser(process.argv);
67

8+
ui().logger.log(
9+
`~~ Runner files: ${JSON.stringify({ runnerConfigPath, runnerOutputPath }, null, 2)}`,
10+
);
11+
712
await executeRunner({ runnerConfigPath, runnerOutputPath });

packages/plugin-eslint/src/lib/runner/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
filePathToCliArg,
1313
objectToCliArgs,
1414
readJsonFile,
15+
ui,
1516
} from '@code-pushup/utils';
1617
import type { ESLintPluginRunnerConfig, ESLintTarget } from '../config.js';
1718
import { lint } from './lint.js';
@@ -25,6 +26,8 @@ export async function executeRunner({
2526
const { slugs, targets } =
2627
await readJsonFile<ESLintPluginRunnerConfig>(runnerConfigPath);
2728

29+
ui().logger.log(`ESLint plugin executing ${targets.length} lint targets`);
30+
2831
const linterOutputs = await targets.reduce(
2932
async (acc, target) => [...(await acc), await lint(target)],
3033
Promise.resolve<LinterOutput[]>([]),

packages/utils/src/lib/execute-process.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
spawn,
77
} from 'node:child_process';
88
import type { Readable, Writable } from 'node:stream';
9+
import { ui } from './logging.js';
910
import { calcDuration } from './reports/utils.js';
1011

1112
/**
@@ -148,6 +149,10 @@ export function executeProcess(cfg: ProcessConfig): Promise<ProcessResult> {
148149
const date = new Date().toISOString();
149150
const start = performance.now();
150151

152+
ui().logger.log(
153+
`Executing command:\n${[command, ...(args || [])].join(' ')}`,
154+
);
155+
151156
return new Promise((resolve, reject) => {
152157
// shell:true tells Windows to use shell command for spawning a child process
153158
const spawnedProcess = spawn(command, args ?? [], {
@@ -179,6 +184,8 @@ export function executeProcess(cfg: ProcessConfig): Promise<ProcessResult> {
179184
const timings = { date, duration: calcDuration(start) };
180185
if (code === 0 || ignoreExitCode) {
181186
onComplete?.();
187+
// todo: maybe if I update spinner instead of logging it will appear with a command it was supposed to be grouped with
188+
ui().logger.log(`Command execution took ${calcDuration(start)}ms`);
182189
resolve({ code, stdout, stderr, ...timings });
183190
} else {
184191
const errorMsg = new ProcessError({ code, stdout, stderr, ...timings });

0 commit comments

Comments
 (0)