xref: /expo/packages/@expo/cli/src/start/index.ts (revision e89a8b74)
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      '--go': 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      '-d': '--dev-client',
41      '-g': '--go',
42      // Alias for adding interop with the Metro docs and RedBox errors.
43      '--reset-cache': '--clear',
44    },
45    argv
46  );
47
48  if (args['--help']) {
49    printHelp(
50      `Start a local dev server for the app`,
51      chalk`npx expo start {dim <dir>}`,
52      [
53        chalk`<dir>                                  Directory of the Expo project. {dim Default: Current working directory}`,
54        `-a, --android                          Open on a connected Android device`,
55        `-i, --ios                              Open in an iOS simulator`,
56        `-w, --web                              Open in a web browser`,
57        ``,
58        chalk`-d, --dev-client                       Launch in a custom native app`,
59        chalk`-g, --go                               Launch in Expo Go`,
60        ``,
61        `-c, --clear                            Clear the bundler cache`,
62        `--max-workers <number>                 Maximum number of tasks to allow Metro to spawn`,
63        `--no-dev                               Bundle in production mode`,
64        `--minify                               Minify JavaScript`,
65        ``,
66        chalk`-m, --host <mode>                      Dev server hosting type. {dim Default: lan}`,
67        chalk`                                       {bold lan}: Use the local network`,
68        chalk`                                       {bold tunnel}: Use any network by tunnel through ngrok`,
69        chalk`                                       {bold 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        chalk`-p, --port <number>                    Port to start the dev server on (does not apply to web or tunnel). {dim Default: 8081}`,
78        ``,
79        `--force-manifest-type <manifest-type>  Override auto detection of manifest type`,
80        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.}`,
81        `-h, --help                             Usage info`,
82      ].join('\n')
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