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