<commit_before>import fs from 'fs'
import Shell from 'shelljs'

// Get ignite config file
export const getConfig = () => {
  try {
    return require(`${Shell.pwd()}/ignite.json`)
  } catch (e) {
    return null
  }
}

// Use this sparingly, as file contents are fickle!
export const insertInFile = (theFile, theFind, theInsert, insertAfter = true) => {
  // read full file - Not a great idea if we ever touch large files
  let data = fs.readFileSync(theFile, 'utf-8')
  let newContents = ''
  // get the full line of first occurance
  let finder = new RegExp(`.*${theFind}.*`, '')
  let matches = data.match(finder)
  // Quick error check
  if (matches.length === 0) throw new Error(`'${theFind}' was not found in file.`)

  // insert contents into file
  if (insertAfter) {
    newContents = data.replace(finder, `${matches[0]}\n${theInsert}`)
  } else {
    newContents = data.replace(finder, `${theInsert}\n${matches[0]}`)
  }

  // overwrite file with modified contents
  fs.writeFileSync(theFile, newContents, 'utf-8')
}

// --------------
// UNTESTED
// --------------<commit_msg>back to old ignite file<commit_after>import fs from 'fs'
import Shell from 'shelljs'

// Get ignite config file
export const getConfig = () => {
  try {
    return require(`${Shell.pwd()}/.ignite`)
  } catch (e) {
    return null
  }
}

// Use this sparingly, as file contents are fickle!
export const insertInFile = (theFile, theFind, theInsert, insertAfter = true) => {
  // read full file - Not a great idea if we ever touch large files
  let data = fs.readFileSync(theFile, 'utf-8')
  let newContents = ''
  // get the full line of first occurance
  let finder = new RegExp(`.*${theFind}.*`, '')
  let matches = data.match(finder)
  // Quick error check
  if (matches.length === 0) throw new Error(`'${theFind}' was not found in file.`)

  // insert contents into file
  if (insertAfter) {
    newContents = data.replace(finder, `${matches[0]}\n${theInsert}`)
  } else {
    newContents = data.replace(finder, `${theInsert}\n${matches[0]}`)
  }

  // overwrite file with modified contents
  fs.writeFileSync(theFile, newContents, 'utf-8')
}

// --------------
// UNTESTED
// --------------
{'fraction_non_alphanumeric': 0.1706422018348624, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 3.0614525139664805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4990630', 'n_tokens_mistral': 695, 'n_tokens_neox': 686, 'n_words': 218}