xref: /expo/tools/src/utils/askForPlatformAsync.ts (revision eeffdb10)
1import inquirer from 'inquirer';
2
3import { Platform } from '../ProjectVersions';
4
5export default async function askForPlatformAsync(
6  platforms: Platform[] = ['ios', 'android']
7): Promise<Platform> {
8  if (process.env.CI) {
9    throw new Error(`Run with \`--platform <${platforms.join(' | ')}>\`.`);
10  }
11
12  if (platforms.length === 1) {
13    return platforms[0];
14  }
15
16  const { platform } = await inquirer.prompt<{ platform: Platform }>([
17    {
18      type: 'list',
19      name: 'platform',
20      message: 'For which platform you want to run this script?',
21      default: platforms[0],
22      choices: platforms,
23    },
24  ]);
25  return platform;
26}
27