Skip to content

Commit 554908e

Browse files
committedJan 23, 2018
fix(@angular/cli): allow for schema-less schematics to be generated
1 parent d3db0f6 commit 554908e

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed
 

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ export default Command.extend({
112112
.then((availableOptions: SchematicAvailableOptions[]) => {
113113
let anonymousOptions: string[] = [];
114114

115-
const nameOption = availableOptions.filter(opt => opt.name === 'name')[0];
116-
if (nameOption) {
115+
if (availableOptions) {
116+
const nameOption = availableOptions.filter(opt => opt.name === 'name')[0];
117+
if (nameOption) {
118+
anonymousOptions = [...anonymousOptions, '<name>'];
119+
}
120+
} else {
117121
anonymousOptions = [...anonymousOptions, '<name>'];
118122
}
119123

@@ -123,7 +127,7 @@ export default Command.extend({
123127

124128
this.registerOptions({
125129
anonymousOptions: anonymousOptions,
126-
availableOptions: availableOptions
130+
availableOptions: availableOptions || []
127131
});
128132
});
129133
},

Diff for: ‎packages/@angular/cli/tasks/schematic-get-help-output.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from 'chalk';
22
const Task = require('../ember-cli/lib/models/task');
33

4-
const { cyan, grey } = chalk;
4+
const { cyan, green, grey } = chalk;
55

66
export interface SchematicGetHelpOptions {
77
collectionName: string;
@@ -40,7 +40,7 @@ export default Task.extend({
4040
}), nonSchematicOptions])
4141
.then(([availableOptions, nonSchematicOptions]: [SchematicAvailableOptions[], any[]]) => {
4242
const output: string[] = [];
43-
[...(nonSchematicOptions || []), ...availableOptions]
43+
[...(nonSchematicOptions || []), ...availableOptions || []]
4444
.filter(opt => hiddenOptions.indexOf(opt.name) === -1)
4545
.forEach(opt => {
4646
let text = cyan(` --${opt.name}`);
@@ -63,6 +63,11 @@ export default Task.extend({
6363
output.push(grey(` aliases: ${aliasText}`));
6464
}
6565
});
66+
if (availableOptions === null) {
67+
output.push(green('This schematic accept additional options, but did not provide '
68+
+ 'documentation.'));
69+
}
70+
6671
return output;
6772
});
6873
}

Diff for: ‎packages/@angular/cli/tasks/schematic-get-options.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ export interface SchematicAvailableOptions {
1818
}
1919

2020
export default Task.extend({
21-
run: function (options: SchematicGetOptions): Promise<SchematicAvailableOptions[]> {
21+
run: function (options: SchematicGetOptions): Promise<SchematicAvailableOptions[] | null> {
2222
const collectionName = options.collectionName ||
2323
CliConfig.getValue('defaults.schematics.collection');
2424

2525
const collection = getCollection(collectionName);
2626

2727
const schematic = getSchematic(collection, options.schematicName);
2828

29+
if (!schematic.description.schemaJson) {
30+
return Promise.resolve(null);
31+
}
32+
2933
const properties = schematic.description.schemaJson.properties;
3034
const keys = Object.keys(properties);
3135
const availableOptions = keys

Diff for: ‎packages/@angular/cli/tasks/schematic-run.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ export default Task.extend({
168168
});
169169

170170
function prepOptions(schematic: Schematic<{}, {}>, options: SchematicOptions): SchematicOptions {
171+
const properties = (<any>schematic.description).schemaJson
172+
? (<any>schematic.description).schemaJson.properties
173+
: options;
171174

172-
const properties = (<any>schematic.description).schemaJson.properties;
173175
const keys = Object.keys(properties);
174176
if (['component', 'c', 'directive', 'd'].indexOf(schematic.description.name) !== -1) {
175177
options.prefix = (options.prefix === 'false' || options.prefix === '')

0 commit comments

Comments
 (0)
Please sign in to comment.