<commit_before>#!/usr/bin/env node
'use strict';

const Chalk = require('chalk');
const inquirer = require('inquirer');
const log = console.log;
const Constants = require('../utils/constants');
const fs = require('fs-extra');

// Main code //
const self = module.exports = {
  init: (input, flags) => {
    inquirer.prompt(Constants.CREATE_QUESTIONS)
      .then(answers => {
        const result = self.getFormatedResult(answers);
        const path = `${Constants.HIVE_LIBS_DIR}/${answers.name.toLowerCase()}`

        log('Instructions:\n')
        log(Chalk.green(`mkdir -p ${path}`))
        log(`info.json`)
        
        const infoContent = JSON.stringify(result, null, '  ');

        self.createFileIn(`${path}`, infoContent)

        self.createPullRequest(result);
    });
  },
  createPullRequest:(result => { 
    // TODO
    // log(`I have no idea how to create a PR`);
  }),
  createFileIn:((destination, content) => {
    fs.ensureDirSync(destination);
    const destinationFile = destination + `/info.json`;

    var options = { flag: 'w' };

    // Write the info.json file
    fs.writeFile(destinationFile, content, options, err => {
      if (err) {
        return log(err);
      }

      log(Chalk.green(content));

      log("The file was saved in " + destinationFile);
    }); 
  }),
  getFormatedResult:(answers => {
    let result = {};

    result.name = answers.name;

    if (answers.description !== '') {
      result.description = answers.description;
    }
    if (answers.homepage !== '') {
      result.homepage = answers.homepage;
    }
    result.dependency = answers.dependency;
    result.compileType = answers.compileType;

    result.repository = {};
    result.repository.server = answers.server;

    if (answers.customRepository !== '') {
      result.repository.url = answers.customRepository;
    }

    return result;
  })
};<commit_msg>small refactor<commit_after>#!/usr/bin/env node
'use strict';

const Chalk = require('chalk');
const inquirer = require('inquirer');
const log = console.log;
const Constants = require('../utils/constants');
const fs = require('fs-extra');

// Main code //
const self = module.exports = {
  init: (input, flags) => {
    inquirer.prompt(Constants.CREATE_QUESTIONS)
      .then(answers => {
        const result = self.getFormatedResult(answers);
        const path = `${Constants.HIVE_LIBS_DIR}/${answers.name.toLowerCase()}`

        log('Instructions:\n')
        log(Chalk.green(`mkdir -p ${path}`))
        log(`info.json`)
        
        const infoContent = JSON.stringify(result, null, '  ');

        self.createFileIn(`${path}`, infoContent)

        self.createPullRequest(result);
    });
  },
  createPullRequest:(result => { 
    // TODO
    // log(`I have no idea how to create a PR`);
  }),
  createFileIn:((destination, content) => {
    fs.ensureDirSync(destination);
    const destinationFile = destination + `/info.json`;

    var options = { flag: 'w' };

    // Write the info.json file
    fs.writeFile(destinationFile, content, options, err => {
      if (err) {
        return log(err);
      }

      log(Chalk.green(content));

      log("The file was saved in " + destinationFile);
    }); 
  }),
  getFormatedResult:(answers => {
    let result = {};

    result.name = answers.name;

    if (answers.description !== '') {
      result.description = answers.description;
    }
    if (answers.homepage !== '') {
      result.homepage = answers.homepage;
    }
    
    result.dependencies = [{
      dependency: answers.dependency,
      compileType: answers.compileType
    }];

    result.repository = {};
    result.repository.server = answers.server;

    if (answers.customRepository !== '') {
      result.repository.url = answers.customRepository;
    }

    return result;
  })
};
{'fraction_non_alphanumeric': 0.1557075223566544, 'fraction_numerical': 0.0, 'mean_word_length': 2.750493096646943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '70113', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1140, 'n_words': 230}