-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from snyk/refactor/monitor
Refactor: monitor to tidy & use more functions for readability and maintanability
- Loading branch information
Showing
3 changed files
with
110 additions
and
95 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/cli/commands/monitor/formatters/format-monitor-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as _ from 'lodash'; | ||
import chalk from 'chalk'; | ||
import { MonitorResult } from '../../../../lib/types'; | ||
|
||
export function formatMonitorOutput( | ||
packageManager, | ||
res: MonitorResult, | ||
manageUrl, | ||
options, | ||
projectName?: string, | ||
foundProjectCount?: number, | ||
): string { | ||
const advertiseGradleSubProjectsCount = | ||
packageManager === 'gradle' && !options['gradle-sub-project']; | ||
|
||
const issues = res.licensesPolicy ? 'issues' : 'vulnerabilities'; | ||
const humanReadableName = projectName | ||
? `${res.path} (${projectName})` | ||
: res.path; | ||
const strOutput = | ||
chalk.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') + | ||
(packageManager === 'yarn' | ||
? 'A yarn.lock file was detected - continuing as a Yarn project.\n' | ||
: '') + | ||
'Explore this snapshot at ' + | ||
res.uri + | ||
'\n\n' + | ||
(advertiseGradleSubProjectsCount && foundProjectCount | ||
? chalk.bold.white( | ||
`This project has multiple sub-projects (${foundProjectCount}), ` + | ||
'use --all-sub-projects flag to scan all sub-projects.\n\n', | ||
) | ||
: '') + | ||
(res.isMonitored | ||
? 'Notifications about newly disclosed ' + | ||
issues + | ||
' related ' + | ||
'to these dependencies will be emailed to you.\n' | ||
: chalk.bold.red( | ||
'Project is inactive, so notifications are turned ' + | ||
'off.\nActivate this project here: ' + | ||
manageUrl + | ||
'\n\n', | ||
)) + | ||
(res.trialStarted | ||
? chalk.yellow( | ||
"You're over the free plan usage limit, \n" + | ||
'and are now on a free 14-day premium trial.\n' + | ||
'View plans here: ' + | ||
manageUrl + | ||
'\n\n', | ||
) | ||
: ''); | ||
|
||
return options.json | ||
? JSON.stringify( | ||
_.assign({}, res, { | ||
manageUrl, | ||
packageManager, | ||
}), | ||
) | ||
: strOutput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters