Skip to content

Commit

Permalink
fix(core): generate should handle multiselect shorthand (#19790)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Oct 31, 2023
1 parent bdde0dd commit 7db366b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
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

0 comments on commit 7db366b

Please sign in to comment.