xref: /expo/packages/@expo/cli/src/start/index.ts (revision e5f02478)
1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from '../../bin/cli';
5import * as Log from '../log';
6import { assertArgs, getProjectRoot } from '../utils/args';
7import { logCmdError } from '../utils/errors';
8
9export const expoStart: Command = async (argv) => {
10  const args = assertArgs(
11    {
12      // Types
13      '--help': Boolean,
14      '--clear': Boolean,
15      '--max-workers': Number,
16      '--no-dev': Boolean,
17      '--minify': Boolean,
18      '--https': Boolean,
19      '--force-manifest-type': String,
20      '--port': Number,
21      '--dev-client': Boolean,
22      '--scheme': String,
23      '--android': Boolean,
24      '--ios': Boolean,
25      '--web': Boolean,
26      '--host': String,
27      '--tunnel': Boolean,
28      '--lan': Boolean,
29      '--localhost': Boolean,
30      '--offline': Boolean,
31      // Aliases
32      '-h': '--help',
33      '-c': '--clear',
34      '-p': '--port',
35      '-a': '--android',
36      '-i': '--ios',
37      '-w': '--web',
38      '-m': '--host',
39    },
40    argv
41  );
42
43  if (args['--help']) {
44    Log.exit(
45      chalk`
46  {bold Description}
47    Start a local dev server for the app
48
49  {bold Usage}
50    $ npx expo start <dir>
51
52  <dir> is the directory of the Expo project.
53  Defaults to the current working directory.
54
55  {bold Options}
56    -a, --android                          Opens your app in Expo Go on a connected Android device
57    -i, --ios                              Opens your app in Expo Go in a currently running iOS simulator on your computer
58    -w, --web                              Opens your app in a web browser
59
60    -c, --clear                            Clear the bundler cache
61    --max-workers <num>                    Maximum number of tasks to allow Metro to spawn
62    --no-dev                               Bundle in production mode
63    --minify                               Minify JavaScript
64
65    -m, --host <mode>                      lan, tunnel, localhost. Dev server hosting type. Default: lan.
66                                           - lan: Use the local network
67                                           - tunnel: Use any network by tunnel through ngrok
68                                           - localhost: Connect to the dev server over localhost
69    --tunnel                               Same as --host tunnel
70    --lan                                  Same as --host lan
71    --localhost                            Same as --host localhost
72
73    --offline                              Skip network requests and use anonymous manifest signatures
74    --https                                Start the dev server with https protocol
75    --scheme <scheme>                      Custom URI protocol to use when launching an app
76    -p, --port <port>                      Port to start the dev server on (does not apply to web or tunnel). Default: 19000
77
78    --dev-client                           Experimental: Starts the bundler for use with the expo-development-client
79    --force-manifest-type <manifest-type>  Override auto detection of manifest type
80    -h, --help                             output usage information
81`,
82      0
83    );
84  }
85
86  const projectRoot = getProjectRoot(args);
87  const { resolveOptionsAsync } = await import('./resolveOptions');
88  const options = await resolveOptionsAsync(projectRoot, args).catch(logCmdError);
89
90  const { APISettings } = await import('../api/settings');
91  APISettings.isOffline = options.offline;
92
93  const { startAsync } = await import('./startAsync');
94  return startAsync(projectRoot, options, { webOnly: false }).catch(logCmdError);
95};
96