"use strict";

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

require("core-js/modules/es.promise");

require("core-js/modules/es.string.replace");

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

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

exports.default = void 0;

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

var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));

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

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

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

var _run = _interopRequireDefault(require("../utils/run"));

var _default = (tag = null) => (0, _plugin.default)('PUBLISH TO NPM', ({
  reporter
}) =>
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
  try {
    const currentBranch = yield (0, _gitBranch.default)();
    let tagName = '';

    if (Boolean(tag)) {
      tagName = tag;
    } else if (currentBranch === 'develop') {
      tagName = 'next';
    } else if ((0, _startsWith.default)(currentBranch).call(currentBranch, 'feature/')) {
      tagName = currentBranch.replace('feature/', '');
    }

    const tagCommand = !!tagName ? ` --tag ${tagName}` : '';
    yield (0, _run.default)(`npm publish ${tagCommand}`);
    return _promise.default.resolve();
  } catch (e) {
    _promise.default.reject(e);
  }
}));

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