'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _semver;

function _load_semver() {
  return _semver = _interopRequireDefault(require('semver'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Change all the component's version to be a valid semver
 * @param {*} componentModel - The parsed component model
 */
function changeVersionToSemVer(componentModel) {
  var semVerVersions = {};
  var addUpdatedVersion = function addUpdatedVersion(value, key) {
    // In case there is already a semver, do nothing
    if ((_semver || _load_semver()).default.valid(key)) {
      semVerVersions[key] = value;
    } else {
      var newVersion = `0.0.${key}`;
      semVerVersions[newVersion] = value;
    }
  };
  // Go over the versions array and update them
  (_ramda || _load_ramda()).default.forEachObjIndexed(addUpdatedVersion, componentModel.versions);
  componentModel.versions = semVerVersions;
  return componentModel;
}

var changeVersionToSemVerDeclartaion = {
  name: 'change version to SemVer',
  migrate: changeVersionToSemVer
};

exports.default = changeVersionToSemVerDeclartaion;