summaryrefslogtreecommitdiff
path: root/src/actions/checkDependencies.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/checkDependencies.ts')
-rw-r--r--src/actions/checkDependencies.ts44
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));
});
});
}