xref: /expo/packages/@expo/cli/src/start/index.ts (revision b7576b8a)
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      '--private-key-path': String,
19      '--port': Number,
20      '--dev-client': Boolean,
21      '--scheme': String,
22      '--android': Boolean,
23      '--ios': Boolean,
24      '--web': Boolean,
25      '--host': String,
26      '--tunnel': Boolean,
27      '--lan': Boolean,
28      '--localhost': Boolean,
29      '--offline': Boolean,
30      '--go': 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      '-d': '--dev-client',
40      '-g': '--go',
41      // Alias for adding interop with the Metro docs and RedBox errors.
42      '--reset-cache': '--clear',
43    },
44    argv
45  );
46
47  if (args['--help']) {
48    printHelp(
49      `Start a local dev server for the app`,
50      chalk`npx expo start {dim <dir>}`,
51      [
52        chalk`<dir>                           Directory of the Expo project. {dim Default: Current working directory}`,
53        `-a, --android                   Open on a connected Android device`,
54        `-i, --ios                       Open in an iOS simulator`,
55        `-w, --web                       Open in a web browser`,
56        ``,
57        chalk`-d, --dev-client                Launch in a custom native app`,
58        chalk`-g, --go                        Launch in Expo Go`,
59        ``,
60        `-c, --clear                     Clear the bundler cache`,
61        `--max-workers <number>          Maximum number of tasks to allow Metro to spawn`,
62        `--no-dev                        Bundle in production mode`,
63        `--minify                        Minify JavaScript`,
64        ``,
65        chalk`-m, --host <string>             Dev server hosting type. {dim Default: lan}`,
66        chalk`                                {bold lan}: Use the local network`,
67        chalk`                                {bold tunnel}: Use any network by tunnel through ngrok`,
68        chalk`                                {bold 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        chalk`-p, --port <number>             Port to start the dev server on (does not apply to web or tunnel). {dim Default: 8081}`,
77        ``,
78        chalk`--private-key-path <path>       Path to private key for code signing. {dim Default: "private-key.pem" in the same directory as the certificate specified by the expo-updates configuration in app.json.}`,
79        `-h, --help                      Usage info`,
80      ].join('\n')
81    );
82  }
83
84  const projectRoot = getProjectRoot(args);
85  const { resolveOptionsAsync } = await import('./resolveOptions.js');
86  const options = await resolveOptionsAsync(projectRoot, args).catch(logCmdError);
87
88  if (options.offline) {
89    const { disableNetwork } = await import('../api/settings.js');
90    disableNetwork();
91  }
92
93  const { startAsync } = await import('./startAsync.js');
94  return startAsync(projectRoot, options, { webOnly: false }).catch(logCmdError);
95};
96