"use strict";

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

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

function _ramda() {
  const data = _interopRequireDefault(require("ramda"));

  _ramda = function () {
    return data;
  };

  return data;
}

function _semver() {
  const data = _interopRequireDefault(require("semver"));

  _semver = function () {
    return data;
  };

  return data;
}

/**
 * Change all the component's version to be a valid semver
 * @param {*} componentModel - The parsed component model
 */
function changeVersionToSemVer(componentModel) {
  const semVerVersions = {};

  const addUpdatedVersion = (value, key) => {
    // In case there is already a semver, do nothing
    if (_semver().default.valid(key)) {
      semVerVersions[key] = value;
    } else {
      const newVersion = `0.0.${key}`;
      semVerVersions[newVersion] = value;
    }
  }; // Go over the versions array and update them


  _ramda().default.forEachObjIndexed(addUpdatedVersion, componentModel.versions);

  componentModel.versions = semVerVersions;
  return componentModel;
}

const changeVersionToSemVerDeclartaion = {
  name: 'change version to SemVer',
  migrate: changeVersionToSemVer
};
var _default = changeVersionToSemVerDeclartaion;
exports.default = _default;