Skip to content

Commit

Permalink
feat(scanner): run on a root component only if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopsimek committed Oct 31, 2019
1 parent 41ac426 commit 7a3d413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DXScannerCommand extends Command {
// flag with a value (-n, --name=VALUE)
authorization: flags.string({ char: 'a', description: 'Credentials to the repository.' }),
json: flags.boolean({ char: 'j', description: 'Print report in JSON' }),
recursive: flags.boolean({ char: 'r', description: 'Scan all components recursively in all sub folders' }),
init: flags.boolean({ char: 'i', description: 'Initialize DX Scanner configuration' }),
fail: flags.string({
options: ['high', 'medium', 'small', 'off', 'all'],
Expand All @@ -45,7 +46,7 @@ class DXScannerCommand extends Command {

cli.action.start(`Scanning URI: ${scanPath}`);

const container = createRootContainer({ uri: scanPath, auth: authorization, json, fail });
const container = createRootContainer({ uri: scanPath, auth: authorization, json, fail, recursive: flags.recursive });
const scanner = container.get(Scanner);

let scanResult: ScanResult;
Expand All @@ -59,7 +60,7 @@ class DXScannerCommand extends Command {
'Insert your Bitbucket app password.\nhttps://confluence.atlassian.com/bitbucket/app-passwords-828781300.html\n',
));

const container = createRootContainer({ uri: scanPath, auth: authorization, json: json });
const container = createRootContainer({ uri: scanPath, auth: authorization, json, fail, recursive: flags.recursive });
const scanner = container.get(Scanner);

scanResult = await scanner.scan();
Expand Down
6 changes: 5 additions & 1 deletion src/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ScannerContextFactory, Types } from '../types';
import { ScannerUtils } from './ScannerUtils';
import _ from 'lodash';
import { sharedSubpath } from '../detectors/utils';
import cli from 'cli-ux';

@injectable()
export class Scanner {
Expand Down Expand Up @@ -155,9 +156,12 @@ export class Scanner {
let relevantComponents = componentsWithContext;

// run only for root component if not set explicitly to run recursively
if (!this.argumentsProvider.recursive) {
if (!this.argumentsProvider.recursive && relevantComponents.length > 1) {
const componentsSharedPath = sharedSubpath(relevantComponents.map((cwc) => cwc.component.path));
relevantComponents = relevantComponents.filter((cwc) => cwc.component.path === componentsSharedPath);
cli.info(
`Found more than 1 component. To scan all ${componentsWithContext.length} components run the scanner with an argument --recursive`,
);
}

const practicesWithComponentContext = await Promise.all(relevantComponents.map((cwctx) => this.detectPracticesForComponent(cwctx)));
Expand Down

0 comments on commit 7a3d413

Please sign in to comment.