-
Notifications
You must be signed in to change notification settings - Fork 0
/
doExport.ts
46 lines (40 loc) · 1.26 KB
/
doExport.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import chalk from 'chalk';
import { StrategyResult, StrategyRunnerOutputStatusEnum } from './src';
interface IExportEntry {
isTable?: boolean;
result: StrategyResult,
}
interface IExportStrategy {
(result: StrategyResult): void;
}
const statusColorMap = {
[StrategyRunnerOutputStatusEnum.Critical]: 'red.bold',
[StrategyRunnerOutputStatusEnum.Medium]: 'yellow.bold',
[StrategyRunnerOutputStatusEnum.Low]: 'green.bold',
};
const exportToConsoleAsTable: IExportStrategy = (result) => {
Object.entries(result).forEach(
([strategyName, strategyResults]) => {
console.log(`{blue.bold ${strategyName}:`);
console.table(strategyResults);
},
);
};
const exportToConsoleAsRows: IExportStrategy = (result) => {
Object.entries(result).forEach(([strategyName, strategyResults]) => {
console.log('\n', chalk.blue.bold(`${strategyName}:`));
strategyResults.forEach((strategyResult) => {
console.log(chalk`{magenta.bold ${strategyResult.name}} ({${statusColorMap[strategyResult.status]} ${strategyResult.status}}): ${strategyResult.description}`);
});
});
};
export default function doExport({
isTable,
result,
}: IExportEntry): void {
if (isTable) {
exportToConsoleAsTable(result);
} else {
exportToConsoleAsRows(result);
}
}