Skip to content

Commit eb78d1c

Browse files
committed
fix(@angular/cli): Allow schematics without a name option.
Fixes angular#8793
1 parent c938936 commit eb78d1c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/@angular/cli/commands/generate.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,16 @@ export default Command.extend({
109109
schematicName,
110110
collectionName
111111
})
112-
.then((availableOptions: SchematicAvailableOptions) => {
112+
.then((availableOptions: SchematicAvailableOptions[]) => {
113113
let anonymousOptions: string[] = [];
114+
115+
const nameOption = availableOptions.filter(opt => opt.name === 'name')[0];
116+
if (nameOption) {
117+
anonymousOptions = [...anonymousOptions, '<name>'];
118+
}
119+
114120
if (collectionName === '@schematics/angular' && schematicName === 'interface') {
115-
anonymousOptions = ['<type>'];
121+
anonymousOptions = [...anonymousOptions, '<type>'];
116122
}
117123

118124
this.registerOptions({
@@ -127,8 +133,12 @@ export default Command.extend({
127133
throw 'The `ng generate module` command requires a name to be specified.';
128134
}
129135

130-
const entityName = rawArgs[1];
131-
commandOptions.name = stringUtils.dasherize(entityName.split(separatorRegEx).pop());
136+
let entityName = rawArgs[1];
137+
if (entityName) {
138+
commandOptions.name = stringUtils.dasherize(entityName.split(separatorRegEx).pop());
139+
} else {
140+
entityName = '';
141+
}
132142

133143
const appConfig = getAppFromConfig(commandOptions.app);
134144
const dynamicPathOptions: DynamicPathOptions = {

tests/e2e/tests/build/build-app-shell-with-schematic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export default function () {
2626

2727
return Promise.resolve()
2828
.then(() => expectToFail(() => {
29-
return ng('generate', 'appShell', 'name', '--universal-app', 'universal');
29+
return ng('generate', 'appShell', '--universal-app', 'universal');
3030
})
3131
.then(() => appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>'))
32-
.then(() => ng('generate', 'appShell', 'name', '--universal-app', 'universal'))
32+
.then(() => ng('generate', 'appShell', '--universal-app', 'universal'))
3333
.then(() => updateJsonFile('package.json', packageJson => {
3434
const dependencies = packageJson['dependencies'];
3535
dependencies['@angular/platform-server'] = platformServerVersion;

0 commit comments

Comments
 (0)