<commit_before>import * as path from "path";
import * as fs from "fs";
import * as inquirer from "inquirer";

import { RegSuitCore } from "reg-suit-core";
import { CoreConfig } from "reg-suit-interface";
import { CliOptions } from "../cli-options";
import packageUtil, { PLUGIN_NAME_REGEXP } from "../package-util";
import getRegCore from "../get-reg-core";

import ignore = require("ignore");

function hasGitignore(dir: string) {
  return fs.existsSync(path.resolve(dir, ".gitignore"));
}

function loadGitignore(dir: string) {
  const gi = fs.readFileSync(path.resolve(dir, ".gitignore"), "utf8");
  const ig = ignore();
  gi.split("\n").forEach(l => {
    if (!l.trim().startsWith("#")) {
      ig.add(l);
    }
  });
  return ig;
}

function appendGitignore(dir: string, name: string) {
  fs.appendFileSync(path.resolve(dir, ".gitignore"), name + "\n", "utf-8");
}

export function prepareCore(coreConf: CoreConfig, confDir: string) {
  return inquirer.prompt([
    {
      name: "workingDir",
      message: "Working directory of reg-suit.",
      default: coreConf.workingDir,
      validate(x: string) {
        return !!x.length;
      }
    },
    {
      name: "addIgnore",
      type: "confirm",
      message: function({ workingDir }: { workingDir: string }) {
        return `Append "${workingDir}" entry to yout .gitignore file.`;
      },
      when({ workingDir }: { workingDir: string }) {
        return hasGitignore(confDir) && !loadGitignore(confDir).ignores(workingDir);<commit_msg>fix typo<commit_after>import * as path from "path";
import * as fs from "fs";
import * as inquirer from "inquirer";

import { RegSuitCore } from "reg-suit-core";
import { CoreConfig } from "reg-suit-interface";
import { CliOptions } from "../cli-options";
import packageUtil, { PLUGIN_NAME_REGEXP } from "../package-util";
import getRegCore from "../get-reg-core";

import ignore = require("ignore");

function hasGitignore(dir: string) {
  return fs.existsSync(path.resolve(dir, ".gitignore"));
}

function loadGitignore(dir: string) {
  const gi = fs.readFileSync(path.resolve(dir, ".gitignore"), "utf8");
  const ig = ignore();
  gi.split("\n").forEach(l => {
    if (!l.trim().startsWith("#")) {
      ig.add(l);
    }
  });
  return ig;
}

function appendGitignore(dir: string, name: string) {
  fs.appendFileSync(path.resolve(dir, ".gitignore"), name + "\n", "utf-8");
}

export function prepareCore(coreConf: CoreConfig, confDir: string) {
  return inquirer.prompt([
    {
      name: "workingDir",
      message: "Working directory of reg-suit.",
      default: coreConf.workingDir,
      validate(x: string) {
        return !!x.length;
      }
    },
    {
      name: "addIgnore",
      type: "confirm",
      message: function({ workingDir }: { workingDir: string }) {
        return `Append "${workingDir}" entry to your .gitignore file.`;
      },
      when({ workingDir }: { workingDir: string }) {
        return hasGitignore(confDir) && !loadGitignore(confDir).ignores(workingDir);
{'fraction_non_alphanumeric': 0.1645021645021645, 'fraction_numerical': 0.001332001332001332, 'mean_word_length': 3.5105105105105103, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5442037', 'n_tokens_mistral': 968, 'n_tokens_neox': 949, 'n_words': 234}