Skip to content

Commit

Permalink
fix(generate): show error when no name is specified
Browse files Browse the repository at this point in the history
Show custom error when user forgets the name while generating blueprints.
Earlier it would fall to the dynamicPathParser function and throw a TypeError: Path must be a string. Received undefined.

Close #2684
  • Loading branch information
Puigcerber authored and filipesilva committed Oct 17, 2016
1 parent 4608445 commit 249ccf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/angular-cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const GenerateCommand = EmberGenerateCommand.extend({
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
}

if (!rawArgs[1]) {
SilentError.debugOrThrow('angular-cli/commands/generate',
`The \`ng generate ${rawArgs[0]}\` command requires a name to be specified.`);
}

// Override default help to hide ember blueprints
EmberGenerateCommand.prototype.printDetailedHelp = function() {
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
Expand Down
6 changes: 6 additions & 0 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('Acceptance: ng generate module', function () {
return tmp.teardown('./tmp');
});

it('will fail if no name is specified', function () {
return ng(['generate', 'module']).catch((error) => {
expect(error).to.equal('The `ng generate module` command requires a name to be specified.');
});
});

it('ng generate module my-module', function () {
return ng(['generate', 'module', 'my-module']).then(() => {
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
Expand Down

0 comments on commit 249ccf7

Please sign in to comment.