| 109 | } |
| 110 | |
| 111 | function createPlatformPrompter(platforms: string[]): Prompter { |
| 112 | let selectManyCalls = 0; |
| 113 | return { |
| 114 | selectOne: async <T>(opts: { options: Array<{ value: T }> }) => { |
| 115 | const preferredOption = opts.options.find((option) => option.value != null); |
| 116 | return (preferredOption ?? opts.options[0]).value; |
| 117 | }, |
| 118 | selectMany: async <T>(opts: { options: Array<{ value: T }> }) => { |
| 119 | selectManyCalls++; |
| 120 | if (selectManyCalls === 1) { |
| 121 | return opts.options |
| 122 | .filter((option) => platforms.includes(String(option.value))) |
| 123 | .map((option) => option.value); |
| 124 | } |
| 125 | return opts.options.map((option) => option.value); |
| 126 | }, |
| 127 | confirm: async (opts: { defaultValue: boolean }) => opts.defaultValue, |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | describe('setup command', () => { |
| 132 | const originalStdinIsTTY = process.stdin.isTTY; |