"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 _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));

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

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

var _gitBranch = _interopRequireDefault(require("git-branch"));

var _publish = _interopRequireDefault(require("@lerna/publish"));

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

var _default = forcePublish => (0, _plugin.default)('PUBLISH', ({
  reporter
}) => /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
  const packagesToPublish = forcePublish && forcePublish === 'all' ? '*' : forcePublish;

  try {
    const currentBranch = yield (0, _gitBranch.default)();

    if (currentBranch === 'develop') {
      yield (0, _publish.default)({
        canary: true,
        distTag: 'next',
        yes: true,
        verifyRegistry: false,
        verifyAccess: false,
        includeMergedTags: true,
        forcePublish: packagesToPublish,
        access: 'public',
        loglevel: 'silly'
      });
    } else if ((0, _startsWith.default)(currentBranch).call(currentBranch, 'feature/')) {
      const featureName = currentBranch.replace('feature/', '');
      yield (0, _publish.default)({
        canary: true,
        preid: featureName,
        distTag: featureName,
        yes: true,
        verifyRegistry: false,
        verifyAccess: false,
        includeMergedTags: true,
        access: 'public',
        forcePublish: packagesToPublish
      });
    } else if (currentBranch === 'master') {
      yield (0, _publish.default)({
        yes: true,
        verifyRegistry: false,
        verifyAccess: false,
        forcePublish: packagesToPublish,
        bump: 'minor',
        access: 'public',
        includeMergedTags: true,
        push: true
      });
    } else {
      reporter.emit('error', 'Current branch is not supported for publishing');
    }

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

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