Skip to content

Commit

Permalink
feat(@angular/cli): add --defaults option to ng new
Browse files Browse the repository at this point in the history
Any option with a default value will not be prompted (if a prompt is defined) and the default will be used instead.

Closes #12084
  • Loading branch information
clydin committed Sep 6, 2018
1 parent 5007a19 commit 270ca76
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/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"type": "boolean",
"default": "true",
"description": "Disables interactive inputs (i.e., prompts)."
},
"defaults": {
"type": "boolean",
"default": "false",
"description": "Disables interactive inputs (i.e., prompts) for options with a default."
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface BaseSchematicOptions extends BaseCommandOptions {
dryRun?: boolean;
force?: boolean;
interactive?: boolean;
defaults?: boolean;
}

export interface RunSchematicOptions {
Expand Down Expand Up @@ -259,6 +260,11 @@ export abstract class SchematicCommand<
});

if (options.interactive !== false && process.stdout.isTTY) {
if (options.defaults) {
(workflow.registry as schema.CoreSchemaRegistry)
.addPreTransform(schema.transforms.addUndefinedDefaults);
}

workflow.registry.usePromptProvider((definitions: Array<schema.PromptDefinition>) => {
const questions: inquirer.Questions = definitions.map(definition => {
const question: inquirer.Question = {
Expand Down

0 comments on commit 270ca76

Please sign in to comment.