<commit_before>'use strict';
var async = require('async');
var chalk = require('chalk');
var customError = require('custom-error');
var inquirer = require('inquirer');
var request = require('request');
var spawn = require('cross-spawn');
var sortOn = require('sort-on');
var urls = require('../utils/urls');

module.exports = function (app) {
  app.insight.track('yoyo', 'install');

  inquirer.prompt([{
    name: 'searchTerm',
    message: 'Search npm for generators'
  }], function (answers) {
    searchNpm(app, answers.searchTerm);
  });
};

function formatRow(row) {
  return {
    name: row.key[1],
    match: function (term) {
      return row.key.join(' ').indexOf(term) >= 0;
    }
  };
}

var NpmError = customError('NpmError');
function npmError(extra) {
  return new NpmError('Failed to fetch npm registry (see http://status.npmjs.org for status) \n' + (extra || ''));
}

var getAllGenerators = (function () {
  var allGenerators;

  return function (cb) {
    if (allGenerators) {
      return cb(allGenerators);
    }

    var url = urls.npm.keyword('yeoman-generator');

    request({
      url: url,
      json: true
    }, function (err, res, body) {
      if (err || res.statusCode !== 200) {
        throw npmError(err + '\n' + body);
      }

      allGenerators = body.rows.map(formatRow);
      cb(allGenerators);
    });
  };
})();

function searchMatchingGenerators(app, term, cb) {
  getAllGenerators(function (allGenerators) {
    cb(allGenerators.filter(function(generator){
      // filter already installed generators
      if (app.env.getGeneratorsMeta()[generator.name]) {
        return false;
      }

      return generator.match(term);
    }));
  });
}<commit_msg>fix regression with generator search including already installed generators<commit_after>'use strict';
var async = require('async');
var chalk = require('chalk');
var customError = require('custom-error');
var inquirer = require('inquirer');
var request = require('request');
var spawn = require('cross-spawn');
var sortOn = require('sort-on');
var utils = require('../utils');
var urls = require('../utils/urls');

module.exports = function (app) {
  app.insight.track('yoyo', 'install');

  inquirer.prompt([{
    name: 'searchTerm',
    message: 'Search npm for generators'
  }], function (answers) {
    searchNpm(app, answers.searchTerm);
  });
};

function formatRow(row) {
  return {
    name: row.key[1],
    match: function (term) {
      return row.key.join(' ').indexOf(term) >= 0;
    }
  };
}

var NpmError = customError('NpmError');
function npmError(extra) {
  return new NpmError('Failed to fetch npm registry (see http://status.npmjs.org for status) \n' + (extra || ''));
}

var getAllGenerators = (function () {
  var allGenerators;

  return function (cb) {
    if (allGenerators) {
      return cb(allGenerators);
    }

    var url = urls.npm.keyword('yeoman-generator');

    request({
      url: url,
      json: true
    }, function (err, res, body) {
      if (err || res.statusCode !== 200) {
        throw npmError(err + '\n' + body);
      }

      allGenerators = body.rows.map(formatRow);
      cb(allGenerators);
    });
  };
})();

function searchMatchingGenerators(app, term, cb) {
  var installedGenerators = utils.generatorsFromEnv(app.env);

  getAllGenerators(function (allGenerators) {
    cb(allGenerators.filter(function (generator) {
      if (installedGenerators.indexOf(generator.name.replace(/^generator-/, '')) !== -1) {
        return false;
      }

      return generator.match(term);
    }));
  });
}
{'fraction_non_alphanumeric': 0.16286277824739362, 'fraction_numerical': 0.0030994646379261764, 'mean_word_length': 3.409937888198758, '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': '1837691', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1119, 'n_words': 262}