"use strict";

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

var _core = require("../../core");

var _options = require("./options");

var _installerLogger = _interopRequireDefault(require("./installer-logger"));

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var _default =
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
  var options,
      _ref2,
      seedersFolder,
      customSeederTemplate,
      logger,
      installer,
      observable,
      _args = arguments;

  return regeneratorRuntime.wrap(function _callee$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
          _context.next = 3;
          return (0, _options.promptMissingOptions)(options);

        case 3:
          _ref2 = _context.sent;
          seedersFolder = _ref2.seedersFolder;
          customSeederTemplate = _ref2.customSeederTemplate;
          // create logger
          logger = new _installerLogger["default"](); // create installer

          installer = new _core.Installer({
            seedersFolder: seedersFolder,
            customSeederTemplate: customSeederTemplate
          }); // run seeders

          observable = installer.install(); // subscribe logger

          observable.subscribe(logger.asObserver()); // wait for installer to finish

          _context.next = 12;
          return observable.toPromise();

        case 12:
        case "end":
          return _context.stop();
      }
    }
  }, _callee);
}));

exports["default"] = _default;