Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace search for generators with the new search used on the website #574

Open
Haroenv opened this issue Apr 20, 2018 · 1 comment
Open

Comments

@Haroenv
Copy link

Haroenv commented Apr 20, 2018

Type of issue

feature request

Why?

once yeoman/yeoman.io#763 is merged and we're all happy with it, we can replace the search to be consistent with what's on the site

Relevant code

The code to change will be around this:

yo/lib/routes/install.js

Lines 44 to 102 in 479250a

const getAllGenerators = _.memoize(() => npmKeyword('yeoman-generator'));
function searchMatchingGenerators(app, term, cb) {
function handleBlacklist(blacklist) {
const installedGenerators = app.env.getGeneratorNames();
getAllGenerators().then(allGenerators => {
cb(null, allGenerators.filter(generator => {
if (blacklist.indexOf(generator.name) !== -1) {
return false;
}
if (installedGenerators.indexOf(generator.name) !== -1) {
return false;
}
return generatorMatchTerm(generator, term);
}));
}, cb);
}
got('http://yeoman.io/blacklist.json', {json: true})
.then(response => handleBlacklist(response.body))
.catch(() => handleBlacklist([]));
}
function fetchGeneratorInfo(generator, cb) {
packageJson(generator.name).then(pkg => {
const official = OFFICIAL_GENERATORS.indexOf(pkg.name) !== -1;
const mustache = official ? chalk.green(` ${figures.mustache} `) : '';
cb(null, {
name: generator.name.replace(/^generator-/, '') + mustache + ' ' + chalk.dim(pkg.description),
value: generator.name,
official: -official
});
}).catch(cb);
}
function searchNpm(app, term) {
const promise = new Promise((resolve, reject) => {
searchMatchingGenerators(app, term, (err, matches) => {
if (err) {
reject(err);
return;
}
async.map(matches, fetchGeneratorInfo, (err2, choices) => {
if (err2) {
reject(err2);
return;
}
resolve(choices);
});
});
});
return promise.then(choices => promptInstallOptions(app, sortOn(choices, ['official', 'name'])));
}

There algoliasearch could be used with the same searchParameters as in yeoman/yeoman.io#763 (comment)

cc @mischah, @SBoudrias, @pixelastic

@JoshuaKGoldberg
Copy link

Related: #361. There's probably some unification work to be done around searching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants