'use strict';

var _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _fsExtra;

function _load_fsExtra() {
  return _fsExtra = _interopRequireDefault(require('fs-extra'));
}

var _glob;

function _load_glob() {
  return _glob = _interopRequireDefault(require('glob'));
}

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = function removeContainingDirIfEmpty(componentDir) {
  return new Promise(function (resolve, reject) {
    var containingDir = (_path || _load_path()).default.dirname(componentDir);

    return (0, (_glob || _load_glob()).default)((_path || _load_path()).default.join(containingDir, '*'), function (err, matches) {
      if (err) return reject(err);
      if ((_ramda || _load_ramda()).default.isEmpty(matches)) {
        return (_fsExtra || _load_fsExtra()).default.remove(containingDir, function (e) {
          if (e) return reject(e);
          return resolve();
        });
      }

      return resolve();
    });
  });
};