Skip to content

Commit

Permalink
Merge pull request #189 from SocketDev/cg/improveDiffScan
Browse files Browse the repository at this point in the history
Improve diff scan command
  • Loading branch information
charliegerard authored Aug 30, 2024
2 parents 8c3db7e + 22ce697 commit ae714e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .dep-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -129,14 +131,16 @@
"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",
"rc": "1.2.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"
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
21 changes: 16 additions & 5 deletions src/commands/diff-scan/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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`)
}

0 comments on commit ae714e9

Please sign in to comment.