"use strict";

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");

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

_Object$defineProperty(exports, "__esModule", {
  value: true
});

exports.default = void 0;

var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _plugin = _interopRequireDefault(require("@start/plugin"));

var _pluginSequence = _interopRequireDefault(require("@start/plugin-sequence"));

var _bootstrap = _interopRequireDefault(require("@lerna/bootstrap"));

var _link = _interopRequireDefault(require("@lerna/link"));

var _isWorkspace = _interopRequireDefault(require("../utils/isWorkspace"));

var _yarnInstall = _interopRequireDefault(require("./yarnInstall"));

var _default = (link, freeze) => (0, _plugin.default)('LERNA BOOTSTRAP', ({
  reporter
}) => /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
  const yarnParams = freeze ? '--frozen-lockfile' : '';
  const bootstrapOptions = freeze ? {
    npmClientArgs: ['--production']
  } : {};

  try {
    const workspace = yield (0, _isWorkspace.default)();

    if (workspace) {
      yield (0, _bootstrap.default)(bootstrapOptions);

      if (link) {
        yield (0, _link.default)({
          forceLocal: true,
          _: {
            pop: () => 'no'
          }
        });
      }
    } else {
      reporter.emit('message', 'This is not a monorepo, fallback to yarn install');
      return (0, _pluginSequence.default)((0, _yarnInstall.default)(yarnParams))(reporter)();
    }

    return _promise.default.resolve();
  } catch (e) {
    return _promise.default.reject(e);
  }
}));

exports.default = _default;
module.exports = exports.default;