'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _chalk;

function _load_chalk() {
  return _chalk = _interopRequireDefault(require('chalk'));
}

var _fsExtra;

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

var _roadrunner;

function _load_roadrunner() {
  return _roadrunner = _interopRequireDefault(require('roadrunner'));
}

var _command;

function _load_command() {
  return _command = _interopRequireDefault(require('../../command'));
}

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _require = require('../../../constants'),
    BASE_DOCS_DOMAIN = _require.BASE_DOCS_DOMAIN,
    MODULES_CACHE_DIR = _require.MODULES_CACHE_DIR,
    MODULES_CACHE_FILENAME = _require.MODULES_CACHE_FILENAME,
    BIT_VERSION = _require.BIT_VERSION;

var ClearCache = function (_Command) {
  _inherits(ClearCache, _Command);

  function ClearCache() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, ClearCache);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ClearCache.__proto__ || Object.getPrototypeOf(ClearCache)).call.apply(_ref, [this].concat(args))), _this), _this.name = 'clear-cache', _this.description = `clears bit's cache from current working machine\n  https://${BASE_DOCS_DOMAIN}/docs/cli-clear-cache.html`, _this.alias = 'cc', _this.opts = [], _this.loader = false, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(ClearCache, [{
    key: 'action',
    value: function action() {
      (_fsExtra || _load_fsExtra()).default.removeSync(MODULES_CACHE_DIR);
      (_fsExtra || _load_fsExtra()).default.mkdirsSync(MODULES_CACHE_DIR);
      (_roadrunner || _load_roadrunner()).default.reset(MODULES_CACHE_FILENAME);
      (_roadrunner || _load_roadrunner()).default.set('CACHE_BREAKER', { version: BIT_VERSION });
      return Promise.resolve();
    }
  }, {
    key: 'report',
    value: function report() {
      return (_chalk || _load_chalk()).default.green('cache cleared');
    }
  }]);

  return ClearCache;
}((_command || _load_command()).default);

exports.default = ClearCache;