summaryrefslogtreecommitdiff
path: root/src/actions
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2026-05-19 04:50:03 +0200
committerLeo Goetz <dev@leogtz.de>2026-05-19 04:50:03 +0200
commite794cb76db36e13958be894e7a8796e4ba5f10b7 (patch)
tree17ef7905832819ee4158d8c7b9ecd4c398c75062 /src/actions
parent69456d49bf45e222dd0474fa9cfb420f3bdb0830 (diff)
refactor: show warnings in the output instead of using ora
Diffstat (limited to 'src/actions')
-rw-r--r--src/actions/checkDependencies.ts44
-rw-r--r--src/actions/outputSummary.ts13
-rw-r--r--src/actions/sendEmail.ts14
3 files changed, 41 insertions, 30 deletions
diff --git a/src/actions/checkDependencies.ts b/src/actions/checkDependencies.ts
index 033a325..7357989 100644
--- a/src/actions/checkDependencies.ts
+++ b/src/actions/checkDependencies.ts
@@ -4,13 +4,13 @@ import type { Config, Project } from "../types.js";
import { getConfig } from "../utils/config.js";
import { exec } from "child_process";
+const spinner = ora("Getting all Project Data").start();
+
export async function checkDependencies() {
const config: Config = await getConfig();
- let projectAudits = [];
+ let projectAudits: PromiseSettledResult<Project>[];
let projects: Promise<Project>[] = [];
- const spinner = ora("Getting all Project Data").start();
-
try {
const entries = await fs.readdir(config.path, { withFileTypes: true });
@@ -18,40 +18,35 @@ export async function checkDependencies() {
if (!entry.isDirectory()) {
continue;
}
+
let dirFullPath = `${config.path}${entry.name}`;
const projectDir = await fs.readdir(dirFullPath);
+
if (projectDir.includes("package.json")) {
- projects.push(getAuditPromise(dirFullPath, entry.name, spinner));
+ let auditPromise = getAuditPromise(dirFullPath, entry.name);
+ projects.push(auditPromise);
}
}
- const results = await Promise.allSettled(projects);
-
- for (const result of results) {
- if (result.status === "fulfilled") {
- projectAudits.push(result.value);
- } else {
- spinner.warn(result.reason);
- }
- }
+ projectAudits = await Promise.allSettled(projects);
spinner.succeed("Got the Data successfully");
+
+ return projectAudits;
} catch (error) {
spinner.fail("Ups and Error :(");
console.log(error);
+ return;
}
-
- return projectAudits;
}
-function getAuditPromise(
+async function getAuditPromise(
path: string,
dirname: string,
- spinner: any,
): Promise<Project> {
return new Promise(async (resolve, reject) => {
- spinner.text = "pulling latest";
- await promiseExec(`cd "${path}" && git pull `, () => {});
+ await pullLatest(path);
+
spinner.text = "getting audit";
promiseExec(
`cd "${path}" && npm audit --json`,
@@ -69,10 +64,15 @@ function getAuditPromise(
});
}
-function promiseExec(cmd: string, callback: any) {
+async function pullLatest(path: string) {
+ spinner.text = "pulling latest";
+ await promiseExec(`cd "${path}" && git pull `, () => {});
+}
+
+function promiseExec<T>(cmd: string, callback: any): Promise<T> {
return new Promise((resolve, _) => {
- exec(cmd, (_, stdout, __) => {
- resolve(callback(_, stdout, __));
+ exec(cmd, (err, stdout, stderr) => {
+ resolve(callback(err, stdout, stderr));
});
});
}
diff --git a/src/actions/outputSummary.ts b/src/actions/outputSummary.ts
index 5a376cb..6f29a5c 100644
--- a/src/actions/outputSummary.ts
+++ b/src/actions/outputSummary.ts
@@ -1,13 +1,18 @@
import chalk from "chalk";
import type { Project } from "../types.js";
-export function outputSummary(projects: Project[]) {
+export function outputSummary(projects: PromiseSettledResult<Project>[]) {
const text = `
This is what i found:
- ${projects.map((project) => {
- let projectVulnerabilities = project.metadata.vulnerabilities.total;
+ ${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 `
- ${project.projectName} has ${projectVulnerabilities > 0 ? chalk.bold.red(projectVulnerabilities) : chalk.bold.green(projectVulnerabilities)} Security Issues`;
+ ${chalk.bold.yellow("WARN:")} ${project.reason}`;
})}
`;
diff --git a/src/actions/sendEmail.ts b/src/actions/sendEmail.ts
index 50394c5..4509a8e 100644
--- a/src/actions/sendEmail.ts
+++ b/src/actions/sendEmail.ts
@@ -4,7 +4,9 @@ import type { Project } from "../types.js";
const transporter = nodemailer.createTransport(emailConfig);
-export const sendAuditEmail = async (projects: Project[]) => {
+export const sendAuditEmail = async (
+ projects: PromiseSettledResult<Project>[],
+) => {
const text = emailContent(projects);
const email = await transporter.sendMail({
from: `"${emailConfig.senderName}" <${emailConfig.senderEmail}>`,
@@ -16,12 +18,16 @@ export const sendAuditEmail = async (projects: Project[]) => {
return email;
};
-const emailContent = (projects: Project[]): string => {
+const emailContent = (projects: PromiseSettledResult<Project>[]): string => {
return `Here is your Report:
${projects.map((project) => {
- let projectVulnerabilities = project.metadata.vulnerabilities.total;
+ if (project.status === "fulfilled") {
+ let projectVulnerabilities = project.value.metadata.vulnerabilities.total;
+ return `
+ ${project.value.projectName} has ${projectVulnerabilities} Security Issues`;
+ }
return `
-${project.projectName} has ${projectVulnerabilities} Security Issues`;
+ WARN: ${project.reason}`;
})}
`;
};