<commit_before>const pixie = require('pixie')
const decompress = require('targz').decompress
const glob = require('glob')
const fs = require('fs')
const path = require('path')
const homedir = require('os').homedir
const readline = require('readline')
const through = require('through2')
const confirm = require('confirm')

function init(args, flags) {
  if (!args.length) return console.log('Usage: project init <template name> [target] [template properties...]')
  const name = args[0]
  const target = args[1] || process.cwd()
  glob(path.join(target, '**', '*'), (err, files) => {
    if (err) throw err
    if (files.length) {
      return confirm('There are files in this folder already, do you want to continue?', [
        { option: 'y', aliases: ['yes'] },
        { option: 'n', aliases: ['no'] }
      ], answer => {
        if (answer.y) write(name, target, flags)
        else console.log('Aborted'); process.exit(0)
      })
    }

    write(name, target, flags)
  })
}

function write(name, target, flags) {
  const template = path.join(homedir(), '.project', `${name}.tar.gz`)
  decompress({
    src: template,
    dest: target,
    tar: {
      mapStream: f => {
        if (!flags) return f;
        return f.pipe(through.obj(function(data, _, cb) {
          this.push(new Buffer(pixie.render(data.toString(), flags), 'utf8'))
          cb()
        }))
      }
    }
  }, err => {
    if (err) return console.log(err)
    console.log(`created project ${path.basename(target)} from ${name}`)
    process.exit(0)
  })
}
<commit_msg>fix(init): fix issue where instantiating a project to a directory that already contains files doesn't actually write new data<commit_after>const pixie = require('pixie')
const decompress = require('targz').decompress
const glob = require('glob')
const fs = require('fs')
const path = require('path')
const homedir = require('os').homedir
const readline = require('readline')
const through = require('through2')
const confirm = require('confirm')

function init(args, flags) {
  if (!args.length) return console.log('Usage: project init <template name> [target] [template properties...]')
  const name = args[0]
  const target = args[1] || process.cwd()
  glob(path.join(target, '**', '*'), (err, files) => {
    if (err) throw err
    if (files.length) {
      return confirm('There are files in this folder already, do you want to continue?', [
        { option: 'y', aliases: ['yes'] },
        { option: 'n', aliases: ['no'] }
      ], answer => {
        if (answer.y) {
          write(name, target, flags)
        } else {
          console.log('Aborted')
          process.exit(0)
        }
      })
    }

    write(name, target, flags)
  })
}

function write(name, target, flags) {
  const template = path.join(homedir(), '.project', `${name}.tar.gz`)
  decompress({
    src: template,
    dest: target,
    tar: {
      mapStream: f => {
        if (!flags) return f;
        return f.pipe(through.obj(function(data, _, cb) {
          this.push(new Buffer(pixie.render(data.toString(), flags), 'utf8'))
          cb()
        }))
      }
    }
  }, err => {
    if (err) return console.log(err)
    console.log(`created project ${path.basename(target)} from ${name}`)
    process.exit(0)
  })
}

{'fraction_non_alphanumeric': 0.16866359447004609, 'fraction_numerical': 0.003686635944700461, 'mean_word_length': 3.04472049689441, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1733583', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1017, 'n_words': 278}