'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _ramda;

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

var _objects;

function _load_objects() {
  return _objects = require('../objects');
}

var _source;

function _load_source() {
  return _source = _interopRequireDefault(require('./source'));
}

var _utils;

function _load_utils() {
  return _utils = require('../../utils');
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../bit-id');
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

var _dependencies;

function _load_dependencies() {
  return _dependencies = require('../../consumer/component/dependencies');
}

var _extensionFile;

function _load_extensionFile() {
  return _extensionFile = _interopRequireDefault(require('../../extensions/extension-file'));
}

var _sources;

function _load_sources() {
  return _sources = require('../../consumer/component/sources');
}

var _repository;

function _load_repository() {
  return _repository = _interopRequireDefault(require('../objects/repository'));
}

var _versionInvalid;

function _load_versionInvalid() {
  return _versionInvalid = _interopRequireDefault(require('../exceptions/version-invalid'));
}

var _logger;

function _load_logger() {
  return _logger = _interopRequireDefault(require('../../logger/logger'));
}

var _versionValidator;

function _load_versionValidator() {
  return _versionValidator = _interopRequireDefault(require('../version-validator'));
}

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

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

/**
 * Represent a version model in the scope
 */
var Version = function (_BitObject) {
  _inherits(Version, _BitObject);

  function Version(props) {
    _classCallCheck(this, Version);

    var _this = _possibleConstructorReturn(this, (Version.__proto__ || Object.getPrototypeOf(Version)).call(this));

    _this.mainFile = props.mainFile;
    _this.files = props.files;
    _this.dists = props.dists;
    _this.compiler = props.compiler;
    _this.tester = props.tester;
    _this.log = props.log;
    _this.dependencies = new (_dependencies || _load_dependencies()).Dependencies(props.dependencies);
    _this.devDependencies = new (_dependencies || _load_dependencies()).Dependencies(props.devDependencies);
    _this.compilerDependencies = new (_dependencies || _load_dependencies()).Dependencies(props.compilerDependencies);
    _this.testerDependencies = new (_dependencies || _load_dependencies()).Dependencies(props.testerDependencies);
    _this.docs = props.docs;
    _this.ci = props.ci || {};
    _this.specsResults = props.specsResults;
    _this.flattenedDependencies = props.flattenedDependencies || new (_bitId || _load_bitId()).BitIds();
    _this.flattenedDevDependencies = props.flattenedDevDependencies || new (_bitId || _load_bitId()).BitIds();
    _this.flattenedCompilerDependencies = props.flattenedCompilerDependencies || new (_bitId || _load_bitId()).BitIds();
    _this.flattenedTesterDependencies = props.flattenedTesterDependencies || new (_bitId || _load_bitId()).BitIds();
    _this.packageDependencies = props.packageDependencies || {};
    _this.devPackageDependencies = props.devPackageDependencies || {};
    _this.peerPackageDependencies = props.peerPackageDependencies || {};
    _this.compilerPackageDependencies = props.compilerPackageDependencies || {};
    _this.testerPackageDependencies = props.testerPackageDependencies || {};
    _this.bindingPrefix = props.bindingPrefix;
    _this.customResolvedPaths = props.customResolvedPaths;
    _this.detachedCompiler = props.detachedCompiler;
    _this.detachedTester = props.detachedTester;
    _this.validateVersion();
    return _this;
  }

  _createClass(Version, [{
    key: 'validateVersion',
    value: function validateVersion() {
      var _this2 = this;

      var nonEmptyFields = ['mainFile', 'files'];
      nonEmptyFields.forEach(function (field) {
        // $FlowFixMe
        if (!_this2[field]) {
          throw new (_versionInvalid || _load_versionInvalid()).default(`failed creating a version object, the field "${field}" can't be empty`);
        }
      });
    }
  }, {
    key: 'id',
    value: function id() {
      var obj = this.toObject();

      // @todo: remove the entire dependencies.relativePaths from the ID (it's going to be a breaking change)
      var getDependencies = function getDependencies(deps) {
        var clonedDependencies = deps.cloneAsString();
        return clonedDependencies.map(function (dependency) {
          return {
            id: dependency.id,
            relativePaths: dependency.relativePaths.map(function (relativePath) {
              return {
                sourceRelativePath: relativePath.sourceRelativePath,
                destinationRelativePath: relativePath.destinationRelativePath
              };
            })
          };
        });
      };

      var filterFunction = function filterFunction(val, key) {
        if (key === 'devDependencies' || key === 'compilerDependencies' || key === 'testerDependencies' || key === 'devPackageDependencies' || key === 'peerPackageDependencies' || key === 'compilerPackageDependencies' || key === 'testerPackageDependencies') {
          return !(_ramda || _load_ramda()).default.isEmpty(val);
        }
        return !!val;
      };

      return JSON.stringify((0, (_utils || _load_utils()).filterObject)({
        mainFile: obj.mainFile,
        files: obj.files,
        compiler: obj.compiler,
        tester: obj.tester,
        log: obj.log,
        dependencies: getDependencies(this.dependencies),
        devDependencies: getDependencies(this.devDependencies),
        compilerDependencies: getDependencies(this.compilerDependencies),
        testerDependencies: getDependencies(this.testerDependencies),
        packageDependencies: obj.packageDependencies,
        devPackageDependencies: obj.devPackageDependencies,
        peerPackageDependencies: obj.peerPackageDependencies,
        compilerPackageDependencies: obj.compilerPackageDependencies,
        testerPackageDependencies: obj.testerPackageDependencies,
        bindingPrefix: obj.bindingPrefix
      }, filterFunction));
    }
  }, {
    key: 'getAllFlattenedDependencies',
    value: function getAllFlattenedDependencies() {
      return (_bitId || _load_bitId()).BitIds.fromArray([].concat(_toConsumableArray(this.flattenedDependencies), _toConsumableArray(this.flattenedDevDependencies), _toConsumableArray(this.flattenedCompilerDependencies), _toConsumableArray(this.flattenedTesterDependencies)));
    }
  }, {
    key: 'getAllDependencies',
    value: function getAllDependencies() {
      return [].concat(_toConsumableArray(this.dependencies.dependencies), _toConsumableArray(this.devDependencies.dependencies), _toConsumableArray(this.compilerDependencies.dependencies), _toConsumableArray(this.testerDependencies.dependencies));
    }
  }, {
    key: 'getAllDependenciesCloned',
    value: function getAllDependenciesCloned() {
      var dependencies = [].concat(_toConsumableArray(this.dependencies.getClone()), _toConsumableArray(this.devDependencies.getClone()), _toConsumableArray(this.compilerDependencies.getClone()), _toConsumableArray(this.testerDependencies.getClone()));
      return new (_dependencies || _load_dependencies()).Dependencies(dependencies);
    }
  }, {
    key: 'updateFlattenedDependency',
    value: function updateFlattenedDependency(currentId, newId) {
      var getUpdated = function getUpdated(flattenedDependencies) {
        var updatedIds = flattenedDependencies.map(function (depId) {
          if (depId.isEqual(currentId)) return newId;
          return depId;
        });
        return (_bitId || _load_bitId()).BitIds.fromArray(updatedIds);
      };
      this.flattenedDependencies = getUpdated(this.flattenedDependencies);
      this.flattenedDevDependencies = getUpdated(this.flattenedDevDependencies);
      this.flattenedCompilerDependencies = getUpdated(this.flattenedCompilerDependencies);
      this.flattenedTesterDependencies = getUpdated(this.flattenedTesterDependencies);
    }
  }, {
    key: 'refs',
    value: function refs() {
      var extractRefsFromFiles = function extractRefsFromFiles(files) {
        var refs = files ? files.map(function (file) {
          return file.file;
        }) : [];
        return refs;
      };
      var files = extractRefsFromFiles(this.files);
      var dists = extractRefsFromFiles(this.dists);
      var compilerFiles = this.compiler ? extractRefsFromFiles(this.compiler.files) : [];
      var testerFiles = this.tester ? extractRefsFromFiles(this.tester.files) : [];
      return [].concat(_toConsumableArray(dists), _toConsumableArray(files), _toConsumableArray(compilerFiles), _toConsumableArray(testerFiles)).filter(function (ref) {
        return ref;
      });
    }
  }, {
    key: 'toObject',
    value: function toObject() {
      var _convertFileToObject = function _convertFileToObject(file) {
        return {
          file: file.file.toString(),
          relativePath: file.relativePath,
          name: file.name,
          test: file.test
        };
      };

      var _convertEnvToObject = function _convertEnvToObject(env) {
        if (typeof env === 'string') {
          return env;
        }
        // Store the env as string in case there is no config and files (for backward compatibility)
        if (envNameOnly(env)) {
          return env.name;
        }
        var result = {
          name: env.name,
          config: env.config,
          files: []
        };
        if (env.files && !(_ramda || _load_ramda()).default.isEmpty(env.files)) {
          result.files = env.files.map((_extensionFile || _load_extensionFile()).default.fromModelObjectToObject);
        }
        return result;
      };

      return (0, (_utils || _load_utils()).filterObject)({
        files: this.files ? this.files.map(_convertFileToObject) : null,
        mainFile: this.mainFile,
        dists: this.dists ? this.dists.map(_convertFileToObject) : null,
        compiler: this.compiler ? _convertEnvToObject(this.compiler) : null,
        bindingPrefix: this.bindingPrefix || (_constants || _load_constants()).DEFAULT_BINDINGS_PREFIX,
        tester: this.tester ? _convertEnvToObject(this.tester) : null,
        detachedCompiler: this.detachedCompiler,
        detachedTester: this.detachedTester,
        log: {
          message: this.log.message,
          date: this.log.date,
          username: this.log.username,
          email: this.log.email
        },
        ci: this.ci,
        specsResults: this.specsResults,
        docs: this.docs,
        dependencies: this.dependencies.cloneAsObject(),
        devDependencies: this.devDependencies.cloneAsObject(),
        compilerDependencies: this.compilerDependencies.cloneAsObject(),
        testerDependencies: this.testerDependencies.cloneAsObject(),
        flattenedDependencies: this.flattenedDependencies.map(function (dep) {
          return dep.serialize();
        }),
        flattenedDevDependencies: this.flattenedDevDependencies.map(function (dep) {
          return dep.serialize();
        }),
        flattenedCompilerDependencies: this.flattenedCompilerDependencies.map(function (dep) {
          return dep.serialize();
        }),
        flattenedTesterDependencies: this.flattenedTesterDependencies.map(function (dep) {
          return dep.serialize();
        }),
        packageDependencies: this.packageDependencies,
        devPackageDependencies: this.devPackageDependencies,
        peerPackageDependencies: this.peerPackageDependencies,
        compilerPackageDependencies: this.compilerPackageDependencies,
        testerPackageDependencies: this.testerPackageDependencies,
        customResolvedPaths: this.customResolvedPaths
      }, function (val) {
        return !!val;
      });
    }
  }, {
    key: 'validateBeforePersisting',
    value: function validateBeforePersisting(versionStr) {
      (_logger || _load_logger()).default.debug('validating version object: ', this.hash().hash);
      var version = Version.parse(versionStr);
      version.validate();
    }
  }, {
    key: 'toBuffer',
    value: function toBuffer(pretty) {
      var obj = this.toObject();
      var args = (0, (_utils || _load_utils()).getStringifyArgs)(pretty);
      var str = JSON.stringify.apply(JSON, [obj].concat(_toConsumableArray(args)));
      if (this.validateBeforePersist) this.validateBeforePersisting(str);
      return (0, (_utils || _load_utils()).bufferFrom)(str);
    }

    /**
     * used by the super class BitObject
     */

  }, {
    key: 'setSpecsResults',
    value: function setSpecsResults(specsResults) {
      this.specsResults = specsResults;
    }
  }, {
    key: 'setDist',
    value: function setDist(dist) {
      this.dist = dist ? {
        file: dist.hash(),
        name: (_constants || _load_constants()).DEFAULT_BUNDLE_FILENAME
      } : null;
    }
  }, {
    key: 'setCIProps',
    value: function setCIProps(ci) {
      this.ci = ci;
    }
  }, {
    key: 'modelFilesToSourceFiles',
    value: function modelFilesToSourceFiles(repository) {
      return Promise.all(this.files.map(function (file) {
        return (_sources || _load_sources()).SourceFile.loadFromSourceFileModel(file, repository);
      }));
    }
    /**
     * Validate the version model properties, to make sure we are not inserting something
     * in the wrong format
     */

  }, {
    key: 'validate',
    value: function validate() {
      (0, (_versionValidator || _load_versionValidator()).default)(this);
    }
  }], [{
    key: 'parse',
    value: function parse(contents) {
      var _JSON$parse = JSON.parse(contents),
          mainFile = _JSON$parse.mainFile,
          dists = _JSON$parse.dists,
          files = _JSON$parse.files,
          compiler = _JSON$parse.compiler,
          bindingPrefix = _JSON$parse.bindingPrefix,
          tester = _JSON$parse.tester,
          detachedCompiler = _JSON$parse.detachedCompiler,
          detachedTester = _JSON$parse.detachedTester,
          log = _JSON$parse.log,
          docs = _JSON$parse.docs,
          ci = _JSON$parse.ci,
          specsResults = _JSON$parse.specsResults,
          dependencies = _JSON$parse.dependencies,
          devDependencies = _JSON$parse.devDependencies,
          compilerDependencies = _JSON$parse.compilerDependencies,
          testerDependencies = _JSON$parse.testerDependencies,
          flattenedDependencies = _JSON$parse.flattenedDependencies,
          flattenedDevDependencies = _JSON$parse.flattenedDevDependencies,
          flattenedCompilerDependencies = _JSON$parse.flattenedCompilerDependencies,
          flattenedTesterDependencies = _JSON$parse.flattenedTesterDependencies,
          devPackageDependencies = _JSON$parse.devPackageDependencies,
          peerPackageDependencies = _JSON$parse.peerPackageDependencies,
          compilerPackageDependencies = _JSON$parse.compilerPackageDependencies,
          testerPackageDependencies = _JSON$parse.testerPackageDependencies,
          packageDependencies = _JSON$parse.packageDependencies,
          customResolvedPaths = _JSON$parse.customResolvedPaths;

      var _getDependencies = function _getDependencies() {
        var deps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

        if (deps.length && (_ramda || _load_ramda()).default.is(String, (0, (_utils || _load_utils()).first)(deps))) {
          // backward compatibility
          return deps.map(function (dependency) {
            return { id: (_bitId || _load_bitId()).BitId.parseObsolete(dependency) };
          });
        }

        var getRelativePath = function getRelativePath(relativePath) {
          if (relativePath.importSpecifiers) {
            // backward compatibility. Before the massive validation was added, an item of
            // relativePath.importSpecifiers array could be missing the mainFile property, which is
            // an invalid ImportSpecifier. (instead the mainFile it had another importSpecifiers object).
            relativePath.importSpecifiers = relativePath.importSpecifiers.filter(function (importSpecifier) {
              return importSpecifier.mainFile;
            });
            if (!relativePath.importSpecifiers.length) delete relativePath.importSpecifiers;
          }

          return relativePath;
        };

        return deps.map(function (dependency) {
          return {
            id: (_bitId || _load_bitId()).BitId.parseBackwardCompatible(dependency.id),
            relativePaths: Array.isArray(dependency.relativePaths) ? dependency.relativePaths.map(getRelativePath) : dependency.relativePaths
          };
        });
      };

      var _getFlattenedDependencies = function _getFlattenedDependencies() {
        var deps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

        return (_bitId || _load_bitId()).BitIds.fromArray(deps.map(function (dep) {
          return (_bitId || _load_bitId()).BitId.parseBackwardCompatible(dep);
        }));
      };

      var parseFile = function parseFile(file) {
        return {
          file: (_objects || _load_objects()).Ref.from(file.file),
          relativePath: file.relativePath,
          name: file.name,
          test: file.test
        };
      };

      return new Version({
        mainFile,
        files: files ? files.map(parseFile) : null,
        dists: dists ? dists.map(parseFile) : null,
        compiler: compiler ? parseEnv(compiler) : null,
        bindingPrefix: bindingPrefix || null,
        tester: tester ? parseEnv(tester) : null,
        detachedCompiler,
        detachedTester,
        log: {
          message: log.message,
          date: log.date,
          username: log.username,
          email: log.email
        },
        ci,
        specsResults,
        docs,
        dependencies: _getDependencies(dependencies),
        devDependencies: _getDependencies(devDependencies),
        compilerDependencies: _getDependencies(compilerDependencies),
        testerDependencies: _getDependencies(testerDependencies),
        flattenedDependencies: _getFlattenedDependencies(flattenedDependencies),
        flattenedDevDependencies: _getFlattenedDependencies(flattenedDevDependencies),
        flattenedCompilerDependencies: _getFlattenedDependencies(flattenedCompilerDependencies),
        flattenedTesterDependencies: _getFlattenedDependencies(flattenedTesterDependencies),
        devPackageDependencies,
        peerPackageDependencies,
        compilerPackageDependencies,
        testerPackageDependencies,
        packageDependencies,
        customResolvedPaths
      });
    }

    /**
     * used by raw-object.toRealObject()
     */

  }, {
    key: 'from',
    value: function from(versionProps) {
      return Version.parse(JSON.stringify(versionProps));
    }

    /**
     * Create version model object from consumer component
     * @param {*} param0
     */

  }, {
    key: 'fromComponent',
    value: function fromComponent(_ref) {
      var component = _ref.component,
          versionFromModel = _ref.versionFromModel,
          files = _ref.files,
          dists = _ref.dists,
          flattenedDependencies = _ref.flattenedDependencies,
          flattenedDevDependencies = _ref.flattenedDevDependencies,
          flattenedCompilerDependencies = _ref.flattenedCompilerDependencies,
          flattenedTesterDependencies = _ref.flattenedTesterDependencies,
          message = _ref.message,
          specsResults = _ref.specsResults,
          username = _ref.username,
          email = _ref.email;

      var parseFile = function parseFile(file) {
        return {
          file: file.file.hash(),
          relativePath: file.relativePath,
          name: file.name,
          test: file.test
        };
      };

      /**
       * Get to envs models and check if they are different
       * @param {*} envModelFromFs
       * @param {*} envModelFromModel
       */
      var areEnvsDifferent = function areEnvsDifferent(envModelFromFs, envModelFromModel) {
        var sortEnv = function sortEnv(env) {
          env.files = (_ramda || _load_ramda()).default.sortBy((_ramda || _load_ramda()).default.prop('name'), env.files);
          env.config = (0, (_utils || _load_utils()).sortObject)(env.config);
          var result = (0, (_utils || _load_utils()).sortObject)(env);
          return result;
        };
        var stringifyEnv = function stringifyEnv(env) {
          if (!env) {
            return '';
          }
          if (typeof env === 'string') {
            return env;
          }
          return JSON.stringify(sortEnv(env));
        };
        var envModelFromFsString = stringifyEnv(envModelFromFs);
        var envModelFromModelString = stringifyEnv(envModelFromModel);
        return (0, (_utils || _load_utils()).sha1)(envModelFromFsString) !== (0, (_utils || _load_utils()).sha1)(envModelFromModelString);
      };

      /**
       * Calculate the detach status based on the component origin, the component detach status from bitmap and comparison
       * between the env in fs and the env in models
       * @param {*} origin
       * @param {*} detachFromFs
       * @param {*} envModelFromFs
       * @param {*} envModelFromModel
       */
      var calculateDetach = function calculateDetach(origin, detachFromFs, envModelFromFs, envModelFromModel) {
        // In case it's already detached keep the state as is
        if (detachFromFs) return detachFromFs;
        // In case i'm the author and it's not already detached it can't be changed here
        if (origin === (_constants || _load_constants()).COMPONENT_ORIGINS.AUTHORED) return undefined;
        var envDiff = areEnvsDifferent(envModelFromFs, envModelFromModel);
        if (!envDiff) return undefined;
        return true;
      };

      var compiler = component.compiler ? component.compiler.toModelObject() : undefined;
      var tester = component.tester ? component.tester.toModelObject() : undefined;

      var compilerDynamicPakageDependencies = component.compiler ? component.compiler.dynamicPackageDependencies : undefined;
      var testerDynamicPakageDependencies = component.tester ? component.tester.dynamicPackageDependencies : undefined;
      var detachedCompiler = void 0;
      var detachedTester = void 0;
      var compilerFromModel = (_ramda || _load_ramda()).default.path(['compiler'], versionFromModel);
      var testerFromModel = (_ramda || _load_ramda()).default.path(['tester'], versionFromModel);
      if (compiler) {
        detachedCompiler = calculateDetach(component.origin, component.detachedCompiler, getEnvModelOrName(compiler), compilerFromModel);
        if (detachedCompiler) {
          // Save it on the component for future use
          component.detachedCompiler = detachedCompiler;
        }
      }
      if (tester) {
        detachedTester = calculateDetach(component.origin, component.detachedTester, getEnvModelOrName(tester), testerFromModel);
        if (detachedTester) {
          // Save it on the component for future use
          component.detachedTester = detachedTester;
        }
      }

      return new Version({
        mainFile: component.mainFile,
        files: files.map(parseFile),
        dists: dists ? dists.map(parseFile) : null,
        compiler,
        bindingPrefix: component.bindingPrefix,
        tester,
        detachedCompiler,
        detachedTester,
        log: {
          message,
          username,
          email,
          date: Date.now().toString()
        },
        specsResults,
        docs: component.docs,
        dependencies: component.dependencies.get(),
        devDependencies: component.devDependencies.get(),
        compilerDependencies: component.compilerDependencies.get(),
        testerDependencies: component.testerDependencies.get(),
        packageDependencies: component.packageDependencies,
        devPackageDependencies: component.devPackageDependencies,
        peerPackageDependencies: component.peerPackageDependencies,
        compilerPackageDependencies: _extends({}, component.compilerPackageDependencies, compilerDynamicPakageDependencies),
        testerPackageDependencies: _extends({}, component.testerPackageDependencies, testerDynamicPakageDependencies),
        flattenedDependencies,
        flattenedDevDependencies,
        flattenedCompilerDependencies,
        flattenedTesterDependencies,
        customResolvedPaths: component.customResolvedPaths
      });
    }
  }]);

  return Version;
}((_objects || _load_objects()).BitObject);

exports.default = Version;


var parseEnv = function parseEnv(env) {
  if (typeof env === 'string') {
    return env;
  }
  // Store the env as string in case there is no config and files (for backward compatibility)
  if (envNameOnly(env)) {
    return env.name;
  }
  return {
    name: env.name,
    config: env.config,
    files: env.files ? env.files.map((_extensionFile || _load_extensionFile()).default.fromObjectToModelObject) : []
  };
};

var envNameOnly = function envNameOnly(env) {
  if ((!env.config || (_ramda || _load_ramda()).default.isEmpty(env.config)) && (!env.files || (_ramda || _load_ramda()).default.isEmpty(env.files))) {
    return true;
  }
  return false;
};

var getEnvModelOrName = function getEnvModelOrName(env) {
  if (typeof env === 'string') {
    return env;
  }
  // Store the env as string in case there is no config and files (for backward compatibility)
  if (envNameOnly(env)) {
    return env.name;
  }
  return env;
};