xref: /expo/packages/@expo/cli/src/start/index.ts (revision e62686cb)
1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from '../../bin/cli';
5import { assertArgs, getProjectRoot, printHelp } from '../utils/args';
6import { logCmdError } from '../utils/errors';
7
8export const expoStart: Command = async (argv) => {
9  const args = assertArgs(
10    {
11      // Types
12      '--help': Boolean,
13      '--clear': Boolean,
14      '--max-workers': Number,
15      '--no-dev': Boolean,
16      '--minify': Boolean,
17      '--https': Boolean,
18      '--force-manifest-type': String,
19      '--private-key-path': 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      // Alias for adding interop with the Metro docs and RedBox errors.
40      '--reset-cache': '--clear',
41    },
42    argv
43  );
44
45  if (args['--help']) {
46    printHelp(
47      `Start a local dev server for the app`,
48      chalk`npx expo start {dim <dir>}`,
49      [
50        chalk`<dir>                                  Directory of the Expo project. {dim Default: Current working directory}`,
51        `-a, --android                          Opens your app in Expo Go on a connected Android device`,
52        `-i, --ios                              Opens your app in Expo Go in a currently running iOS simulator on your computer`,
53        `-w, --web                              Opens your app in a web browser`,
54        ``,
55        `-c, --clear                            Clear the bundler cache`,
56        `--max-workers <num>                    Maximum number of tasks to allow Metro to spawn`,
57        `--no-dev                               Bundle in production mode`,
58        `--minify                               Minify JavaScript`,
59        ``,
60        chalk`-m, --host <mode>                      Dev server hosting type. {dim Default: lan}`,
61        chalk`                                       {bold lan}: Use the local network`,
62        chalk`                                       {bold tunnel}: Use any network by tunnel through ngrok`,
63        chalk`                                       {bold localhost}: Connect to the dev server over localhost`,
64        `--tunnel                               Same as --host tunnel`,
65        `--lan                                  Same as --host lan`,
66        `--localhost                            Same as --host localhost`,
67        ``,
68        `--offline                              Skip network requests and use anonymous manifest signatures`,
69        `--https                                Start the dev server with https protocol`,
70        `--scheme <scheme>                      Custom URI protocol to use when launching an app`,
71        chalk`-p, --port <port>                      Port to start the dev server on (does not apply to web or tunnel). {dim Default: 19000}`,
72        ``,
73        chalk`--dev-client                           {yellow Experimental:} Starts the bundler for use with the expo-development-client`,
74        `--force-manifest-type <manifest-type>  Override auto detection of manifest type`,
75        `--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.`,
76        `-h, --help                             Usage info`,
77      ].join('\n')
78    );
79  }
80
81  const projectRoot = getProjectRoot(args);
82  const { resolveOptionsAsync } = await import('./resolveOptions');
83  const options = await resolveOptionsAsync(projectRoot, args).catch(logCmdError);
84
85  const { APISettings } = await import('../api/settings');
86  APISettings.isOffline = options.offline;
87
88  const { startAsync } = await import('./startAsync');
89  return startAsync(projectRoot, options, { webOnly: false }).catch(logCmdError);
90};
91