xref: /expo/packages/@expo/cli/src/export/index.ts (revision bfcd021e)
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      // Aliases
20      '-h': '--help',
21      // '-s': '--dump-sourcemap',
22      // '-d': '--dump-assetmap',
23      '-c': '--clear',
24    },
25    argv
26  );
27
28  if (args['--help']) {
29    printHelp(
30      `Export the static files of the app for hosting it on a web server`,
31      chalk`npx expo export {dim <dir>}`,
32      [
33        chalk`<dir>                         Directory of the Expo project. {dim Default: Current working directory}`,
34        chalk`--platform <all|android|ios>  Platforms: android, ios, all. {dim Default: all}`,
35        `--dev                         Configure static files for developing locally using a non-https server`,
36        chalk`--output-dir <dir>            The directory to export the static files to. {dim Default: dist}`,
37        `--max-workers <number>        Maximum number of tasks to allow the bundler to spawn`,
38        `--dump-assetmap               Dump the asset map for further processing`,
39        `--dump-sourcemap              Dump the source map for debugging the JS bundle`,
40        `-c, --clear                   Clear the bundler cache`,
41        `-h, --help                    Usage info`,
42      ].join('\n')
43    );
44  }
45
46  const projectRoot = getProjectRoot(args);
47  const { resolveOptionsAsync } = await import('./resolveOptions');
48  const options = await resolveOptionsAsync(args).catch(logCmdError);
49
50  const { exportAsync } = await import('./exportAsync');
51  return exportAsync(projectRoot, options).catch(logCmdError);
52};
53