All files / util ensure-output.js

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23            2x 1x   2x           4x 1x   4x        
import fs from 'fs-promise';
import path from 'path';
 
// This is different from fs-extra's ensureDir because it wipes out the existing directory,
// if it's found.
async function ensureDirectory(dir) {
  if (await fs.exists(dir)) {
    await fs.remove(dir);
  }
  return fs.mkdirs(dir);
}
 
// This is different from fs-extra's ensureFile because it wipes out the existing file,
// if it's found.
async function ensureFile(file) {
  if (await fs.exists(file)) {
    await fs.remove(file);
  }
  await fs.mkdirs(path.dirname(file));
}
 
export { ensureDirectory, ensureFile };