<commit_before>'use strict';

const inquirer = require('inquirer');
const ora = require('ora');
const fs = require('fs');
const chalk = require('chalk');
const path = require('path');
const validFilename = require('valid-filename');
const spawn = require('child_process').spawn;
const compilerMap = require('./compilerMap');
const dotPingyTmpl = require('./dotPingyTmpl');

const createChoices = (type) => [
  type,
  ...compilerMap[type].map(x => x.name)
]

const nameToModule = (type, prettyName) =>
    (compilerMap[type].find(x => x.name === prettyName) || {}).module;

const stage1 = [
  {
    type: 'list',
    name: 'html',
    message: 'What document format do you wish to use',
    choices: createChoices('HTML'),
  }, {
    type: 'list',
    name: 'styles',
    message: 'What styles format do you wish to use',
    choices: createChoices('CSS'),
  }, {
    type: 'list',
    name: 'scripts',
    message: 'What scripts format do you wish to use',
    choices: createChoices('JS'),
  }, {
    type: 'input',
    name: 'exportDir',
    message: 'Choose the folder name to export compiled files to',
    default: 'dist',
    validate: (input) => {
      if (!validFilename(input)) return 'Invalid folder name';
      return true;
    }
  },
];



function prepare() {
  inquirer.prompt(stage1).then((answers) => {
    const modules = {
      html: nameToModule('HTML', answers.html),
      css: nameToModule('CSS', answers.styles),
      js: nameToModule('JS', answers.scripts),
    }
    // TODO: add '@pingy/cli' below
    const deps = [modules.html, modules.css, modules.js].filter(x => !!x);

    const pkgJsonPath = path.join(process.cwd(), 'package.json')
    const pkgJsonExists = fs.existsSync(pkgJsonPath);

    if (!pkgJsonExists) {
      const npmInit = spawn('npm', ['init'], { stdio: 'inherit' });
      npmInit.on('exit', (code) => {
        if (code === 0) {
          updatePkgScripts(pkgJsonPath, answers);
          installDeps(deps);
        }
        else ora().fail(`npm init failed with code: ${code}`);
      });
    } else {
      updatePkgScripts(pkgJsonPath, answers);
      installDeps(deps)
    }
  });
}

function installDeps(deps) {
  if (deps.length === 0) {
    console.log(`\nNo dependencies needed. ${chalk.green('Done!')}`);
    return;
  }
  console.log('\nReady to install dependencies.');
  console.log('\nCommand that will now be run:');
  console.log(
    '  > ' + chalk.bold.underline(`npm install --save-dev ${deps.join(' ')}\n`)
  );
<commit_msg>add @pingy/cli to deps for install<commit_after>'use strict';

const inquirer = require('inquirer');
const ora = require('ora');
const fs = require('fs');
const chalk = require('chalk');
const path = require('path');
const validFilename = require('valid-filename');
const spawn = require('child_process').spawn;
const compilerMap = require('./compilerMap');
const dotPingyTmpl = require('./dotPingyTmpl');

const createChoices = (type) => [
  type,
  ...compilerMap[type].map(x => x.name)
]

const nameToModule = (type, prettyName) =>
    (compilerMap[type].find(x => x.name === prettyName) || {}).module;

const stage1 = [
  {
    type: 'list',
    name: 'html',
    message: 'What document format do you wish to use',
    choices: createChoices('HTML'),
  }, {
    type: 'list',
    name: 'styles',
    message: 'What styles format do you wish to use',
    choices: createChoices('CSS'),
  }, {
    type: 'list',
    name: 'scripts',
    message: 'What scripts format do you wish to use',
    choices: createChoices('JS'),
  }, {
    type: 'input',
    name: 'exportDir',
    message: 'Choose the folder name to export compiled files to',
    default: 'dist',
    validate: (input) => {
      if (!validFilename(input)) return 'Invalid folder name';
      return true;
    }
  },
];



function prepare() {
  inquirer.prompt(stage1).then((answers) => {
    const modules = {
      html: nameToModule('HTML', answers.html),
      css: nameToModule('CSS', answers.styles),
      js: nameToModule('JS', answers.scripts),
    }

    const deps = [
      '@pingy/cli', modules.html, modules.css, modules.js
    ].filter(x => !!x);

    const pkgJsonPath = path.join(process.cwd(), 'package.json')
    const pkgJsonExists = fs.existsSync(pkgJsonPath);

    if (!pkgJsonExists) {
      const npmInit = spawn('npm', ['init'], { stdio: 'inherit' });
      npmInit.on('exit', (code) => {
        if (code === 0) {
          updatePkgScripts(pkgJsonPath, answers);
          installDeps(deps);
        }
        else ora().fail(`npm init failed with code: ${code}`);
      });
    } else {
      updatePkgScripts(pkgJsonPath, answers);
      installDeps(deps)
    }
  });
}

function installDeps(deps) {
  if (deps.length === 0) {
    console.log(`\nNo dependencies needed. ${chalk.green('Done!')}`);
    return;
  }
  console.log('\nReady to install dependencies.');
  console.log('\nCommand that will now be run:');
  console.log(
    '  > ' + chalk.bold.underline(`npm install --save-dev ${deps.join(' ')}\n`)
  );

{'fraction_non_alphanumeric': 0.17379145025968837, 'fraction_numerical': 0.0015980823012385138, 'mean_word_length': 3.228885135135135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2184340', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1616, 'n_words': 403}