Skip to content

Commit

Permalink
fix(@angular/cli): don't show deprecation messages for defaults when …
Browse files Browse the repository at this point in the history
…using `--defaults`

With this change we use the addUndefinedDefaults transformer post validation and don't create prompts which have a default value when options.defaults is truthy.

Closes: #18692
  • Loading branch information
alan-agius4 authored and filipesilva committed Oct 13, 2020
1 parent db00a24 commit 49199ce
Showing 1 changed file with 36 additions and 38 deletions.
74 changes: 36 additions & 38 deletions packages/angular/cli/models/schematic-command.ts
Expand Up @@ -304,53 +304,51 @@ export abstract class SchematicCommand<
...(await getSchematicDefaults(schematic.collection.name, schematic.name, getProjectName())),
...current,
});
workflow.engineHost.registerOptionsTransform(defaultOptionTransform);

if (options.defaults) {
workflow.registry.addPreTransform(schema.transforms.addUndefinedDefaults);
} else {
workflow.registry.addPostTransform(schema.transforms.addUndefinedDefaults);
}
workflow.engineHost.registerOptionsTransform(defaultOptionTransform);

workflow.registry.addPostTransform(schema.transforms.addUndefinedDefaults);
workflow.registry.addSmartDefaultProvider('projectName', getProjectName);
workflow.registry.useXDeprecatedProvider(msg => this.logger.warn(msg));

if (options.interactive !== false && isTTY()) {
workflow.registry.usePromptProvider((definitions: Array<schema.PromptDefinition>) => {
const questions: inquirer.QuestionCollection = definitions.map(definition => {
const question: inquirer.Question = {
name: definition.id,
message: definition.message,
default: definition.default,
};

const validator = definition.validator;
if (validator) {
question.validate = input => validator(input);
}
const questions: inquirer.QuestionCollection = definitions
.filter(definition => !options.defaults || definition.default === undefined)
.map(definition => {
const question: inquirer.Question = {
name: definition.id,
message: definition.message,
default: definition.default,
};

const validator = definition.validator;
if (validator) {
question.validate = input => validator(input);
}

switch (definition.type) {
case 'confirmation':
question.type = 'confirm';
break;
case 'list':
question.type = definition.multiselect ? 'checkbox' : 'list';
(question as inquirer.CheckboxQuestion).choices = definition.items?.map(item => {
return typeof item == 'string'
? item
: {
name: item.label,
value: item.value,
};
});
break;
default:
question.type = definition.type;
break;
}
switch (definition.type) {
case 'confirmation':
question.type = 'confirm';
break;
case 'list':
question.type = definition.multiselect ? 'checkbox' : 'list';
(question as inquirer.CheckboxQuestion).choices = definition.items?.map(item => {
return typeof item == 'string'
? item
: {
name: item.label,
value: item.value,
};
});
break;
default:
question.type = definition.type;
break;
}

return question;
});
return question;
});

return inquirer.prompt(questions);
});
Expand Down

0 comments on commit 49199ce

Please sign in to comment.