Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): generate should handle multiselect shorthand #19790

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/nx/src/utils/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,44 @@ describe('params', () => {
]);
});

it('should use a multiselect if type is array and x-prompt uses shorthand', () => {
const prompts = getPromptsForSchema(
{},
{
properties: {
pets: {
type: 'array',
'x-prompt': 'What kind of pets do you have?',
items: {
enum: ['cat', 'dog', 'fish'],
},
},
},
},
{
version: 2,
projects: {},
}
);

expect(prompts).toMatchInlineSnapshot(`
[
{
"choices": [
"cat",
"dog",
"fish",
],
"limit": 10,
"message": "What kind of pets do you have?",
"name": "pets",
"type": "multiselect",
"validate": [Function],
},
]
`);
});

describe('Project prompts', () => {
it('should use an autocomplete prompt for a property named project', () => {
const prompts = getPromptsForSchema(
Expand Down
21 changes: 17 additions & 4 deletions packages/nx/src/utils/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,23 @@ export function getPromptsForSchema(
// Normalize x-prompt
if (typeof v['x-prompt'] === 'string') {
const message = v['x-prompt'];
v['x-prompt'] = {
type: v.type === 'boolean' ? 'confirm' : 'input',
message,
};
if (v.type === 'boolean') {
v['x-prompt'] = {
type: 'confirm',
message,
};
} else if (v.type === 'array' && v.items?.enum) {
v['x-prompt'] = {
type: 'multiselect',
items: v.items.enum,
message,
};
} else {
v['x-prompt'] = {
type: 'input',
message,
};
}
}

question.message = v['x-prompt'].message;
Expand Down