diff --git a/src/index.ts b/src/index.ts index 76920481e..d7e377883 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'], @@ -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; @@ -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(); diff --git a/src/scanner/Scanner.ts b/src/scanner/Scanner.ts index f5534a056..52b1b3dbf 100644 --- a/src/scanner/Scanner.ts +++ b/src/scanner/Scanner.ts @@ -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 { @@ -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)));