'use strict';

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

var envVariable_envVariable = require('../env-variable/env-variable.js');
var nodejs_fs = require('../nodejs/fs.js');
var nodejs_path = require('../nodejs/path.js');

function getPublishRootDir() {
  var rootDir = process.cwd();
  return rootDir;
}
function findPublishSh(dir) {
  var FILE_NAME = 'publish.sh';
  var file = nodejs_path.getPath().resolve(dir, FILE_NAME);
  if (nodejs_fs.getFs().existsSync(file)) {
    return file;
  }
}
function getPublishBashPath() {
  return findPublishSh(nodejs_path.getPath().resolve(__dirname, '..')) || findPublishSh(nodejs_path.getPath().resolve(__dirname, '../bin')) || findPublishSh(nodejs_path.getPath().resolve(__dirname, '../../bin')) || 'ERROR_FILE';
}
function getPublishEnvValue(key) {
  var rootDir = getPublishRootDir();
  var localEnvPath = nodejs_path.getPath().join(rootDir, '.env.local');
  var envPath = nodejs_path.getPath().join(rootDir, '.env');
  var envValue = envVariable_envVariable.readEnvVariable(key, envPath);
  var localEnvValue = envVariable_envVariable.readEnvVariable(key, localEnvPath);
  return localEnvValue || envValue || '';
}
function getPublishModuleName() {
  var dir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  return dir.split('/')[1] || '';
}

exports.getPublishBashPath = getPublishBashPath;
exports.getPublishEnvValue = getPublishEnvValue;
exports.getPublishModuleName = getPublishModuleName;
exports.getPublishRootDir = getPublishRootDir;
