"use strict";

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

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

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 _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _path = require("path");

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

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

var _getCurrentVersion = _interopRequireDefault(require("../utils/getCurrentVersion"));

var _getPackageNugetName = _interopRequireDefault(require("../utils/getPackageNugetName"));

var _default = nugetName => (0, _plugin.default)('PUBLISH TO NUGET', ({
  reporter
}) =>
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
  try {
    const version = (0, _getCurrentVersion.default)();
    const name = nugetName || (0, _getPackageNugetName.default)();
    const basePath = (0, _path.resolve)((0, _path.join)(process.cwd(), './_dist'));
    const outFolder = (0, _path.resolve)((0, _path.join)(process.cwd(), './build'));
    const runFrom = (0, _path.resolve)(__dirname, '../../../tools');
    const c = `${runFrom}\\Octo.exe pack --id="${name}" --basePath="${basePath}" --outFolder="${outFolder}" --version="${version}" --overwrite`;
    const createPackage = yield (0, _run.default)(c, false, true);
    const server = 'https://artifactory.meniga.net/artifactory/api/nuget/internal-nuget-artifacts/' + name;
    const apiKey = 'internal-nuget-artifacts:AP9eyg52Aur6PZFq8wFopQUV1Zv';
    const command = `${runFrom}\\nuget.exe push "${outFolder}\\${name}.${version}.nupkg" -Source "${server}" -ApiKey "${apiKey}"`;
    yield (0, _run.default)(command, false, true);
    reporter.emit('message', `Publish ${name} version ${version} to nuget successful`);
  } catch (e) {
    console.log('ERROR', e);
    return _promise.default.reject(e);
  }

  return _promise.default.resolve();
}));

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