Skip to content

Commit

Permalink
feat: use micro-promisify in writeToDisk
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeAmat committed Oct 14, 2018
1 parent 4a69ab0 commit 36b00c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PWMetrics {
await sheets.appendResults(results.runs);
}

this.outputData(results);
await this.outputData(results);

if (this.flags.expectations) {
const resultsToCompare = this.runs > 1 ? results.median.timings : results[0].timings;
Expand Down Expand Up @@ -226,10 +226,10 @@ class PWMetrics {
const formattedData = JSON.stringify(data, null, 2) + os.EOL;
// output to file.
if (this.flags.outputPath !== 'stdout') {
writeToDisk(this.flags.outputPath, formattedData);
return writeToDisk(this.flags.outputPath, formattedData);
// output to stdout
} else if (formattedData) {
process.stdout.write(formattedData);
return Promise.resolve(process.stdout.write(formattedData));
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import * as path from 'path';
import * as fs from 'fs';
import * as promisify from 'micro-promisify';

import {getMessageWithPrefix} from './messages';
import {Logger} from './logger';

Expand All @@ -27,11 +29,11 @@ export function getConfigFromFile(fileName: string = 'package.json') {
}

export function writeToDisk(fileName: string, data: string) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
const filePath = path.join(process.cwd(), fileName);

try {
fs.writeFileSync(filePath, data);
await promisify(fs.writeFile)(filePath, data);
} catch (err) {
reject(err);
}
Expand Down

0 comments on commit 36b00c2

Please sign in to comment.