xref: /expo/packages/@expo/cli/src/export/index.ts (revision dfd15ebd)
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 expoExport: Command = async (argv) => {
9  const args = assertArgs(
10    {
11      // Types
12      '--help': Boolean,
13      '--clear': Boolean,
14      '--dump-assetmap': Boolean,
15      '--dev': Boolean,
16      '--dump-sourcemap': Boolean,
17      '--max-workers': Number,
18      '--output-dir': String,
19      '--platform': String,
20
21      // Hack: This is added because EAS CLI always includes the flag.
22      // If supplied, we'll do nothing with the value, but at least the process won't crash.
23      // Note that we also don't show this value in the `--help` prompt since we don't want people to use it.
24      '--experimental-bundle': Boolean,
25
26      // Aliases
27      '-h': '--help',
28      // '-s': '--dump-sourcemap',
29      // '-d': '--dump-assetmap',
30      '-c': '--clear',
31      '-p': '--platform',
32    },
33    argv
34  );
35
36  if (args['--help']) {
37    printHelp(
38      `Export the static files of the app for hosting it on a web server`,
39      chalk`npx expo export {dim <dir>}`,
40      [
41        chalk`<dir>                      Directory of the Expo project. {dim Default: Current working directory}`,
42        `--dev                      Configure static files for developing locally using a non-https server`,
43        chalk`--output-dir <dir>         The directory to export the static files to. {dim Default: dist}`,
44        `--max-workers <number>     Maximum number of tasks to allow the bundler to spawn`,
45        `--dump-assetmap            Dump the asset map for further processing`,
46        `--dump-sourcemap           Dump the source map for debugging the JS bundle`,
47        chalk`-p, --platform <platform>  Options: android, ios, web, all. {dim Default: all}`,
48        `-c, --clear                Clear the bundler cache`,
49        `-h, --help                 Usage info`,
50      ].join('\n')
51    );
52  }
53
54  const projectRoot = getProjectRoot(args);
55  const { resolveOptionsAsync } = await import('./resolveOptions');
56  const options = await resolveOptionsAsync(projectRoot, args).catch(logCmdError);
57
58  const { exportAsync } = await import('./exportAsync');
59  return exportAsync(projectRoot, options).catch(logCmdError);
60};
61