summaryrefslogtreecommitdiff
path: root/src/actions/output.ts
blob: 348cb8ed328274c71b3b5744a20c0085545544e8 (plain) (blame)
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
import chalk from "chalk";
import type { ProjectAudit, ProjectFix } from "../types.js";

export function outputSummary(projects: PromiseSettledResult<ProjectAudit>[]) {
  const text = `
    This is what i found:
    ${projects.map((project: any) => {
      if (project.status === "fulfilled") {
        let projectVulnerabilities =
          project.value.metadata.vulnerabilities.total;
        return `
    ${project.value.projectName} has ${projectVulnerabilities > 0 ? chalk.bold.red(projectVulnerabilities) : chalk.bold.green(projectVulnerabilities)} Security Issues`;
      }
      return `
    ${chalk.bold.yellow("WARN:")} ${project.reason}`;
    })}
  `;

  console.log(text);
}

export function outputFixes(fixes: PromiseSettledResult<ProjectFix>[]) {
  const text = `
    This is what i found:
    ${fixes.map((project) => {
      if (project.status === "fulfilled") {
        return `
    ${project.value.projectName} got fixed, added ${chalk.green(project.value.added)}, removed ${chalk.green(project.value.removed)} and changed ${chalk.green(project.value.changed)}`;
      }
      return `
    ${chalk.red(project.reason)}`;
    })}
  `;

  console.log(text);
}