|
1 | 1 | import { Platform } from '@expo/eas-build-job'; |
2 | 2 |
|
3 | 3 | import { AppPlatform } from './graphql/generated'; |
| 4 | +import Log from './log'; |
4 | 5 | import { promptAsync } from './prompts'; |
5 | 6 |
|
6 | 7 | export const appPlatformDisplayNames: Record<AppPlatform, string> = { |
@@ -47,21 +48,42 @@ export async function selectRequestedPlatformAsync(platform?: string): Promise<R |
47 | 48 | return requestedPlatform; |
48 | 49 | } |
49 | 50 |
|
| 51 | +export async function selectPlatformWithExitOptionAsync(platform?: string): Promise<Platform> { |
| 52 | + return await selectPlatformInternalAsync(platform, true); |
| 53 | +} |
50 | 54 | export async function selectPlatformAsync(platform?: string): Promise<Platform> { |
| 55 | + return await selectPlatformInternalAsync(platform, false); |
| 56 | +} |
| 57 | + |
| 58 | +async function selectPlatformInternalAsync( |
| 59 | + platform?: string, |
| 60 | + allowExit?: boolean |
| 61 | +): Promise<Platform> { |
51 | 62 | if (platform && Object.values(Platform).includes(platform.toLowerCase() as Platform)) { |
52 | 63 | return platform.toLowerCase() as Platform; |
53 | 64 | } |
54 | 65 |
|
55 | | - const { resolvedPlatform } = await promptAsync({ |
| 66 | + const platformChoices: { title: string; value: Platform | 'Exit' }[] = [ |
| 67 | + { title: 'Android', value: Platform.ANDROID }, |
| 68 | + { title: 'iOS', value: Platform.IOS }, |
| 69 | + ]; |
| 70 | + |
| 71 | + if (allowExit) { |
| 72 | + platformChoices.push({ title: 'Exit', value: 'Exit' }); |
| 73 | + } |
| 74 | + |
| 75 | + const result: any = await promptAsync({ |
56 | 76 | type: 'select', |
57 | 77 | message: 'Select platform', |
58 | 78 | name: 'resolvedPlatform', |
59 | | - choices: [ |
60 | | - { title: 'Android', value: Platform.ANDROID }, |
61 | | - { title: 'iOS', value: Platform.IOS }, |
62 | | - ], |
| 79 | + choices: platformChoices, |
63 | 80 | }); |
64 | | - return resolvedPlatform; |
| 81 | + if (result.resolvedPlatform === 'Exit') { |
| 82 | + Log.addNewLineIfNone(); |
| 83 | + Log.log('Exiting'); |
| 84 | + process.exit(0); |
| 85 | + } |
| 86 | + return result.resolvedPlatform; |
65 | 87 | } |
66 | 88 |
|
67 | 89 | export function toPlatforms(requestedPlatform: RequestedPlatform): Platform[] { |
|
0 commit comments