@code-pushup/cli
Version:
A CLI to run all kinds of code quality measurements to align your team with company goals
45 lines • 1.78 kB
JavaScript
import yargs from 'yargs';
import { toArray, ui } from '@code-pushup/utils';
import { OptionValidationError } from './validate-filter-options.utils.js';
export function filterKebabCaseKeys(obj) {
return Object.entries(obj)
.filter(([key]) => !key.includes('-'))
.reduce((acc, [key, value]) => typeof value === 'string' ||
(typeof value === 'object' && Array.isArray(obj[key]))
? { ...acc, [key]: value }
: typeof value === 'object' && !Array.isArray(value) && value != null
? {
...acc,
[key]: filterKebabCaseKeys(value),
}
: { ...acc, [key]: value }, {});
}
// Log error and flush stdout to ensure all logs are printed
// before Yargs exits or rethrows the error.
// This prevents log suppression, especially in async execution.
// Related issue: https://github.com/yargs/yargs/issues/2118
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function logErrorBeforeThrow(fn) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (async (...args) => {
try {
return await fn(...args);
}
catch (error) {
if (error instanceof OptionValidationError) {
ui().logger.error(error.message);
await new Promise(resolve => process.stdout.write('', resolve));
yargs().exit(1, error);
}
else {
console.error(error);
await new Promise(resolve => process.stdout.write('', resolve));
throw error;
}
}
});
}
export function coerceArray(param) {
return [...new Set(toArray(param).flatMap(f => f.split(',')))];
}
//# sourceMappingURL=global.utils.js.map