"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.exit = exports.validateUserConfig = exports.validateSeederTemplatePath = exports.validateSeedersFolderName = exports.getObjectWithSelectedKeys = exports.getFolderNameFromPath = exports.normalizeSeederFileName = exports.normalizeSeederName = void 0;

var _lodash = require("lodash");

var _config = _interopRequireDefault(require("../config"));

var _constants = require("./constants");

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

var normalizeSeederName = function normalizeSeederName(name) {
  return (0, _lodash.upperFirst)((0, _lodash.camelCase)(name));
};

exports.normalizeSeederName = normalizeSeederName;

var normalizeSeederFileName = function normalizeSeederFileName(name) {
  return "".concat((0, _lodash.kebabCase)(name), ".seeder.js");
};

exports.normalizeSeederFileName = normalizeSeederFileName;

var getFolderNameFromPath = function getFolderNameFromPath(path) {
  return path.substring(path.lastIndexOf('/') + 1);
};

exports.getFolderNameFromPath = getFolderNameFromPath;

var getObjectWithSelectedKeys = function getObjectWithSelectedKeys(obj, keys) {
  var newObj = {};
  Object.keys(obj).forEach(function (k) {
    if (keys.includes(k)) {
      newObj[k] = obj[k];
    }
  });
  return newObj;
};

exports.getObjectWithSelectedKeys = getObjectWithSelectedKeys;

var validateSeedersFolderName = function validateSeedersFolderName(name) {
  return typeof name === 'string' && (0, _lodash.trim)(name).length >= 3;
};

exports.validateSeedersFolderName = validateSeedersFolderName;

var validateSeederTemplatePath = function validateSeederTemplatePath(name) {
  return typeof name === 'string' && (0, _lodash.trim)(name).length >= 6;
};

exports.validateSeederTemplatePath = validateSeederTemplatePath;

var validateUserConfig = function validateUserConfig() {
  var userConfigExists = _config["default"].userConfigExists;

  if (!userConfigExists) {
    throw new Error('Must contain md-seed-config.js at the project root. run `md-seed init` to create the config file.');
  }
};

exports.validateUserConfig = validateUserConfig;

var exit = function exit(error) {
  if (error && error.message && error.message !== 'exit') {
    console.error(error);
    process.exit(_constants.ExitCodes.Error);
  } else {
    process.exit(_constants.ExitCodes.Success);
  }
};

exports.exit = exit;