Skip to content

Commit

Permalink
refactor: add various logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vmasek committed Feb 4, 2025
1 parent f40292b commit 5e38156
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/lib/collect-and-persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function collectAndPersistReports(

const report = await collect(options);
const sortedScoredReport = sortReport(scoreReport(report));

const persistResults = await persistReport(
report,
sortedScoredReport,
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/lib/implementation/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type {
RunnerConfig,
RunnerFunction,
} from '@code-pushup/models';
import { calcDuration, executeProcess, readJsonFile } from '@code-pushup/utils';
import {
calcDuration,
executeProcess,
readJsonFile,
removeDirectoryIfExists,
} from '@code-pushup/utils';

export type RunnerResult = {
date: string;
Expand All @@ -26,7 +31,8 @@ export async function executeRunnerConfig(
});

// read process output from file system and parse it
const outputs = await readJsonFile(path.join(process.cwd(), outputFile));
const outputs = await readJsonFile(outputFile);
await removeDirectoryIfExists(path.dirname(outputFile));

// transform unknownAuditOutputs to auditOutputs
const audits = outputTransform ? await outputTransform(outputs) : outputs;
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-eslint/src/lib/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
filePathToCliArg,
objectToCliArgs,
readJsonFile,
ui,
} from '@code-pushup/utils';
import type { ESLintPluginRunnerConfig, ESLintTarget } from '../config.js';
import { lint } from './lint.js';
Expand All @@ -25,6 +26,8 @@ export async function executeRunner({
const { slugs, targets } =
await readJsonFile<ESLintPluginRunnerConfig>(runnerConfigPath);

ui().logger.log(`ESLint plugin executing ${targets.length} lint targets`);

const linterOutputs = await targets.reduce(
async (acc, target) => [...(await acc), await lint(target)],
Promise.resolve<LinterOutput[]>([]),
Expand Down
5 changes: 5 additions & 0 deletions packages/utils/src/lib/execute-process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gray } from 'ansis';
import {
type ChildProcess,
type ChildProcessByStdio,
Expand All @@ -6,6 +7,7 @@ import {
spawn,
} from 'node:child_process';
import type { Readable, Writable } from 'node:stream';
import { ui } from './logging.js';
import { calcDuration } from './reports/utils.js';

/**
Expand Down Expand Up @@ -148,6 +150,9 @@ export function executeProcess(cfg: ProcessConfig): Promise<ProcessResult> {
const date = new Date().toISOString();
const start = performance.now();

const logCommand = [command, ...(args || [])].join(' ');
ui().logger.log(gray(`Executing command:\n${logCommand}`));

return new Promise((resolve, reject) => {
// shell:true tells Windows to use shell command for spawning a child process
const spawnedProcess = spawn(command, args ?? [], {
Expand Down

0 comments on commit 5e38156

Please sign in to comment.