Skip to content

Commit ca8e834

Browse files
committedJan 23, 2018
fix(@angular/cli): allow colon separated schematic name in generate
1 parent 554908e commit ca8e834

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
 

Diff for: ‎packages/@angular/cli/commands/generate.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,24 @@ export default Command.extend({
6565
'<schematic>'
6666
],
6767

68-
getCollectionName(rawArgs: string[]) {
68+
getCollectionName(rawArgs: string[], parsedOptions?: { collection?: string }): [string, string] {
69+
let schematicName = rawArgs[0];
6970
let collectionName = CliConfig.getValue('defaults.schematics.collection');
70-
if (rawArgs) {
71+
72+
if (schematicName.match(/:/)) {
73+
[collectionName, schematicName] = schematicName.split(':', 2);
74+
} else if (parsedOptions) {
75+
if (parsedOptions.collection) {
76+
collectionName = parsedOptions.collection;
77+
}
78+
} else {
7179
const parsedArgs = this.parseArgs(rawArgs, false);
7280
if (parsedArgs.options.collection) {
7381
collectionName = parsedArgs.options.collection;
7482
}
7583
}
76-
return collectionName;
84+
85+
return [collectionName, schematicName];
7786
},
7887

7988
beforeRun: function(rawArgs: string[]) {
@@ -83,7 +92,7 @@ export default Command.extend({
8392
return;
8493
}
8594

86-
const schematicName = rawArgs[0];
95+
const [collectionName, schematicName] = this.getCollectionName(rawArgs);
8796
if (!schematicName) {
8897
return Promise.reject(new SilentError(oneLine`
8998
The "ng generate" command requires a
@@ -103,7 +112,6 @@ export default Command.extend({
103112
ui: this.ui,
104113
project: this.project
105114
});
106-
const collectionName = this.getCollectionName(rawArgs);
107115

108116
return getOptionsTask.run({
109117
schematicName,
@@ -166,7 +174,7 @@ export default Command.extend({
166174
: commandOptions.path;
167175

168176
const cwd = this.project.root;
169-
const schematicName = rawArgs[0];
177+
const [collectionName, schematicName] = this.getCollectionName(rawArgs, commandOptions);
170178

171179
if (['component', 'c', 'directive', 'd'].indexOf(schematicName) !== -1) {
172180
if (commandOptions.prefix === undefined) {
@@ -185,8 +193,6 @@ export default Command.extend({
185193
ui: this.ui,
186194
project: this.project
187195
});
188-
const collectionName = commandOptions.collection ||
189-
CliConfig.getValue('defaults.schematics.collection');
190196

191197
if (collectionName === '@schematics/angular' && schematicName === 'interface' && rawArgs[2]) {
192198
commandOptions.type = rawArgs[2];

0 commit comments

Comments
 (0)