<commit_before>import Generator from 'yeoman-generator';
import { dependencies, configs } from '../core';
import { buildConfig as buildLintStagedConfig, LintStagedConfig } from './lint-staged';
import prettifyJson from '../prettier/prettify-json';

interface Hooks {
  [name: string]: string;
}

export default class HooksGenerator extends Generator {
  private lintStagedConfig: LintStagedConfig = {};

  public initializing(): void {
    dependencies.importFrom(this.fs.readJSON('package.json'));
  }

  public configuring(): void {
    this.lintStagedConfig = buildLintStagedConfig();
  }

  public async writing(): Promise<void> {
    if (Object.keys(this.lintStagedConfig).length > 0) {
      prettifyJson(this.lintStagedConfig);

      await configs.save('.lintstagedrc.json', this.lintStagedConfig);

      dependencies.add('lint-staged', 'devDependencies');
    }

    const config: { hooks: Hooks } = { hooks: {} };

    if (dependencies.has('lint-staged', 'devDependencies')) {
      config.hooks['pre-commit'] = 'lint-staged';
    }

    config.hooks['pre-push'] = 'yarn verify';

    if (Object.keys(config.hooks).length > 0) {
      this.fs.writeJSON(this.destinationPath('.huskyrc.json'), config);

      dependencies.add('husky', 'devDependencies');
    }
  }

  public install(): void {
    this.yarnInstall(dependencies.get('devDependencies'), { dev: true });
  }
}<commit_msg>refactor: save husky config<commit_after>import Generator from 'yeoman-generator';
import { dependencies, configs } from '../core';
import { buildConfig as buildLintStagedConfig, LintStagedConfig } from './lint-staged';
import prettifyJson from '../prettier/prettify-json';

interface Hooks {
  [name: string]: string;
}

export default class HooksGenerator extends Generator {
  private lintStagedConfig: LintStagedConfig = {};

  public initializing(): void {
    dependencies.importFrom(this.fs.readJSON('package.json'));
  }

  public configuring(): void {
    this.lintStagedConfig = buildLintStagedConfig();
  }

  public async writing(): Promise<void> {
    if (Object.keys(this.lintStagedConfig).length > 0) {
      prettifyJson(this.lintStagedConfig);

      await configs.save('.lintstagedrc.json', this.lintStagedConfig);

      dependencies.add('lint-staged', 'devDependencies');
    }

    const config: { hooks: Hooks } = { hooks: {} };

    if (dependencies.has('lint-staged', 'devDependencies')) {
      config.hooks['pre-commit'] = 'lint-staged';
    }

    config.hooks['pre-push'] = 'yarn verify';

    if (Object.keys(config.hooks).length > 0) {
      await configs.save('.huskyrc.json', config);

      dependencies.add('husky', 'devDependencies');
    }
  }

  public install(): void {
    this.yarnInstall(dependencies.get('devDependencies'), { dev: true });
  }
}
{'fraction_non_alphanumeric': 0.14922689679971232, 'fraction_numerical': 0.001438331535418914, 'mean_word_length': 4.012612612612613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3555674', 'n_tokens_mistral': 881, 'n_tokens_neox': 848, 'n_words': 168}