ForestAdmin/toolbelt

View on GitHub
src/utils/directory-existence-checker.js

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
const fs = require('fs');
const path = require('path');

function DirectoryExistenceChecker(directory, basePath = undefined) {
  this.perform = () => {
    let directoryToCheck = directory;
    if (basePath) directoryToCheck = path.resolve(basePath, directory);
    try {
      fs.accessSync(directoryToCheck, fs.F_OK);
      return true;
    } catch (error) {
      return false;
    }
  };
}

module.exports = DirectoryExistenceChecker;