xref: /expo/packages/@expo/cli/src/run/ios/index.ts (revision 4bf00a55)
1#!/usr/bin/env node
2import arg from 'arg';
3import chalk from 'chalk';
4import path from 'path';
5
6import { XcodeConfiguration } from './XcodeBuild.types';
7import { Command } from '../../../bin/cli';
8import { assertWithOptionsArgs, printHelp } from '../../utils/args';
9import { logCmdError } from '../../utils/errors';
10
11export const expoRunIos: Command = async (argv) => {
12  const rawArgsMap: arg.Spec = {
13    // Types
14    '--help': Boolean,
15    '--no-build-cache': Boolean,
16    '--no-install': Boolean,
17    '--no-bundler': Boolean,
18    '--configuration': String,
19
20    '--port': Number,
21    // Aliases
22    '-p': '--port',
23
24    '-h': '--help',
25  };
26  const args = assertWithOptionsArgs(rawArgsMap, {
27    argv,
28
29    permissive: true,
30  });
31
32  // '-d' -> '--device': Boolean,
33  // '--scheme': String,
34
35  if (args['--help']) {
36    printHelp(
37      `Run the iOS app binary locally`,
38      `npx expo run:ios`,
39      [
40        `--no-build-cache                 Clear the native derived data before building`,
41        `--no-install                     Skip installing dependencies`,
42        `--no-bundler                     Skip starting the Metro bundler`,
43        `--scheme [scheme]                Scheme to build`,
44        chalk`--configuration <configuration>  Xcode configuration to use. Debug or Release. {dim Default: Debug}`,
45        `-d, --device [device]            Device name or UDID to build the app on`,
46        chalk`-p, --port <port>                Port to start the Metro bundler on. {dim Default: 8081}`,
47        `-h, --help                       Usage info`,
48      ].join('\n'),
49      [
50        '',
51        chalk`  Build for production (unsigned) with the {bold Release} configuration:`,
52        chalk`    {dim $} npx expo run:ios --configuration Release`,
53        '',
54      ].join('\n')
55    );
56  }
57
58  const { resolveStringOrBooleanArgsAsync } = await import('../../utils/resolveArgs');
59  const parsed = await resolveStringOrBooleanArgsAsync(argv ?? [], rawArgsMap, {
60    '--scheme': Boolean,
61    '--device': Boolean,
62    '-d': '--device',
63  }).catch(logCmdError);
64
65  const { runIosAsync } = await import('./runIosAsync');
66  return runIosAsync(path.resolve(parsed.projectRoot), {
67    // Parsed options
68    buildCache: !args['--no-build-cache'],
69    install: !args['--no-install'],
70    bundler: !args['--no-bundler'],
71    port: args['--port'],
72
73    // Custom parsed args
74    device: parsed.args['--device'],
75    scheme: parsed.args['--scheme'],
76    configuration: parsed.args['--configuration'] as XcodeConfiguration,
77  }).catch(logCmdError);
78};
79