From 22ce697b30efd55db62e7f1757898f9ecf677a98 Mon Sep 17 00:00:00 2001 From: Charlie Gerard Date: Fri, 30 Aug 2024 11:19:16 -0700 Subject: [PATCH] refactor output and add json flag for detailed scan --- .dep-stats.json | 8 ++++++-- package.json | 2 ++ src/commands/diff-scan/get.ts | 21 ++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.dep-stats.json b/.dep-stats.json index efd373a1..19638164 100644 --- a/.dep-stats.json +++ b/.dep-stats.json @@ -102,6 +102,7 @@ "emoji-regex": "^10.3.0", "fast-glob": "^3.3.2", "graceful-fs": "^4.2.6", + "has-flag": "^4.0.0", "hpagent": "^1.2.0", "ignore": "^5.3.1", "ini": "4.1.3", @@ -113,7 +114,8 @@ "registry-auth-token": "^5.0.2", "semver": "^7.6.2", "signal-exit": "^4.1.0", - "supports-hyperlinks": "^2.2.0", + "supports-color": "^7.0.0", + "supports-hyperlinks": "^3.1.0", "synp": "^1.9.13", "which": "^4.0.0", "write-file-atomic": "^5.0.1", @@ -129,6 +131,7 @@ "emoji-regex": "^10.3.0", "fast-glob": "^3.3.2", "graceful-fs": "^4.2.6", + "has-flag": "^4.0.0", "ini": "4.1.3", "node-domexception": "^1.0.0", "onetime": "^5.1.0", @@ -136,7 +139,8 @@ "registry-auth-token": "^5.0.2", "semver": "^7.6.2", "signal-exit": "^4.1.0", - "supports-hyperlinks": "^2.2.0", + "supports-color": "^7.0.0", + "supports-hyperlinks": "^3.1.0", "write-file-atomic": "^5.0.1" } } diff --git a/package.json b/package.json index 5d7658b2..344a8712 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "emoji-regex": "^10.3.0", "fast-glob": "^3.3.2", "graceful-fs": "^4.2.6", + "has-flag": "^4.0.0", "hpagent": "^1.2.0", "ignore": "^5.3.1", "ini": "4.1.3", @@ -53,6 +54,7 @@ "registry-auth-token": "^5.0.2", "semver": "^7.6.2", "signal-exit": "^4.1.0", + "supports-color": "^7.0.0", "supports-hyperlinks": "^3.1.0", "synp": "^1.9.13", "which": "^4.0.0", diff --git a/src/commands/diff-scan/get.ts b/src/commands/diff-scan/get.ts index c02ce0a7..a673dc23 100644 --- a/src/commands/diff-scan/get.ts +++ b/src/commands/diff-scan/get.ts @@ -138,7 +138,7 @@ function setupCommand( } async function getDiffScan( - { before, after, orgSlug, file }: CommandContext, + { before, after, orgSlug, file, outputJson }: CommandContext, spinner: Ora, apiKey: string, ): Promise { @@ -156,13 +156,24 @@ async function getDiffScan( spinner.stop() - if(file){ + if(file && !outputJson){ fs.writeFile(file, JSON.stringify(data), err => { err ? console.error(err) : console.log(`Data successfully written to ${file}`) }) return } - console.log(`\n Diff scan result: \n`) - console.log(util.inspect(data, {showHidden: false, depth: null, colors: true})) -} + if(outputJson){ + console.log(`\n Diff scan result: \n`) + console.log(util.inspect(data, {showHidden: false, depth: null, colors: true})) + // @ts-ignore + console.log(`\n View this diff scan in the Socket dashboard: ${chalk.cyan(data.diff_report_url)} \n`) + return + } + + console.log("Diff scan result: ") + console.log(data) + console.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`) + // @ts-ignore + console.log(`\n View this diff scan in the Socket dashboard: ${chalk.cyan(data.diff_report_url)} \n`) +} \ No newline at end of file