Skip to content

Commit

Permalink
feat: refactor project count
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Nov 4, 2019
1 parent 17410d5 commit 5dccb99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/cli/commands/monitor/formatters/format-monitor-response.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import * as _ from 'lodash';
import chalk from 'chalk';
import {MonitorResult } from '../../../../lib/types';
import { MonitorResult } from '../../../../lib/types';

export function formatMonitorOutput(
packageManager,
res: MonitorResult,
manageUrl,
options,
projectName?: string,
advertiseSubprojectsCount?: number | null,
) {
foundProjectCount?: number,
): string {
const advertiseGradleSubProjectsCount =
packageManager === 'gradle' && !options['gradle-sub-project'];

const issues = res.licensesPolicy ? 'issues' : 'vulnerabilities';
const humanReadableName = projectName
? `${res.path} (${projectName})`
Expand All @@ -22,9 +25,9 @@ export function formatMonitorOutput(
'Explore this snapshot at ' +
res.uri +
'\n\n' +
(advertiseSubprojectsCount
(advertiseGradleSubProjectsCount && foundProjectCount
? chalk.bold.white(
`This project has multiple sub-projects (${advertiseSubprojectsCount}), ` +
`This project has multiple sub-projects (${foundProjectCount}), ` +
'use --all-sub-projects flag to scan all sub-projects.\n\n',
)
: '') +
Expand Down
17 changes: 4 additions & 13 deletions src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,11 @@ async function monitor(...args0: MethodArgs): Promise<any> {
// a MultiProjectResult to an array of these.

let perProjectResult: pluginApi.SinglePackageResult[] = [];
let advertiseSubprojectsCount: number | null = null;
let foundProjectCount;
if (pluginApi.isMultiResult(inspectResult)) {
perProjectResult = convertMultiPluginResultToSingle(inspectResult);
} else {
if (packageManager === 'gradle') {
advertiseSubprojectsCount = getSubProjectCountForGradle(
inspectResult,
options['gradle-sub-project'],
);
}
foundProjectCount = getSubProjectCount(inspectResult);
perProjectResult = [inspectResult];
}

Expand Down Expand Up @@ -206,7 +201,7 @@ async function monitor(...args0: MethodArgs): Promise<any> {
manageUrl,
options,
projectName,
advertiseSubprojectsCount,
foundProjectCount,
);
results.push({ ok: true, data: monOutput, path, projectName });
}
Expand Down Expand Up @@ -274,12 +269,8 @@ function convertMultiPluginResultToSingle(
}));
}

function getSubProjectCountForGradle(
inspectResult,
calledForSingleSubProject,
): number | null {
function getSubProjectCount(inspectResult): number | null {
if (
!calledForSingleSubProject &&
inspectResult.plugin.meta &&
inspectResult.plugin.meta.allSubProjectNames &&
inspectResult.plugin.meta.allSubProjectNames.length > 1
Expand Down

0 comments on commit 5dccb99

Please sign in to comment.