debt-collector
Version:
a nodejs tool to identify, track and mesure technical debt
44 lines (43 loc) • 3.8 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Text, Box } from 'ink';
import { TaskList, Task } from 'ink-task-list';
import spinners from 'cli-spinners';
import zod from 'zod';
import { option } from 'pastel';
import { Results, ResultsFileOnly, ResultsNoMatchRule, useCheckState, } from '../components/check/index.js';
import { useDevLogger } from '../components/hooks/useDevLogger.js';
import { LogViewer } from '../components/DevLogger/LogViewer.js';
export const options = zod.object({
rule: zod.string().optional().describe(option({ description: 'rule id', alias: 'r' })),
tags: zod.string().array().optional().describe(option({ description: 'a list of tags', alias: 't' })),
config: zod.string().optional().describe(option({ description: 'an alternative path to the configuration file', alias: 'c' })),
include: zod.string().optional().describe(option({ description: 'a glob pattern to override the include configuration', alias: 'g' })),
reportFormat: zod.enum(['filesOnly', 'noMatchRules', 'standard']).default('standard').optional().describe(option({ description: 'report format', alias: 'f' })),
changedSince: zod.string().optional().describe(option({ description: 'a revision to filter files changed since (commit hash or branch name)', alias: 's' })),
limitTop: zod.number().optional().describe(option({ description: 'limit the number of results ordered by score', alias: 'l' })),
});
export const alias = 'c';
function Check({ options }) {
const { rule, tags, config, include, reportFormat, changedSince, limitTop, } = options;
const logger = useDevLogger();
const { results, fileList, checkedFileCount, isConfigValid, configErrors, collectingFrom, hasFilters, withFilters, } = useCheckState({
rule,
tags,
config,
include,
changedSince,
});
return (_jsxs(_Fragment, { children: [_jsx(LogViewer, { logs: logger.logs }), _jsxs(TaskList, { children: [_jsx(Task, { state: isConfigValid === null
? 'loading'
: isConfigValid
? 'success'
: 'error', spinner: spinners.dots, label: "validating configuration", status: isConfigValid === null
? 'checking configuration'
: isConfigValid
? 'success'
: 'error' }), _jsx(Task, { state: fileList === null ? 'loading' : 'success', spinner: spinners.dots, label: "defining files to check", status: fileList === null ? undefined : `${fileList.length} files` }), _jsx(Task, { state: results === null ? 'loading' : 'success', spinner: spinners.dots, label: "checking files", status: `${checkedFileCount}/${fileList === null ? '?' : fileList.length} files` })] }), isConfigValid === false &&
configErrors &&
configErrors.length > 0 &&
configErrors.map((error, i) => (_jsx(Text, { color: "red", children: error }, i))), results !== null && reportFormat === 'standard' && (_jsx(Results, { results: results, limitTop: limitTop })), results !== null && reportFormat === 'filesOnly' && (_jsx(ResultsFileOnly, { results: results, limitTop: limitTop })), results !== null && reportFormat === 'noMatchRules' && (_jsx(ResultsNoMatchRule, { results: results, initialConfig: results.config })), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: "grey", children: collectingFrom }), hasFilters && _jsx(Text, { color: "grey", children: withFilters }), _jsxs(Text, { color: "grey", children: ["Reporting :", reportFormat, ' ', limitTop && `• top ${limitTop} biggest score`] })] })] }));
}
export default Check;