diff --git a/lib/environment.js b/lib/environment.js index 056e2098..800e940f 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -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'); @@ -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.' diff --git a/package.json b/package.json index 2ce48674..59d36bae 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/environment.js b/test/environment.js index 2fd71b30..12bc88a3 100644 --- a/test/environment.js +++ b/test/environment.js @@ -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()', () => {