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

'use strict'

var fs = require('fs')
  , path = require('path')
  , prompt = require('prompt')
  , childProcess = require('child_process')
  , string = require('string')
  , settings
  , gitUser
  , hasPackageJson
  , packageJson = {}

if(fs.existsSync('./package.json')) {
  hasPackageJson = true
  packageJson = JSON.parse(fs.readFileSync('./package.json').toString())
}

childProcess.exec('git config --get user.name', function(ex, out, err) {
  if(ex) throw ex
  gitUser = out.trim()
  onGitConfig()
})

function onGitConfig() {
  var prompts = []
  if(!packageJson.description) prompts.push('description')
  if(!packageJson.keywords) prompts.push('keywords(space-delimited)')
  if(!hasPackageJson || !packageJson.scripts) {
    if(!hasPackageJson || !packageJson.scripts.build)
      prompts.push('browser(y/n)')
    if(!hasPackageJson || !packageJson.scripts.test)
      prompts.push('tests(y/n)')
  }
  prompt.get(prompts, function(err, result) {
    if(err) throw err
    settings = result
    settings.author = gitUser
    settings.title = path.basename(process.cwd())
    settings.githubUrl = 'https://github.com/' +
      settings.author + '/' + settings.title
    settings.year = new Date().getYear() + 1900
    settings.camelTitle = string(settings.title).camelize()
    settings.travisLink = '[![Build Status]' +
      '(https://secure.travis-ci.org/' +
      settings.author + '/' +
      settings.title + '.png)]' +
      '(http://travis-ci.org/' +
      settings.author + '/' +
      settings.title + ')'
    if(fs.existsSync('./index.js'))
      settings.main = 'index.js'
    else settings.main = settings.title + '.js'
    settings.browser = settings['browser(y/n)'] === 'y'
    settings.tests = settings['tests(y/n)'] === 'y'
    settings.keywords = (settings['keywords(space-delimited)'] || '')
      .split(' ')
      .filter(function(x) { return x.length })
    onPrompt()
  })
}

function onPrompt() {<commit_msg>Fix handling of package.json but not scripts<commit_after>#!/usr/bin/env node

'use strict'

var fs = require('fs')
  , path = require('path')
  , prompt = require('prompt')
  , childProcess = require('child_process')
  , string = require('string')
  , settings
  , gitUser
  , hasPackageJson
  , packageJson = {}

if(fs.existsSync('./package.json')) {
  hasPackageJson = true
  packageJson = JSON.parse(fs.readFileSync('./package.json').toString())
}

childProcess.exec('git config --get user.name', function(ex, out, err) {
  if(ex) throw ex
  gitUser = out.trim()
  onGitConfig()
})

function onGitConfig() {
  var prompts = []
  if(!packageJson.description) prompts.push('description')
  if(!packageJson.keywords) prompts.push('keywords(space-delimited)')
  if(!hasPackageJson || !packageJson.scripts) {
    if(!hasPackageJson || !packageJson.scripts || !packageJson.scripts.build)
      prompts.push('browser(y/n)')
    if(!hasPackageJson || !packageJson.scripts || !packageJson.scripts.test)
      prompts.push('tests(y/n)')
  }
  prompt.get(prompts, function(err, result) {
    if(err) throw err
    settings = result
    settings.author = gitUser
    settings.title = path.basename(process.cwd())
    settings.githubUrl = 'https://github.com/' +
      settings.author + '/' + settings.title
    settings.year = new Date().getYear() + 1900
    settings.camelTitle = string(settings.title).camelize()
    settings.travisLink = '[![Build Status]' +
      '(https://secure.travis-ci.org/' +
      settings.author + '/' +
      settings.title + '.png)]' +
      '(http://travis-ci.org/' +
      settings.author + '/' +
      settings.title + ')'
    if(fs.existsSync('./index.js'))
      settings.main = 'index.js'
    else settings.main = settings.title + '.js'
    settings.browser = settings['browser(y/n)'] === 'y'
    settings.tests = settings['tests(y/n)'] === 'y'
    settings.keywords = (settings['keywords(space-delimited)'] || '')
      .split(' ')
      .filter(function(x) { return x.length })
    onPrompt()
  })
}

function onPrompt() {
{'fraction_non_alphanumeric': 0.1805314129625031, 'fraction_numerical': 0.0019865905140302956, 'mean_word_length': 3.436123348017621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5151064', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1304, 'n_words': 222}