"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _bluebird() {
  const data = require("bluebird");

  _bluebird = function () {
    return data;
  };

  return data;
}

function _path() {
  const data = _interopRequireDefault(require("path"));

  _path = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = _interopRequireDefault(require("./consumer"));

  _consumer = function () {
    return data;
  };

  return data;
}

var _default =
/*#__PURE__*/
function () {
  var _loadConsumer = (0, _bluebird().coroutine)(function* (currentPath = process.cwd(), newInstance = false) {
    if (newInstance || !loadConsumer.cache || !loadConsumer.cache[currentPath]) {
      const consumer = yield _consumer().default.load(_path().default.resolve(currentPath));
      if (!loadConsumer.cache) loadConsumer.cache = {};
      loadConsumer.cache[currentPath] = consumer;
    }

    return loadConsumer.cache[currentPath];
  });

  function loadConsumer() {
    return _loadConsumer.apply(this, arguments);
  }

  return loadConsumer;
}();

exports.default = _default;