xref: /expo/packages/@expo/cli/src/run/android/index.ts (revision bb5069cd)
1#!/usr/bin/env node
2import arg from 'arg';
3import chalk from 'chalk';
4import path from 'path';
5
6import { Command } from '../../../bin/cli';
7import * as Log from '../../log';
8import { assertWithOptionsArgs } from '../../utils/args';
9import { logCmdError } from '../../utils/errors';
10
11export const expoRunAndroid: Command = async (argv) => {
12  const rawArgsMap: arg.Spec = {
13    // Types
14    '--help': Boolean,
15    '--no-build-cache': Boolean,
16    '--no-install': Boolean,
17    '--no-bundler': Boolean,
18    '--variant': String,
19
20    '--port': Number,
21    // Aliases
22    '-p': '--port',
23
24    '-h': '--help',
25  };
26  const args = assertWithOptionsArgs(rawArgsMap, {
27    argv,
28
29    permissive: true,
30  });
31
32  // '-d' -> '--device': Boolean,
33
34  if (args['--help']) {
35    Log.exit(
36      chalk`
37  {bold Description}
38    Run the native Android app locally
39
40  {bold Usage}
41    $ npx expo run:android <dir>
42
43  {bold Options}
44    --no-build-cache       Clear the native build cache
45    --no-install           Skip installing dependencies
46    --no-bundler           Skip starting the bundler
47    --variant <name>       Build variant. {dim Default: debug}
48    -d, --device [device]  Device name to run the app on
49    -p, --port <port>      Port to start the dev server on. {dim Default: 8081}
50    -h, --help             Output usage information
51`,
52      0
53    );
54  }
55
56  const { resolveStringOrBooleanArgsAsync } = await import('../../utils/resolveArgs');
57  const parsed = await resolveStringOrBooleanArgsAsync(argv ?? [], rawArgsMap, {
58    '--device': Boolean,
59    '-d': '--device',
60  }).catch(logCmdError);
61
62  const { runAndroidAsync } = await import('./runAndroidAsync');
63
64  return runAndroidAsync(path.resolve(parsed.projectRoot), {
65    // Parsed options
66    buildCache: !args['--no-build-cache'],
67    install: !args['--no-install'],
68    bundler: !args['--no-bundler'],
69    port: args['--port'],
70    variant: args['--variant'],
71
72    // Custom parsed args
73    device: parsed.args['--device'],
74  }).catch(logCmdError);
75};
76