"use strict";

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

var _applyValuesToShema = require("./applyValuesToShema");

var _cliArgsToObject = require("./cliArgsToObject");

var _defaultConfigValues = _interopRequireDefault(require("./defaultConfigValues"));

var _deprecatedOptionsHandler = require("./deprecatedOptionsHandler");

var _getCWD = require("./getCWD");

var _getNpmVersion = require("./getNpmVersion");

var _npmConfigToObject = require("./npmConfigToObject");

var _readOptionsForPackageJson = require("./readOptionsForPackageJson");

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

// import schemas from './oldDefaultConfigValues';
const args = process.argv.slice(2);
exports.args = args;
const processEnv = (0, _npmConfigToObject.npmConfigToObject)();
const cliArgsObject = (0, _cliArgsToObject.cliArgsToObject)(args);
Object.assign(processEnv, cliArgsObject);
global.reactCLIOptions = null;

const getOptions = () => {
  if (global.reactCLIOptions) {
    return global.reactCLIOptions;
  }

  const appPath = process.cwd();
  const userSchemas = (0, _readOptionsForPackageJson.readOptionsForPackageJson)(appPath);
  const options = (0, _applyValuesToShema.applyValuesToShema)(_defaultConfigValues.default, userSchemas || {}, processEnv);
  (0, _deprecatedOptionsHandler.deprecatedOptionsHandler)(options); // for future may be for npm 8 edge cases

  options.npmVersion = (0, _getNpmVersion.getNpmVersion)();
  options.cwd = (0, _getCWD.getCWD)();
  options.packageVersion = process.env.npm_package_version;
  options.extraArgs = process.argv.slice(3); // eslint-disable-next-line prefer-destructuring

  options.commandOption = process.argv[2];
  global.reactCLIOptions = options; // console.log({ options });

  return options;
};

exports.getOptions = getOptions;