From e794cb76db36e13958be894e7a8796e4ba5f10b7 Mon Sep 17 00:00:00 2001 From: Leo Goetz Date: Tue, 19 May 2026 04:50:03 +0200 Subject: refactor: show warnings in the output instead of using ora --- src/actions/checkDependencies.ts | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/actions/checkDependencies.ts') 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[]; let projects: Promise[] = []; - 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 { 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(cmd: string, callback: any): Promise { return new Promise((resolve, _) => { - exec(cmd, (_, stdout, __) => { - resolve(callback(_, stdout, __)); + exec(cmd, (err, stdout, stderr) => { + resolve(callback(err, stdout, stderr)); }); }); } -- cgit v1.3.1