diff options
| author | Leo Goetz <dev@leogtz.de> | 2026-05-19 04:50:03 +0200 |
|---|---|---|
| committer | Leo Goetz <dev@leogtz.de> | 2026-05-19 04:50:03 +0200 |
| commit | e794cb76db36e13958be894e7a8796e4ba5f10b7 (patch) | |
| tree | 17ef7905832819ee4158d8c7b9ecd4c398c75062 /src/actions/checkDependencies.ts | |
| parent | 69456d49bf45e222dd0474fa9cfb420f3bdb0830 (diff) | |
refactor: show warnings in the output instead of using ora
Diffstat (limited to 'src/actions/checkDependencies.ts')
| -rw-r--r-- | src/actions/checkDependencies.ts | 44 |
1 files changed, 22 insertions, 22 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)); }); }); } |
