const path = require('path');

const skeletonsPath = path.join(__dirname, 'skeletons');
const version = require(path.join(__dirname, '../package.json')).version;

module.exports.targetPath = path.resolve(process.cwd());
module.exports.skeletonsPath = skeletonsPath;

module.exports.angularBasePath = path.join(skeletonsPath, '_angular/base');
module.exports.angularBaseMobilePath = path.join(skeletonsPath, '_angular/base-mobile');

module.exports.webMavenPath = path.join(skeletonsPath, 'web-maven');
module.exports.webSpringBootPath = path.join(skeletonsPath, 'web-spring-boot');

module.exports.webPhpStarterRepo = 'webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-php-starter.git'
module.exports.webSymfonyPath = path.join(skeletonsPath, 'web-symfony');

module.exports.optionsPath = {
    "ecl-ec": path.join(skeletonsPath, '_angular/options/ecl-ec'),
    "ecl-eu": path.join(skeletonsPath, '_angular/options/ecl-eu'),
};

module.exports.version = version;

// f.e. :
//  eui-cli --config appType:angular,npmInstall:false --targetPath eui-angular
//  eui-cli --config appType:angular,appOptions:ecl,npmInstall:false --targetPath eui-angular-ecl-ec

module.exports.parseInputConfig = (inputConfig) => {

  if (!inputConfig) {
    return;
  }

  const configArray = inputConfig.split(',').map(item => {
    const x = item.split(':');

    const propName = x[0];
    let value = x[1];

    // treating text to boolean values : f.e. : npmInstall=true
    if (value === 'true') {
      value = true;
    }
    if (value === 'false') {
      value = false;
    }

    // treating string array values : f.e. : appOptions=ecl_something
    if (propName === 'appOptions') {
      value = value.split('_');
    }

    return { [propName]: value };
  });

  return Object.assign({}, ...configArray);
}
