"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.npmConfigToObject = npmConfigToObject;
const NPM_CONFIG_PREFIX = 'npm_config_'; // TODO: we have to do option parse logic little better
// if user use react-cli stritly 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 = {};
  let keysWithColon = [];
  Object.keys(process.env).filter(key => key.startsWith(NPM_CONFIG_PREFIX)).forEach(key => {
    let nkey = key.slice(NPM_CONFIG_PREFIX.length);
    processEnv[nkey] = process.env[key];
    nkey.includes(':') && keysWithColon.push(nkey);
  });
  keysWithColon.forEach(key => {
    let nkey = key.replace(/:/g, '_');

    if (processEnv[nkey]) {
      console.warn('there is some options conflict', key, nkey);
    }

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