|
1 | 1 | import { Spinner } from '@socketsecurity/registry/lib/spinner' |
| 2 | +import { pluralize } from '@socketsecurity/registry/lib/words' |
2 | 3 |
|
3 | 4 | import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api' |
4 | | -import { debugLog } from '../../utils/debug' |
5 | | -import { getLogSymbols } from '../../utils/logging' |
| 5 | +import { debugLog, isDebug } from '../../utils/debug' |
6 | 6 | import { getPackageFiles } from '../../utils/path-resolve' |
7 | 7 | import { setupSdk } from '../../utils/sdk' |
8 | 8 |
|
@@ -48,32 +48,34 @@ export async function createReport( |
48 | 48 | supportedFiles |
49 | 49 | ) |
50 | 50 |
|
51 | | - debugLog( |
52 | | - 'Uploading:', |
53 | | - packagePaths.join(`\n${getLogSymbols().info} Uploading: `) |
54 | | - ) |
| 51 | + const { length: packagePathsCount } = packagePaths |
55 | 52 |
|
| 53 | + if (packagePathsCount && isDebug()) { |
| 54 | + for (const pkgPath of packagePaths) { |
| 55 | + debugLog(`Uploading: ${pkgPath}`) |
| 56 | + } |
| 57 | + } |
56 | 58 | if (dryRun) { |
57 | 59 | debugLog('[dryRun] Skipped actual upload') |
58 | 60 | return undefined |
59 | | - } else { |
60 | | - const socketSdk = await setupSdk() |
61 | | - const spinner = new Spinner({ |
62 | | - text: `Creating report with ${packagePaths.length} package files` |
63 | | - }).start() |
| 61 | + } |
| 62 | + const spinner = new Spinner() |
| 63 | + |
| 64 | + spinner.start( |
| 65 | + `Creating report with ${packagePathsCount} package ${pluralize('file', packagePathsCount)}` |
| 66 | + ) |
64 | 67 |
|
65 | | - const apiCall = socketSdk.createReportFromFilePaths( |
66 | | - packagePaths, |
67 | | - cwd, |
68 | | - socketConfig?.issueRules |
69 | | - ) |
70 | | - const result = await handleApiCall(apiCall, 'creating report') |
| 68 | + const apiCall = socketSdk.createReportFromFilePaths( |
| 69 | + packagePaths, |
| 70 | + cwd, |
| 71 | + socketConfig?.issueRules |
| 72 | + ) |
| 73 | + const result = await handleApiCall(apiCall, 'creating report') |
71 | 74 |
|
72 | | - if (!result.success) { |
73 | | - handleUnsuccessfulApiResponse('createReport', result, spinner) |
74 | | - return undefined |
75 | | - } |
76 | | - spinner.successAndStop() |
77 | | - return result |
| 75 | + if (!result.success) { |
| 76 | + handleUnsuccessfulApiResponse('createReport', result, spinner) |
| 77 | + return undefined |
78 | 78 | } |
| 79 | + spinner.successAndStop() |
| 80 | + return result |
79 | 81 | } |
0 commit comments