<commit_before>const Listr = require('listr')
const fs = require('fs-extra')
const createInstallPlugin = require('../tasks/installPlugin')
const Command = require('../Command')
const readProjectConfiguration = require('../tasks/readProjectConfiguration')
const saveProjectConfiguration = require('../tasks/saveProjectConfiguration')
const gitCheckChanges = require('../tasks/gitCheckChanges')
const selectPlugins = require('../tasks/selectPlugins')
const fetchPlugins = require('../tasks/fetchPlugins')
const bootstrapProjectDeps = require('../tasks/bootstrapProjectDeps')
const cleanCache = require('../tasks/cleanCache')
const resolvePluginsDeps = require('../tasks/resolvePluginsDeps')
const { extendsTask, skipMode } = require('../utils/tasks')
const { DEV_MODE, TEST_MODE } = require('../constants')
const { commit: gitCommit } = require('../utils/git')
const { findInList: findPluginInList } = require('../utils/plugin')

const skipNotProdMode = skipMode(DEV_MODE, TEST_MODE)

class AddPluginsCommand extends Command {
  constructor([...pluginsToInstall], options) {
    super(options)

    this.state = {
      pluginsToInstall,
    }

    this.installPlugins = this.installPlugins.bind(this)
  }

  installPlugins(ctx) {
    const { plugins: pluginList, configuration: { pluginsPath } } = ctx

    fs.ensureDirSync(pluginsPath)

    const pluginsToInstall = this.state.pluginsToInstall.map(plugin =>
      findPluginInList(plugin, pluginList)
    )

    const invalidPlugins = pluginsToInstall.filter(plugin => !plugin.cloneUrl).map(plugin => plugin.name)
    if (invalidPlugins.length) {
      throw new Error(`Can't find plugins with names:\n - ${invalidPlugins.join(', ')}`)
    }

    return new Listr(
      pluginsToInstall.map(({ name, cloneUrl }) =>
        createInstallPlugin(name, cloneUrl)
      ), { exitOnError: false }
    )
  }

  init() {
    const { pluginsToInstall } = this.state
    this.add([
      readProjectConfiguration,
      extendsTask(gitCheckChanges, {
        skip: skipNotProdMode,
        after: ({ hasChanges }) => {
          if (hasChanges) {
            throw new Error('Working tree has modifications. Cannot add plugins')
          }
        },
      }),
      fetchPlugins,
      {
        title: 'Select plugins to install',
        task: selectPlugins.task,
        skip: skipNotProdMode,
        enabled: () => pluginsToInstall.length === 0,
        before: ctx => {
          ctx.excludePluginsNames = ctx.configuration.plugins
        },
        after: ctx => {
          this.state.pluginsToInstall = ctx.selectedPlugins
          delete ctx.selectedPlugins
        },
      },
      {
        title: 'Install plugins',
        task: this.installPlugins,
      },
      resolvePluginsDeps,
      bootstrapProjectDeps,
      saveProjectConfiguration,
      {
        title: 'Git commit',
        skip: ctx => (
          ((!ctx.installedPlugins || !ctx.installedPlugins.length) && 'Plugins not added') || skipNotProdMode(ctx)
        ),
        task: ({ projectPath, installedPlugins }) => {
          gitCommit(projectPath, `Add plugins: ${installedPlugins.join(', ')}`)
        },
      },
      cleanCache,
    ])
  }
}

AddPluginsCommand.commandName = 'add'
AddPluginsCommand.commandDescription = 'Add plugins'

module.exports = AddPluginsCommand
<commit_msg>Fix select in dev mode<commit_after>const Listr = require('listr')
const fs = require('fs-extra')
const createInstallPlugin = require('../tasks/installPlugin')
const Command = require('../Command')
const readProjectConfiguration = require('../tasks/readProjectConfiguration')
const saveProjectConfiguration = require('../tasks/saveProjectConfiguration')
const gitCheckChanges = require('../tasks/gitCheckChanges')
const selectPlugins = require('../tasks/selectPlugins')
const fetchPlugins = require('../tasks/fetchPlugins')
const bootstrapProjectDeps = require('../tasks/bootstrapProjectDeps')
const cleanCache = require('../tasks/cleanCache')
const resolvePluginsDeps = require('../tasks/resolvePluginsDeps')
const { extendsTask, skipMode } = require('../utils/tasks')
const { DEV_MODE, TEST_MODE } = require('../constants')
const { commit: gitCommit } = require('../utils/git')
const { findInList: findPluginInList } = require('../utils/plugin')

const skipNotProdMode = skipMode(DEV_MODE, TEST_MODE)

const skipTestMode = skipMode(TEST_MODE)

class AddPluginsCommand extends Command {
  constructor([...pluginsToInstall], options) {
    super(options)

    this.state = {
      pluginsToInstall,
    }

    this.installPlugins = this.installPlugins.bind(this)
  }

  installPlugins(ctx) {
    const { plugins: pluginList, configuration: { pluginsPath } } = ctx

    fs.ensureDirSync(pluginsPath)

    const pluginsToInstall = this.state.pluginsToInstall.map(plugin =>
      findPluginInList(plugin, pluginList)
    )

    const invalidPlugins = pluginsToInstall.filter(plugin => !plugin.cloneUrl).map(plugin => plugin.name)
    if (invalidPlugins.length) {
      throw new Error(`Can't find plugins with names:\n - ${invalidPlugins.join(', ')}`)
    }

    return new Listr(
      pluginsToInstall.map(({ name, cloneUrl }) =>
        createInstallPlugin(name, cloneUrl)
      ), { exitOnError: false }
    )
  }

  init() {
    const { pluginsToInstall } = this.state
    this.add([
      readProjectConfiguration,
      extendsTask(gitCheckChanges, {
        skip: skipNotProdMode,
        after: ({ hasChanges }) => {
          if (hasChanges) {
            throw new Error('Working tree has modifications. Cannot add plugins')
          }
        },
      }),
      fetchPlugins,
      {
        title: 'Select plugins to install',
        task: selectPlugins.task,
        skip: skipTestMode,
        enabled: () => pluginsToInstall.length === 0,
        before: ctx => {
          ctx.excludePluginsNames = ctx.configuration.plugins
        },
        after: ctx => {
          this.state.pluginsToInstall = ctx.selectedPlugins
          delete ctx.selectedPlugins
        },
      },
      {
        title: 'Install plugins',
        task: this.installPlugins,
      },
      resolvePluginsDeps,
      bootstrapProjectDeps,
      saveProjectConfiguration,
      {
        title: 'Git commit',
        skip: ctx => (
          ((!ctx.installedPlugins || !ctx.installedPlugins.length) && 'Plugins not added') || skipNotProdMode(ctx)
        ),
        task: ({ projectPath, installedPlugins }) => {
          gitCommit(projectPath, `Add plugins: ${installedPlugins.join(', ')}`)
        },
      },
      cleanCache,
    ])
  }
}

AddPluginsCommand.commandName = 'add'
AddPluginsCommand.commandDescription = 'Add plugins'

module.exports = AddPluginsCommand

{'fraction_non_alphanumeric': 0.12825501346902124, 'fraction_numerical': 0.000299311583358276, 'mean_word_length': 3.060145808019441, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1522964', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1858, 'n_words': 377}