<commit_before>#!/usr/bin/env node

var moduleInit = require('..')
var path = require('path')
var chalk = require('chalk')
var config = require('git-config').sync()
var inquirer = require('inquirer')
var canHazPackage = require('can-haz-package')

var clopts = require('cliclopts')([
  {
    name: 'version',
    abbr: 'v',
    boolean: true,
    help: 'show version information'
  },
  {
    name: 'help',
    abbr: 'h',
    help: 'show help',
    boolean: true
  }
])
var argv = require('minimist')(process.argv.slice(2), {
  alias: clopts.alias(),
  boolean: clopts.boolean(),
  default: clopts.default()
})
var errs = 0

if (argv.version) {
  console.log(require('../package').version)
  process.exit(0)
}

if (argv.help) {
  console.log('Usage: module-init [options]')
  clopts.print()
  console.log('Run without arguments for interactive mode')
  process.exit(0)
}

if (!config.user ||
  !config.user.name) {
  console.log(chalk.red('Missing user name in .gitconfig'))
  console.log('  Please make sure your name is set, e.g.')
  console.log('  git config --global user.name "<NAME>"')
  errs++
}

if (!config.user ||
  !config.user.email) {
  console.log(chalk.red('Missing user email in .gitconfig'))
  console.log('  Please make sure your email is set, e.g.')
  console.log('  git config --global user.email "YOUR EMAIL"')
  errs++
}

if (!config.github || !config.github.user) {
  console.log(chalk.red('Missing github user in .gitconfig'))
  console.log('  Please make sure your github username is set, e.g.')
  console.log('  git config --global github.user "YOUR USERNAME"')
  errs++
}

if (errs) process.exit(1)

var questions = [{
  type: 'input',
  name: 'pkgName',
  message: 'name',
  default: path.basename(process.cwd()),
  validate: canHazPackage
},
  {
    type: 'input',
    name: 'pkgVersion',
    message: 'version',
    default: '1.0.0'
  },
  {
    type: 'input',
    name: 'pkgDescription',
    message: 'description'
  },
  {
    type: 'input',
    name: 'pkgKeywords',
    message: 'keywords'
  },
  {
    type: 'list',
    name: 'pkgLicense',
    message: 'license',
    choices: ['ISC', 'Apache-2.0'],
    default: 'ISC'
  },
  {
    type: 'confirm',
    name: 'pkgContributing',
    message: 'contributing',
    default: true
  },
  {
    type: 'list',
    name: 'pkgLinter',
    message: 'linter',
    choices: ['standard', 'semistandard'],
    default: 'standard'
  }]

inquirer.prompt(questions, function (data) {
  data.usrName = config.user.name
  data.usrEmail = config.user.email
  data.usrGithub = config.github.user

  if (!data.pkgDescription) data.pkgDescription = ''
  if (data.pkgKeywords !== '') {
    data.pkgKeywords = data.pkgKeywords
      .split(/[\s,]+/)
      .filter(function (value, index, self) {
        return !!value && self.indexOf(value) === index
      })
      .map(function (value) {
        return '"' + value + '"'
      })
      .join(', ')
  }

  moduleInit(data)
    .on('create', function (file) {
      // file created
      console.warn(chalk.green('✓ ') + chalk.bold(file) + ' created')
    })
    .on('warn', function (msg) {
      // something weird happened
      console.warn(chalk.yellow('✗ ' + msg))
    })
    .on('err', function (err) {
      // something went horribly wrong!
      console.error(err)
      process.exit(1)
    })<commit_msg>:feet: add cli option for dir<commit_after>#!/usr/bin/env node

var moduleInit = require('..')
var path = require('path')
var chalk = require('chalk')
var config = require('git-config').sync()
var inquirer = require('inquirer')
var canHazPackage = require('can-haz-package')

var clopts = require('cliclopts')([
  {
    name: 'dir',
    abbr: 'd',
    help: 'specify module directory (default: cwd)'
  },
  {
    name: 'version',
    abbr: 'v',
    boolean: true,
    help: 'show version information'
  },
  {
    name: 'help',
    abbr: 'h',
    help: 'show help',
    boolean: true
  }
])
var argv = require('minimist')(process.argv.slice(2), {
  alias: clopts.alias(),
  boolean: clopts.boolean(),
  default: clopts.default()
})
var errs = 0

if (argv.version) {
  console.log(require('../package').version)
  process.exit(0)
}

if (argv.help) {
  console.log('Usage: module-init [options]')
  clopts.print()
  process.exit(0)
}

if (!config.user ||
  !config.user.name) {
  console.log(chalk.red('Missing user name in .gitconfig'))
  console.log('  Please make sure your name is set, e.g.')
  console.log('  git config --global user.name "<NAME>"')
  errs++
}

if (!config.user ||
  !config.user.email) {
  console.log(chalk.red('Missing user email in .gitconfig'))
  console.log('  Please make sure your email is set, e.g.')
  console.log('  git config --global user.email "YOUR EMAIL"')
  errs++
}

if (!config.github || !config.github.user) {
  console.log(chalk.red('Missing github user in .gitconfig'))
  console.log('  Please make sure your github username is set, e.g.')
  console.log('  git config --global github.user "YOUR USERNAME"')
  errs++
}

if (errs) process.exit(1)

var questions = [{
  type: 'input',
  name: 'pkgName',
  message: 'name',
  default: argv.dir || path.basename(process.cwd()),
  validate: canHazPackage
},
  {
    type: 'input',
    name: 'pkgVersion',
    message: 'version',
    default: '1.0.0'
  },
  {
    type: 'input',
    name: 'pkgDescription',
    message: 'description'
  },
  {
    type: 'input',
    name: 'pkgKeywords',
    message: 'keywords'
  },
  {
    type: 'list',
    name: 'pkgLicense',
    message: 'license',
    choices: ['ISC', 'Apache-2.0'],
    default: 'ISC'
  },
  {
    type: 'confirm',
    name: 'pkgContributing',
    message: 'contributing',
    default: true
  },
  {
    type: 'list',
    name: 'pkgLinter',
    message: 'linter',
    choices: ['standard', 'semistandard'],
    default: 'standard'
  }]

inquirer.prompt(questions, function (data) {
  data.usrName = config.user.name
  data.usrEmail = config.user.email
  data.usrGithub = config.github.user

  if (argv.dir) data.dir = argv.dir
  if (!data.pkgDescription) data.pkgDescription = ''
  if (data.pkgKeywords !== '') {
    data.pkgKeywords = data.pkgKeywords
      .split(/[\s,]+/)
      .filter(function (value, index, self) {
        return !!value && self.indexOf(value) === index
      })
      .map(function (value) {
        return '"' + value + '"'
      })
      .join(', ')
  }

  moduleInit(data)
    .on('create', function (file) {
      // file created
      console.warn(chalk.green('✓ ') + chalk.bold(file) + ' created')
    })
    .on('warn', function (msg) {
      // something weird happened
      console.warn(chalk.yellow('✗ ' + msg))
    })
    .on('err', function (err) {
      // something went horribly wrong!
      console.error(err)
      process.exit(1)
    })
{'fraction_non_alphanumeric': 0.17894736842105263, 'fraction_numerical': 0.0032616753150481836, 'mean_word_length': 2.9775943396226414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3887970', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2367, 'n_words': 548}