xref: /expo/packages/@expo/cli/src/export/index.ts (revision 104f0ac7)
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    },
32    argv
33  );
34
35  if (args['--help']) {
36    printHelp(
37      `Export the static files of the app for hosting it on a web server`,
38      chalk`npx expo export {dim <dir>}`,
39      [
40        chalk`<dir>                   Directory of the Expo project. {dim Default: Current working directory}`,
41        chalk`--platform <platform>   Options: android, ios, web, all. {dim Default: all}`,
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        `-c, --clear             Clear the bundler cache`,
48        `-h, --help              Usage info`,
49      ].join('\n')
50    );
51  }
52
53  const projectRoot = getProjectRoot(args);
54  const { resolveOptionsAsync } = await import('./resolveOptions');
55  const options = await resolveOptionsAsync(projectRoot, args).catch(logCmdError);
56
57  const { exportAsync } = await import('./exportAsync');
58  return exportAsync(projectRoot, options).catch(logCmdError);
59};
60