"use strict";

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

var _os = require("os");

var _fs = require("fs");

var _path = require("path");

const appPath = process.cwd();
const isNodeModuleUnderAppFolder = __dirname.indexOf(appPath) !== -1;
const isWindows = (0, _os.platform)().toLowerCase() === 'win32';
const suffixExt = isWindows ? '.cmd' : ''; // function searchForCommandPath(commandName) {
//   let pathFolders = __dirname.split(sep);
//   let cliPath;
//   while (pathFolders.pop()) {
//     cliPath = join(pathFolders.join(sep), 'node_modules', '.bin', commandName);
//     if (existsSync(cliPath)) {
//       return cliPath;
//     }
//   }
//   console.warn(`unable to find command "${commandName}"`);
//   return join(__dirname, '..', 'node_modules', '.bin', commandName);
// }

function searchForCommandPath(libName) {
  const commandPath = (0, _path.join)(__dirname, '..', '..', '..', 'node_modules', '.bin', libName); // TODO: need to check for windows machine reason command with ext added,
  //  when we  use  global react-cli package (executable) working or not 

  return (0, _fs.existsSync)(commandPath) ? commandPath : libName;
}

const getCliPath = !isNodeModuleUnderAppFolder ? commandName => searchForCommandPath(commandName + suffixExt) : commandName => commandName + suffixExt;
exports.getCliPath = getCliPath;