<commit_before>import { spawn } from 'child_process'
import prompt from 'prompt'
import chalk from 'chalk'
import path from 'path'
import _ from 'lodash'
import fs from 'fs'
import util from '../util'
import stats from '../stats'

const introductionText = "\nHey there, thanks for using botpress!" +
  "\nWe'll walk you through the creation of your new bot." +
  "\nFor more information or help, please visit http://github.com/botpress/botpress"
  + "\n---------------"

const waitingText = 'please wait, we are installing everything for you...'
const nextStepText = 'now run ' + chalk.bold('`bp start`') + ' in your terminal'

const assertDoesntExist = (file) => {
  if (fs.existsSync(file)) {
    util.print('error', 'package.json or botfile.js are already in repository, ' +
      'remove them before running this command again.')
    process.exit(1)
  }
}

const getTemplate = (template) => {
  const templatePath = path.join(__dirname, 'templates/init', template)
  const templateContent = fs.readFileSync(templatePath)
  return _.template(templateContent)
}

const generateTemplate = (filename, variables = {}) => {
  const template = getTemplate(filename)
  const compiled = template(variables)
  const destination = path.join(filename.replace(/_\._/, '.'))
  fs.writeFileSync(destination, compiled)
}

const generate = (result) => {
  generateTemplate('package.json', result)
  generateTemplate('LICENSE')
  generateTemplate('botfile.js')
  generateTemplate('index.js')
  generateTemplate('_._gitignore')
  generateTemplate('_._welcome')
  generateTemplate('theme.scss')

  fs.mkdirSync('data')
  fs.writeFileSync('data/bot.log', '')
  fs.writeFileSync('data/notification.json', '[]')

  fs.mkdirSync('modules_config')

  util.print(waitingText)
  const install = spawn(util.npmCmd, ['install'])

  install.stdout.on('data', (data) => {
    process.stdout.write(data.toString())
  })

  install.stderr.on('data', (data) => {
    process.stdout.write(data.toString())
  })

  install.on('close', (code) => {
    if (code > 0) {
      util.print('error', 'an error occured during installation')
    } else {
      util.print('success', 'installation has completed successfully')
      util.print(nextStepText)
    }
  })
}

module.exports = function(program) {
  var dirName = process.argv[3];
  if(dirName != undefined){
    if (!fs.existsSync(dirName)){
          fs.mkdirSync(dirName);
          process.chdir(dirName);
    }else{
      util.print('error',dirName + " directory already exists");
      return;
    }
  }
  stats({}).track('cli', 'bot', 'init')

  util.print(introductionText)

  _.each(['package.json', 'botfile.js', 'index.js'], assertDoesntExist)

  const currentDirectoryName = path.basename(path.resolve('./'))

  var schema = {
    properties: {
      name: {
        description: chalk.white('name:'),
        pattern: /^[a-z0-9][a-z0-9-_\.]+$/,
        message: 'name must be only lowercase letters, ' +
          'digits, dashes, underscores and dots.',
        required: true,
        default: currentDirectoryName
      },
      description: {
        required: false,
        description: chalk.white('description:')
      },
      author: {
        required: false,
        description: chalk.white('author:')
      },
      version: {
        required: false,
        description: chalk.white('version:'),
        default: '0.0.1'
      },
    }
  }

  if (program.yes) {
    generate({
      name: currentDirectoryName,
      description: '',
      author: '',
      version: '0.0.1'
    })
  } else {
    prompt.message = ''
    prompt.delimiter = ''
    prompt.start()
    prompt.get(schema, function (err, result) {
      generate(result)
    })
  }
}<commit_msg>Update Code Style<commit_after>import { spawn } from 'child_process'
import prompt from 'prompt'
import chalk from 'chalk'
import path from 'path'
import _ from 'lodash'
import fs from 'fs'
import util from '../util'
import stats from '../stats'

const introductionText = "\nHey there, thanks for using botpress!" +
  "\nWe'll walk you through the creation of your new bot." +
  "\nFor more information or help, please visit http://github.com/botpress/botpress" + "\n---------------"

const waitingText = 'please wait, we are installing everything for you...'
const nextStepText = 'now run ' + chalk.bold('`bp start`') + ' in your terminal'

const assertDoesntExist = (file) => {
  if (fs.existsSync(file)) {
    util.print('error', 'package.json or botfile.js are already in repository, ' +
      'remove them before running this command again.')
    process.exit(1)
  }
}

const getTemplate = (template) => {
  const templatePath = path.join(__dirname, 'templates/init', template)
  const templateContent = fs.readFileSync(templatePath)
  return _.template(templateContent)
}

const generateTemplate = (filename, variables = {}) => {
  const template = getTemplate(filename)
  const compiled = template(variables)
  const destination = path.join(filename.replace(/_\._/, '.'))
  fs.writeFileSync(destination, compiled)
}

const generate = (result) => {
  generateTemplate('package.json', result)
  generateTemplate('LICENSE')
  generateTemplate('botfile.js')
  generateTemplate('index.js')
  generateTemplate('_._gitignore')
  generateTemplate('_._welcome')
  generateTemplate('theme.scss')

  fs.mkdirSync('data')
  fs.writeFileSync('data/bot.log', '')
  fs.writeFileSync('data/notification.json', '[]')

  fs.mkdirSync('modules_config')

  util.print(waitingText)
  const install = spawn(util.npmCmd, ['install'])

  install.stdout.on('data', (data) => {
    process.stdout.write(data.toString())
  })

  install.stderr.on('data', (data) => {
    process.stdout.write(data.toString())
  })

  install.on('close', (code) => {
    if (code > 0) {
      util.print('error', 'an error occured during installation')
    } else {
      util.print('success', 'installation has completed successfully')
      util.print(nextStepText)
    }
  })
}

module.exports = function(program) {
  var dirName = process.argv[3];
  if (dirName != undefined) {
    if (!fs.existsSync(dirName)) {
      fs.mkdirSync(dirName);
      process.chdir(dirName);
    } else {
      util.print('error', dirName + " directory already exists");
      return;
    }
  }
  stats({}).track('cli', 'bot', 'init')

  util.print(introductionText)

  _.each(['package.json', 'botfile.js', 'index.js'], assertDoesntExist)

  const currentDirectoryName = path.basename(path.resolve('./'))

  var schema = {
    properties: {
      name: {
        description: chalk.white('name:'),
        pattern: /^[a-z0-9][a-z0-9-_\.]+$/,
        message: 'name must be only lowercase letters, ' +
          'digits, dashes, underscores and dots.',
        required: true,
        default: currentDirectoryName
      },
      description: {
        required: false,
        description: chalk.white('description:')
      },
      author: {
        required: false,
        description: chalk.white('author:')
      },
      version: {
        required: false,
        description: chalk.white('version:'),
        default: '0.0.1'
      },
    }
  }

  if (program.yes) {
    generate({
      name: currentDirectoryName,
      description: '',
      author: '',
      version: '0.0.1'
    })
  } else {
    prompt.message = ''
    prompt.delimiter = ''
    prompt.start()
    prompt.get(schema, function(err, result) {
      generate(result)
    })
  }
}
{'fraction_non_alphanumeric': 0.15656633823727897, 'fraction_numerical': 0.0035092455122148736, 'mean_word_length': 3.148936170212766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7412583', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2231, 'n_words': 517}