UNPKG

debt-collector

Version:

a nodejs tool to identify, track and mesure technical debt

41 lines (40 loc) 2.27 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from 'react'; import { Text } from 'ink'; import { useValidatedConfig } from '../lib/config/index.js'; import useGitUtils from '../lib/git/useGitUtils.js'; import zod from 'zod'; import { option } from 'pastel'; export const options = zod.object({ 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' })), openReport: zod.boolean().optional().describe(option({ description: 'open the report in the browser', alias: 'o' })), }); export const alias = 'wdr'; const WalkDryRun = ({ options }) => { const { config } = options; const [results, setResults] = useState(null); const [parsedResult, setParsedResult] = useState(null); const { isConfigValid, sanitizedConfig } = useValidatedConfig(config); const { execWalkCommand } = useGitUtils(sanitizedConfig); useEffect(() => { if (isConfigValid && !!sanitizedConfig?.walkConfig) { ; (async () => { const { gitCommand, parser, limit } = sanitizedConfig.walkConfig; const result = await execWalkCommand(gitCommand); if (!result) { setResults('Error while executing the command'); return; } const parsedResults = parser(result); const limitedParsedResults = parsedResults.slice(0, limit || 10); setResults(`${result.substring(0, 2000)}...`); setParsedResult(limitedParsedResults); })(); } }, [isConfigValid]); return (_jsxs(_Fragment, { children: [_jsx(Text, {}), _jsxs(Text, { bold: true, backgroundColor: "red", children: ["Truncated result of the command :", ' '] }), _jsx(Text, { children: results }), _jsx(Text, {}), _jsxs(Text, { bold: true, backgroundColor: "red", children: ["Result of the parser with limit :", ' '] }), _jsx(Text, { children: JSON.stringify(parsedResult, null, 2) })] })); }; export default WalkDryRun;