Skip to content

Commit

Permalink
Fix for issue yeoman/yo#518 (#81)
Browse files Browse the repository at this point in the history
* Fix for issue yeoman/yo#518

* Removed unnecessary '@' filtering in regex

* Processed review comments.
  • Loading branch information
rgroothuijsen authored and SBoudrias committed May 3, 2017
1 parent 414b8c0 commit cc008e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const escapeStrRe = require('escape-string-regexp');
const untildify = require('untildify');
const memFs = require('mem-fs');
const debug = require('debug')('yeoman:environment');
const isScoped = require('is-scoped');
const Store = require('./store');
const resolver = require('./resolver');
const TerminalAdapter = require('./adapter');
Expand Down Expand Up @@ -338,13 +339,21 @@ class Environment extends EventEmitter {
const Generator = this.get(namespace);

if (typeof Generator !== 'function') {
let generatorHint = '';
if (isScoped(namespace)) {
const splitName = namespace.split('/');
generatorHint = `${splitName[0]}/generator-${splitName[1]}`;
} else {
generatorHint = `generator-${namespace}`;
}

return this.error(
new Error(
chalk.red('You don\'t seem to have a generator with the name “' + namespace + '” installed.') + '\n' +
'But help is on the way:\n\n' +
'You can see available generators via ' +
chalk.yellow('npm search yeoman-generator') + ' or via ' + chalk.yellow('http://yeoman.io/generators/') + '. \n' +
'Install them with ' + chalk.yellow('npm install generator-' + namespace) + '.\n\n' +
'Install them with ' + chalk.yellow(`npm install ${generatorHint}`) + '.\n\n' +
'To see all your installed generators run ' + chalk.yellow('yo') + ' without any arguments. ' +
'Adding the ' + chalk.yellow('--help') + ' option will also show subgenerators. \n\n' +
'If ' + chalk.yellow('yo') + ' cannot find the generator, run ' + chalk.yellow('yo doctor') + ' to troubleshoot your system.'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"globby": "^6.1.0",
"grouped-queue": "^0.3.0",
"inquirer": "^3.0.1",
"is-scoped": "^1.0.0",
"lodash": "^4.11.1",
"log-symbols": "^1.0.1",
"mem-fs": "^1.1.0",
Expand Down
7 changes: 7 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ describe('Environment', () => {
it('returns the generator', function () {
assert.ok(this.env.run('stub:run') instanceof Generator);
});

it('correctly append scope in generator hint', function () {
this.env.on('error', err => {
assert.ok(err.message.indexOf('@dummyscope/generator-package') >= 0);
});
this.env.run('@dummyscope/package');
});
});

describe('#registerModulePath()', () => {
Expand Down

0 comments on commit cc008e5

Please sign in to comment.