const path = require('path');
const generators = require('../../lib/generators');
const config = require('../../lib/config');
const utils = require('../../lib/utils');

// fetching cli arguments
const args = utils.getArgs();

// Print header and version
utils.logBigTitle('eUI CLI');
utils.logAccent(` --- v${config.version} ---\n`);

// remapping config if passed as argument - automated mode
let inputConfig = config.parseInputConfig(args.config);

// Detecting targetPath and create it if present as argument - local and automated mode
let targetPath;

if (args.targetPath) {
  targetPath = path.join(config.targetPath, args.targetPath);

  if (!utils.isDirExists(targetPath)) {
    utils.mkdir(targetPath);
  }

// otherwise taking the default config targetPath defined
} else {
  targetPath = config.targetPath;
}

if (args.v) {
  console.info('Current eUI CLI version installed : ' + config.version);

} else {
  return generators.appGenerate({
    inputConfig: inputConfig,
    targetPath: targetPath
  });
}