"use strict";

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

var _logger = require("../logger");

const NPM_CONFIG_PREFIX = 'npm_config_'; // TODO: we have to do option parse logic little better
// if user use react-cli strictly without using npm scripts options won't work,
//  So  we have to write our own option parse logic or some other library
// console.log('type', process.argv,  process.env.npm_config_check,  process.env.npm_config_clone_type, process.env.npm_config_clone_url);
// console.log('Object.keys(process.env).filter(s => s.startsWith(\'npm_config_\') && s.includes(\'clone\')', Object.keys(process.env).filter(s => s.startsWith('npm_config_') && s.includes('clone')));

function npmConfigToObject() {
  // // clone:type
  const processEnv = {};
  const keysWithColon = [];
  Object.keys(process.env).filter(key => key.startsWith(NPM_CONFIG_PREFIX)).forEach(key => {
    const nKey = key.slice(NPM_CONFIG_PREFIX.length);
    processEnv[nKey] = process.env[key];
    nKey.includes(':') && keysWithColon.push(nKey);
  });
  keysWithColon.forEach(key => {
    const nKey = key.replace(/:/g, '_');

    if (processEnv[nKey]) {
      (0, _logger.warnLogger)('there is some options conflict', key, nKey);
    }

    processEnv[nKey] = processEnv[key];
  });
  return processEnv;
}