Skip to content

Commit

Permalink
feat(Results): Saving command line output for viewing later in history (
Browse files Browse the repository at this point in the history
#89)

Fixes: #78
  • Loading branch information
ndickerson authored Sep 26, 2018
1 parent ee512df commit 041dd87
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ export class AppComponent implements OnInit {
private onDone(text: string): void {
this.zone.run(() => {
this.currentRun.output = this.currentRun.output.concat(text);
// Wait for final report from results file
this.fileService.writeOutputFile(this.currentRun.output);
// Wait a second for final report from results file (final file changes can occur just after CLI process exits)
setTimeout(() => {
this.fileService.unsubscribe();
this.dataloaderService.unsubscribe();
this.sendNotification();
this.fileService.getAllRuns(this.onRunData.bind(this));
this.fileService.getAllRuns(this.onRunData.bind(this)); // refreshes data
}, 1000);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/app/providers/file/file.service.fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class FakePreviewData {
class Run {
previewData: IPreviewData = new FakePreviewData();
results: IResults = new FakeResultsData(this.previewData);
output: string = '\nData Loader Sample Output File\n Total Records: 0\n';
}

/**
Expand Down
28 changes: 26 additions & 2 deletions src/app/providers/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class FileService {
private userDataDir: string;
private runsDir: string;
private resultsFile: string;
private outputFile: string;
private settingsFile: string;
private configFile: string;

Expand All @@ -68,6 +69,7 @@ export class FileService {
let timestamp: string = moment().format('YYYY-MM-DD_HH.mm.ss');
let runDir: string = path.join(this.runsDir, timestamp);
this.resultsFile = path.join(runDir, 'results.json');
this.outputFile = path.join(runDir, 'output.txt');

// Create runs directory if it does not exist
if (!this.electronService.fs.existsSync(this.runsDir)) {
Expand All @@ -88,6 +90,9 @@ export class FileService {
return '';
}

/**
* Reads the user's settings file and sets appropriate defaults for missing values and older versions.
*/
readSettings(): ISettings {
if (ElectronService.isElectron()) {
if (this.electronService.fs.existsSync(this.settingsFile)) {
Expand Down Expand Up @@ -122,6 +127,9 @@ export class FileService {
}
}

/**
* Saves the users settings in the current settings file version.
*/
writeSettings(settings: ISettings): void {
if (ElectronService.isElectron()) {
let encryptedSettings: ISettings = Object.assign({}, settings);
Expand Down Expand Up @@ -162,6 +170,17 @@ export class FileService {
}
}

/**
* Since the CLI does not save off the stderr/stdout to file, we capture it and save it out when a run completes
*
* @param output: the output text that has been captured during a run
*/
writeOutputFile(output: string): void {
if (ElectronService.isElectron()) {
this.electronService.fs.writeFileSync(this.outputFile, output);
}
}

/**
* Returns the total number of rows and the first 100 rows of CSV data with the following format:
*
Expand Down Expand Up @@ -254,12 +273,17 @@ export class FileService {
if (this.electronService.fs.statSync(dir).isDirectory()) {
let previewData: string = path.join(dir, 'previewData.json');
let results: string = path.join(dir, 'results.json');
let output: string = path.join(dir, 'output.txt');
if (this.electronService.fs.existsSync(previewData) && this.electronService.fs.existsSync(results)) {
try {
allRuns.unshift({
let run: IRun = {
previewData: JSON.parse(this.electronService.fs.readFileSync(previewData, 'utf8')),
results: JSON.parse(this.electronService.fs.readFileSync(results, 'utf8')),
});
};
if (this.electronService.fs.existsSync(output)) {
run.output = this.electronService.fs.readFileSync(output, 'utf8');
}
allRuns.unshift(run);
} catch (parseErr) {
console.error(`Error parsing run directory: ${dir} - ${parseErr}`); // tslint:disable-line:no-console
}
Expand Down

0 comments on commit 041dd87

Please sign in to comment.