belsrc/vue-gen

View on GitHub
src/utils/make-dir.js

Summary

Maintainability
A
0 mins
Test Coverage
/* eslint-disable promise/prefer-await-to-then */
const fs = require('fs');
const checkDir = require('./check-dir');

const promMkDir = filePath =>
  new Promise((resolve, reject) =>
    fs.mkdir(filePath, { recursive: true }, error => error ? reject(error) : resolve(filePath)));

const makeDir = async filePath =>
  Promise.resolve()
    .then(() => checkDir(filePath))
    .then(exists => exists ? filePath : promMkDir(filePath));

module.exports = makeDir;