Skip to content

Commit

Permalink
Feature: write report to input dir in report-only mode (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Oct 24, 2022
1 parent fedbc29 commit acee792
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/modules/reportGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class ReportGenerator {
async generate(datsStatuses: DATStatus[]): Promise<void> {
await this.progressBar.logInfo('Generating report');

const report = this.options.getOutputReport();
const report = this.options.getOutputReportPath();

const contents = (
await Promise.all(datsStatuses
Expand Down
17 changes: 14 additions & 3 deletions src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'reflect-metadata';

import { Expose, instanceToPlain, plainToInstance } from 'class-transformer';
import fg from 'fast-glob';
import { promises as fsPromises } from 'fs';
import fs, { promises as fsPromises } from 'fs';
import { isNotJunk } from 'junk';
import micromatch from 'micromatch';
import moment from 'moment';
Expand Down Expand Up @@ -343,8 +343,19 @@ export default class Options implements OptionsProps {
return fsPoly.makeLegal(output);
}

getOutputReport(): string {
const output = this.shouldWrite() ? this.output : process.cwd();
getOutputReportPath(): string {
let output = process.cwd();
if (this.shouldWrite()) {
// Write to the output dir if writing
output = this.output;
} else if (this.input.length === 1) {
// Write to the input dir if there is only one
let [input] = this.input;
while (!fs.existsSync(input)) {
input = path.dirname(input);
}
}

return path.join(
output,
fsPoly.makeLegal(`${Constants.COMMAND_NAME}_${moment().format()}.csv`),
Expand Down
2 changes: 1 addition & 1 deletion test/igir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function expectEndToEnd(optionsProps: OptionsProps, expectedFiles: string[
await fsPoly.rm(tempOutput, { force: true, recursive: true });

const reports = await fg(path.join(
path.dirname(options.getOutputReport()),
path.dirname(options.getOutputReportPath()),
`${Constants.COMMAND_NAME}_*.csv`,
));
await Promise.all(reports.map(async (report) => fsPoly.rm(report)));
Expand Down

0 comments on commit acee792

Please sign in to comment.