Skip to content

Commit

Permalink
fix(core): exit after the printing the debug
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopsimek committed Oct 30, 2019
1 parent a899956 commit 8623d57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { createRootContainer } from './inversify.config';
import { Scanner } from './scanner/Scanner';
import { Scanner, ScanResult } from './scanner/Scanner';
import { Command, flags } from '@oclif/command';
import cli from 'cli-ux';
import { ServiceError } from './lib/errors';
Expand Down Expand Up @@ -52,8 +52,9 @@ class DXScannerCommand extends Command {
const container = createRootContainer({ uri: scanPath, auth: authorization, json, fail });
const scanner = container.get(Scanner);

let scanResult: ScanResult;
try {
await scanner.scan();
scanResult = await scanner.scan();
} catch (error) {
if (error instanceof ServiceError) {
ScanningStrategyDetectorUtils.isGitHubPath(scanPath)
Expand All @@ -65,7 +66,7 @@ class DXScannerCommand extends Command {
const container = createRootContainer({ uri: scanPath, auth: authorization, json: json });
const scanner = container.get(Scanner);

await scanner.scan();
scanResult = await scanner.scan();
} else {
throw error;
}
Expand All @@ -76,6 +77,10 @@ class DXScannerCommand extends Command {
const hrend = process.hrtime(hrstart);

console.info('Scan duration %ds.', hrend[0]);

if (scanResult.shouldExitOnEnd) {
process.exit(1);
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Scanner {
private readonly practices: IPracticeWithMetadata[];
private readonly argumentsProvider: ArgumentsProvider;
private readonly scanDebug: debug.Debugger;
private shouldExitOnEnd = false;

constructor(
@inject(ScanningStrategyDetector) scanStrategyDetector: ScanningStrategyDetector,
Expand All @@ -52,7 +53,7 @@ export class Scanner {
this.scanDebug = debug('scanner');
}

async scan(): Promise<void> {
async scan(): Promise<ScanResult> {
let scanStrategy = await this.scanStrategyDetector.detect();
this.scanDebug(`Scan strategy: ${inspect(scanStrategy)}`);
scanStrategy = await this.preprocessData(scanStrategy);
Expand All @@ -70,6 +71,8 @@ export class Scanner {
projectComponents.length,
)}; Practices: ${inspect(componentsWithPractices.length)}.`,
);

return { shouldExitOnEnd: this.shouldExitOnEnd };
}

/**
Expand Down Expand Up @@ -182,7 +185,7 @@ export class Scanner {

const notPracticingPracticesToFail = ScannerUtils.filterNotPracticingPracticesToFail(relevantPractices, this.argumentsProvider);
if (notPracticingPracticesToFail.length > 0) {
process.exit(1);
this.shouldExitOnEnd = true;
}
}

Expand Down Expand Up @@ -259,3 +262,7 @@ export interface PracticeWithContext {
evaluation: PracticeEvaluationResult;
isOn: boolean;
}

export type ScanResult = {
shouldExitOnEnd: boolean;
};

0 comments on commit 8623d57

Please sign in to comment.