carvalholeo/generator-dh

View on GitHub
src/utils/emptyDirectory.js

Summary

Maintainability
A
0 mins
Test Coverage
const { readdir } = require('fs-extra')
/**
 * Check if the given directory `dir` is empty.
 *
 * @param {String} dir Directory to be verified if is empty
 * @param {Function} fn Callback function called when this function were finished
 * @return {void}
 */
function emptyDirectory (dir, fn) {
  readdir(dir, function (err, files) {
    if (err && err.code !== 'ENOENT') {
      throw err
    }
    fn(!files || !files.length)
  })
}

module.exports = emptyDirectory