Skip to content

Commit 6bfe05f

Browse files
committed
Use more yactoSpinner ending calls
1 parent b58d502 commit 6bfe05f

20 files changed

+65
-107
lines changed

src/commands/analytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ async function fetchOrgAnalyticsData(
189189
if (result.success === false) {
190190
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner)
191191
}
192+
192193
spinner.stop()
193194

194195
if (!result.data.length) {
@@ -353,6 +354,7 @@ async function fetchRepoAnalyticsData(
353354
if (result.success === false) {
354355
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner)
355356
}
357+
356358
spinner.stop()
357359

358360
if (!result.data.length) {

src/commands/audit-log.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ async function fetchOrgAuditLog(
154154
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner)
155155
return
156156
}
157+
157158
spinner.stop()
158159

159160
const data: AuditChoices = []

src/commands/dependencies.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ async function searchDeps({
109109
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
110110
)
111111
}
112-
const spinnerText = 'Searching dependencies...'
113-
const spinner = yoctoSpinner({ text: spinnerText }).start()
114-
112+
const spinner = yoctoSpinner({ text: 'Searching dependencies...' }).start()
115113
const socketSdk = await setupSdk(apiKey)
116114

117115
const result = await handleApiCall(
@@ -124,9 +122,7 @@ async function searchDeps({
124122
return
125123
}
126124

127-
spinner.stop()
128-
129-
console.log('Organization dependencies:\n')
125+
spinner.stop('Organization dependencies:')
130126

131127
if (outputJson) {
132128
console.log(result.data)

src/commands/diff-scan/get.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ async function getDiffScan(
142142
const data = await response.json()
143143

144144
if (!response.ok) {
145-
spinner.stop()
146145
const err = await handleAPIError(response.status)
147-
console.error(`${colors.bgRed(colors.white(response.statusText))}: ${err}`)
146+
spinner.error(`${colors.bgRed(colors.white(response.statusText))}: ${err}`)
148147
return
149148
}
150149

src/commands/info.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,32 +197,27 @@ function formatPackageDataOutput(
197197
Object.entries(scoreResult).map(score =>
198198
console.log(`- ${score[0]}: ${formatScore(score[1])}`)
199199
)
200-
200+
console.log('\n')
201201
if (objectSome(severityCount)) {
202-
const issueSummary = formatSeverityCount(severityCount)
203-
console.log('\n')
204202
spinner[strict ? 'error' : 'success'](
205-
`Package has these issues: ${issueSummary}`
203+
`Package has these issues: ${formatSeverityCount(severityCount)}`
206204
)
207205
formatPackageIssuesDetails(data, outputMarkdown)
208206
} else {
209-
console.log('\n')
210207
spinner.success('Package has no issues')
211208
}
212209

213210
const format = new ColorOrMarkdown(!!outputMarkdown)
214211
const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}`
212+
213+
console.log('\n')
215214
if (pkgVersion === 'latest') {
216215
console.log(
217-
'\nDetailed info on socket.dev: ' +
218-
format.hyperlink(`${pkgName}`, url, { fallbackToUrl: true })
216+
`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, { fallbackToUrl: true })}`
219217
)
220218
} else {
221219
console.log(
222-
'\nDetailed info on socket.dev: ' +
223-
format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
224-
fallbackToUrl: true
225-
})
220+
`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, { fallbackToUrl: true })}`
226221
)
227222
}
228223
if (!outputMarkdown) {

src/commands/login.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ export const login: CliSubcommand = {
102102
const spinner = yoctoSpinner({ text: 'Verifying API key...' }).start()
103103

104104
let orgs: SocketSdkReturnType<'getOrganizations'>['data']
105-
106105
try {
107106
const sdk = await setupSdk(apiKey, apiBaseUrl, apiProxy)
108107
const result = await sdk.getOrganizations()
109108
if (!result.success) {
110109
throw new AuthError()
111110
}
112111
orgs = result.data
113-
spinner.success('API key verified\n')
112+
spinner.success('API key verified')
114113
} catch {
115114
spinner.error('Invalid API key')
116115
return

src/commands/optimize.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -775,32 +775,32 @@ export const optimize: CliSubcommand = {
775775
})
776776
if (!supported) {
777777
console.log(
778-
` ${COMMAND_TITLE}: No supported Node or browser range detected`
778+
`✖️ ${COMMAND_TITLE}: No supported Node or browser range detected`
779779
)
780780
return
781781
}
782782
if (agent === 'vlt') {
783783
console.log(
784-
` ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`
784+
`✖️ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`
785785
)
786786
return
787787
}
788788
const lockName = lockPath ? path.basename(lockPath) : 'lock file'
789789
if (lockSrc === undefined) {
790-
console.log(` ${COMMAND_TITLE}: No ${lockName} found`)
790+
console.log(`✖️ ${COMMAND_TITLE}: No ${lockName} found`)
791791
return
792792
}
793793
if (lockSrc.trim() === '') {
794-
console.log(` ${COMMAND_TITLE}: ${lockName} is empty`)
794+
console.log(`✖️ ${COMMAND_TITLE}: ${lockName} is empty`)
795795
return
796796
}
797797
if (pkgPath === undefined) {
798-
console.log(` ${COMMAND_TITLE}: No package.json found`)
798+
console.log(`✖️ ${COMMAND_TITLE}: No package.json found`)
799799
return
800800
}
801801
if (prod && (agent === 'bun' || agent === 'yarn/berry')) {
802802
console.log(
803-
` ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`
803+
`✖️ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`
804804
)
805805
return
806806
}
@@ -879,9 +879,8 @@ export const optimize: CliSubcommand = {
879879
)
880880
}
881881
} catch {
882-
spinner.stop()
883-
console.log(
884-
`✘ ${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`
882+
spinner.error(
883+
`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`
885884
)
886885
}
887886
}

src/commands/organization.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,23 @@ async function fetchOrganizations(): Promise<void> {
5252
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
5353
)
5454
}
55-
const socketSdk = await setupSdk(apiKey)
5655
const spinner = yoctoSpinner({ text: 'Fetching organizations...' }).start()
57-
56+
const socketSdk = await setupSdk(apiKey)
5857
const result = await handleApiCall(
5958
socketSdk.getOrganizations(),
6059
'looking up organizations'
6160
)
61+
6262
if (result.success === false) {
6363
handleUnsuccessfulApiResponse('getOrganizations', result, spinner)
6464
return
6565
}
6666

67-
spinner.stop()
68-
69-
const organizations = Object.values(result.data.organizations)
70-
71-
console.log(
67+
spinner.stop(
7268
`List of organizations associated with your API key: ${colors.italic(apiKey)}`
7369
)
7470

71+
const organizations = Object.values(result.data.organizations)
7572
for (const o of organizations) {
7673
console.log(`
7774
Name: ${o?.name}

src/commands/report/create.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,12 @@ async function createReport(
271271
)
272272
const result = await handleApiCall(apiCall, 'creating report')
273273

274-
if (result.success === false) {
275-
return handleUnsuccessfulApiResponse('createReport', result, spinner)
274+
if (result.success) {
275+
spinner.success()
276+
return result
276277
}
277-
278-
// Conclude the status of the API call
279-
280-
spinner.success()
281-
282-
return result
278+
handleUnsuccessfulApiResponse('createReport', result, spinner)
279+
return undefined
283280
}
284281

285282
function formatReportCreationOutput(
@@ -293,11 +290,8 @@ function formatReportCreationOutput(
293290
console.log(JSON.stringify(data, undefined, 2))
294291
return
295292
}
296-
297293
const format = new ColorOrMarkdown(!!outputMarkdown)
298-
299294
console.log(
300-
'\nNew report: ' +
301-
format.hyperlink(data.id, data.url, { fallbackToUrl: true })
295+
`New report: ${format.hyperlink(data.id, data.url, { fallbackToUrl: true })}`
302296
)
303297
}

src/commands/repos/create.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ async function createRepo(
150150
'creating repository'
151151
)
152152

153-
if (!result.success) {
153+
if (result.success) {
154+
spinner.success('Repository created successfully')
155+
} else {
154156
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner)
155-
return
156157
}
157-
158-
spinner.stop()
159-
160-
console.log('\n✅ Repository created successfully\n')
161158
}

0 commit comments

Comments
 (0)