Skip to content

Commit 5ee9c8b

Browse files
Puigcerberkieronqtran
authored andcommitted
fix(generate): show error when no name is specified
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 angular#2684
1 parent 48d58a0 commit 5ee9c8b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/angular-cli/commands/generate.ts

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const GenerateCommand = EmberGenerateCommand.extend({
2424
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
2525
}
2626

27+
if (!rawArgs[1]) {
28+
SilentError.debugOrThrow('angular-cli/commands/generate',
29+
`The \`ng generate ${rawArgs[0]}\` command requires a name to be specified.`);
30+
}
31+
2732
// Override default help to hide ember blueprints
2833
EmberGenerateCommand.prototype.printDetailedHelp = function() {
2934
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));

tests/acceptance/generate-module.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ describe('Acceptance: ng generate module', function () {
3030
return tmp.teardown('./tmp');
3131
});
3232

33+
it('will fail if no name is specified', function () {
34+
return ng(['generate', 'module']).catch((error) => {
35+
expect(error).to.equal('The `ng generate module` command requires a name to be specified.');
36+
});
37+
});
38+
3339
it('ng generate module my-module', function () {
3440
return ng(['generate', 'module', 'my-module']).then(() => {
3541
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);

0 commit comments

Comments
 (0)