All files / src/helpers ensure-file.ts

82.61% Statements 19/23
100% Branches 9/9
100% Functions 8/8
88.89% Lines 16/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  2x 1x 1x 1x 3x 1x     2x 2x 2x 2x   1x 1x 1x  
import * as chalk from 'chalk';
import * as fs from 'fs';
import {promisify} from 'util';

export async function ensureFile(filename: string): Promise<void | never> {
  try {
    await promisify(fs.access)(filename, fs.constants.F_OK);
  } catch (_) {
    try {
      await promisify(fs.writeFile)(filename, '');
    } catch (err) {
      // tslint:disable-next-line no-console
      console.error(chalk.red(err.message));
      process.exit(1);
    }
  }
}