'use strict';

var _loudRejection;

function _load_loudRejection() {
  return _loudRejection = _interopRequireDefault(require('loud-rejection'));
}

var _commandRegistrarBuilder;

function _load_commandRegistrarBuilder() {
  return _commandRegistrarBuilder = _interopRequireDefault(require('./cli/command-registrar-builder'));
}

var _extensionsLoader;

function _load_extensionsLoader() {
  return _extensionsLoader = _interopRequireDefault(require('./extensions/extensions-loader'));
}

var _hooks;

function _load_hooks() {
  return _hooks = _interopRequireDefault(require('./hooks'));
}

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

(0, (_loudRejection || _load_loudRejection()).default)();
(_hooks || _load_hooks()).default.init();

// Load extensions
(0, (_extensionsLoader || _load_extensionsLoader()).default)().then(function (extensions) {
  // Make sure to register all the hooks actions in the global hooks manager
  extensions.forEach(function (extension) {
    extension.registerHookActionsOnHooksManager();
  });
  var extensionsCommands = extensions.reduce(function (acc, curr) {
    if (curr.commands && curr.commands.length) {
      acc = acc.concat(curr.commands);
    }
    return acc;
  }, []);
  var registrar = (0, (_commandRegistrarBuilder || _load_commandRegistrarBuilder()).default)(extensionsCommands);

  try {
    registrar.run();
  } catch (err) {
    console.error('loud rejected:', err); // eslint-disable-line no-console
  }
});