/* eslint-disable no-console */ import { type ApiScanResultItem, type PluginConfigScanResultItem, type ScanConfigSchema, createTerminalTable, } from '@ones-open/cli-utils' import chalk from 'chalk' export const printResults = ( apiScanResults: ApiScanResultItem[], pluginConfigScanResults: PluginConfigScanResultItem[], scanConfig: ScanConfigSchema, ) => { const { output: { level }, } = scanConfig if (apiScanResults.length > 0) { const apiResultTable = createTerminalTable({ 'Code': 1, 'Matched APIs': 1, }) let count = 0 apiScanResults.forEach(({ value, location, matched = [] }) => { const shouldSkip = level === 'matched' && matched.length === 0 if (!shouldSkip) { const { file, line, column } = location const relativePath = file.replace(process.cwd(), '.') apiResultTable.push([ `${chalk.green(value)}\nat ${relativePath}:${line}:${column}`, matched.join('\n'), ]) count++ } }) console.log(chalk.bold(`APIs(${count} in total):`)) console.log(apiResultTable.toString()) } if (pluginConfigScanResults.length > 0) { const pluginConfigResultTable = createTerminalTable({ 'Plugin Config Item': 1, 'Matched APIs': 1, }) let count = 0 pluginConfigScanResults.forEach(({ value, correspondingApis = [], matched = [] }) => { const shouldSkip = level === 'matched' && matched.length === 0 if (!shouldSkip) { pluginConfigResultTable.push([ `${chalk.green(value)}\ncorresponding to\n${chalk.green(correspondingApis.join('\n'))}`, matched.join('\n'), ]) } }) count++ console.log(chalk.bold(`Plugin config items(${count} in total):`)) console.log(pluginConfigResultTable.toString()) } if (apiScanResults.length + pluginConfigScanResults.length === 0) { console.log(chalk.green('[Scan Completed]: No Results Found')) } }