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