Skip to content

Commit ae714e9

Browse files
Merge pull request #189 from SocketDev/cg/improveDiffScan
Improve diff scan command
2 parents 8c3db7e + 22ce697 commit ae714e9

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.dep-stats.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"emoji-regex": "^10.3.0",
103103
"fast-glob": "^3.3.2",
104104
"graceful-fs": "^4.2.6",
105+
"has-flag": "^4.0.0",
105106
"hpagent": "^1.2.0",
106107
"ignore": "^5.3.1",
107108
"ini": "4.1.3",
@@ -113,7 +114,8 @@
113114
"registry-auth-token": "^5.0.2",
114115
"semver": "^7.6.2",
115116
"signal-exit": "^4.1.0",
116-
"supports-hyperlinks": "^2.2.0",
117+
"supports-color": "^7.0.0",
118+
"supports-hyperlinks": "^3.1.0",
117119
"synp": "^1.9.13",
118120
"which": "^4.0.0",
119121
"write-file-atomic": "^5.0.1",
@@ -129,14 +131,16 @@
129131
"emoji-regex": "^10.3.0",
130132
"fast-glob": "^3.3.2",
131133
"graceful-fs": "^4.2.6",
134+
"has-flag": "^4.0.0",
132135
"ini": "4.1.3",
133136
"node-domexception": "^1.0.0",
134137
"onetime": "^5.1.0",
135138
"rc": "1.2.8",
136139
"registry-auth-token": "^5.0.2",
137140
"semver": "^7.6.2",
138141
"signal-exit": "^4.1.0",
139-
"supports-hyperlinks": "^2.2.0",
142+
"supports-color": "^7.0.0",
143+
"supports-hyperlinks": "^3.1.0",
140144
"write-file-atomic": "^5.0.1"
141145
}
142146
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"emoji-regex": "^10.3.0",
4343
"fast-glob": "^3.3.2",
4444
"graceful-fs": "^4.2.6",
45+
"has-flag": "^4.0.0",
4546
"hpagent": "^1.2.0",
4647
"ignore": "^5.3.1",
4748
"ini": "4.1.3",
@@ -53,6 +54,7 @@
5354
"registry-auth-token": "^5.0.2",
5455
"semver": "^7.6.2",
5556
"signal-exit": "^4.1.0",
57+
"supports-color": "^7.0.0",
5658
"supports-hyperlinks": "^3.1.0",
5759
"synp": "^1.9.13",
5860
"which": "^4.0.0",

src/commands/diff-scan/get.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function setupCommand(
138138
}
139139

140140
async function getDiffScan(
141-
{ before, after, orgSlug, file }: CommandContext,
141+
{ before, after, orgSlug, file, outputJson }: CommandContext,
142142
spinner: Ora,
143143
apiKey: string,
144144
): Promise<void> {
@@ -156,13 +156,24 @@ async function getDiffScan(
156156

157157
spinner.stop()
158158

159-
if(file){
159+
if(file && !outputJson){
160160
fs.writeFile(file, JSON.stringify(data), err => {
161161
err ? console.error(err) : console.log(`Data successfully written to ${file}`)
162162
})
163163
return
164164
}
165165

166-
console.log(`\n Diff scan result: \n`)
167-
console.log(util.inspect(data, {showHidden: false, depth: null, colors: true}))
168-
}
166+
if(outputJson){
167+
console.log(`\n Diff scan result: \n`)
168+
console.log(util.inspect(data, {showHidden: false, depth: null, colors: true}))
169+
// @ts-ignore
170+
console.log(`\n View this diff scan in the Socket dashboard: ${chalk.cyan(data.diff_report_url)} \n`)
171+
return
172+
}
173+
174+
console.log("Diff scan result: ")
175+
console.log(data)
176+
console.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`)
177+
// @ts-ignore
178+
console.log(`\n View this diff scan in the Socket dashboard: ${chalk.cyan(data.diff_report_url)} \n`)
179+
}

0 commit comments

Comments
 (0)