1b6b91c50SEvan Bacon#!/usr/bin/env node 2b6b91c50SEvan Baconimport arg from 'arg'; 3b6b91c50SEvan Baconimport chalk from 'chalk'; 4b6b91c50SEvan Baconimport path from 'path'; 5b6b91c50SEvan Bacon 6b6b91c50SEvan Baconimport { Command } from '../../../bin/cli'; 7b6b91c50SEvan Baconimport { assertWithOptionsArgs, printHelp } from '../../utils/args'; 8b6b91c50SEvan Bacon 9b6b91c50SEvan Baconexport const expoExportEmbed: Command = async (argv) => { 10b6b91c50SEvan Bacon const rawArgsMap: arg.Spec = { 11b6b91c50SEvan Bacon // Types 12b6b91c50SEvan Bacon '--entry-file': String, 13b6b91c50SEvan Bacon '--platform': String, 14b6b91c50SEvan Bacon '--transformer': String, 15b6b91c50SEvan Bacon '--bundle-output': String, 16b6b91c50SEvan Bacon '--bundle-encoding': String, 17b6b91c50SEvan Bacon '--max-workers': Number, 18b6b91c50SEvan Bacon '--sourcemap-output': String, 19b6b91c50SEvan Bacon '--sourcemap-sources-root': String, 20b6b91c50SEvan Bacon '--assets-dest': String, 21b6b91c50SEvan Bacon '--asset-catalog-dest': String, 22b6b91c50SEvan Bacon '--unstable-transform-profile': String, 23b6b91c50SEvan Bacon '--config': String, 24b6b91c50SEvan Bacon 25b6b91c50SEvan Bacon // This is here for compatibility with the `npx react-native bundle` command. 26b6b91c50SEvan Bacon // devs should use `DEBUG=expo:*` instead. 27b6b91c50SEvan Bacon '--verbose': Boolean, 28b6b91c50SEvan Bacon '--help': Boolean, 29b6b91c50SEvan Bacon // Aliases 30b6b91c50SEvan Bacon '-h': '--help', 31b6b91c50SEvan Bacon '-v': '--verbose', 32b6b91c50SEvan Bacon }; 33b6b91c50SEvan Bacon const args = assertWithOptionsArgs(rawArgsMap, { 34b6b91c50SEvan Bacon argv, 35b6b91c50SEvan Bacon permissive: true, 36b6b91c50SEvan Bacon }); 37b6b91c50SEvan Bacon 38b6b91c50SEvan Bacon if (args['--help']) { 39b6b91c50SEvan Bacon printHelp( 40b6b91c50SEvan Bacon `(Internal) Export the JavaScript bundle during a native build script for embedding in a native binary`, 41b6b91c50SEvan Bacon chalk`npx expo export:embed {dim <dir>}`, 42b6b91c50SEvan Bacon [ 43b6b91c50SEvan Bacon chalk`<dir> Directory of the Expo project. {dim Default: Current working directory}`, 44b6b91c50SEvan Bacon `--entry-file <path> Path to the root JS file, either absolute or relative to JS root`, 45b6b91c50SEvan Bacon `--platform <string> Either "ios" or "android" (default: "ios")`, 46b6b91c50SEvan Bacon `--transformer <string> Specify a custom transformer to be used`, 47b6b91c50SEvan Bacon `--dev [boolean] If false, warnings are disabled and the bundle is minified (default: true)`, 48b6b91c50SEvan Bacon `--minify [boolean] Allows overriding whether bundle is minified. This defaults to false if dev is true, and true if dev is false. Disabling minification can be useful for speeding up production builds for testing purposes.`, 49b6b91c50SEvan Bacon `--bundle-output <string> File name where to store the resulting bundle, ex. /tmp/groups.bundle`, 50b6b91c50SEvan Bacon `--bundle-encoding <string> Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: "utf8")`, 51b6b91c50SEvan Bacon `--max-workers <number> Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine.`, 52b6b91c50SEvan Bacon `--sourcemap-output <string> File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map`, 53b6b91c50SEvan Bacon `--sourcemap-sources-root <string> Path to make sourcemap's sources entries relative to, ex. /root/dir`, 54b6b91c50SEvan Bacon `--sourcemap-use-absolute-path Report SourceMapURL using its full path`, 55b6b91c50SEvan Bacon `--assets-dest <string> Directory name where to store assets referenced in the bundle`, 56b6b91c50SEvan Bacon `--asset-catalog-dest <string> Directory to create an iOS Asset Catalog for images`, 57b6b91c50SEvan Bacon `--unstable-transform-profile <string> Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default`, 58b6b91c50SEvan Bacon `--reset-cache Removes cached files`, 59b6b91c50SEvan Bacon `-v, --verbose Enables debug logging`, 60b6b91c50SEvan Bacon 61b6b91c50SEvan Bacon `--config <string> Path to the CLI configuration file`, 62b6b91c50SEvan Bacon // This is seemingly unused. 63b6b91c50SEvan Bacon `--read-global-cache Try to fetch transformed JS code from the global cache, if configured.`, 64b6b91c50SEvan Bacon 65b6b91c50SEvan Bacon `-h, --help Usage info`, 66b6b91c50SEvan Bacon ].join('\n') 67b6b91c50SEvan Bacon ); 68b6b91c50SEvan Bacon } 69b6b91c50SEvan Bacon 70b6b91c50SEvan Bacon const [ 71b6b91c50SEvan Bacon { exportEmbedAsync }, 72b6b91c50SEvan Bacon { resolveOptions }, 73b6b91c50SEvan Bacon { logCmdError }, 74b6b91c50SEvan Bacon { resolveCustomBooleanArgsAsync }, 75b6b91c50SEvan Bacon ] = await Promise.all([ 76*1a3a1db5SEvan Bacon import('./exportEmbedAsync.js'), 77*1a3a1db5SEvan Bacon import('./resolveOptions.js'), 78*1a3a1db5SEvan Bacon import('../../utils/errors.js'), 79*1a3a1db5SEvan Bacon import('../../utils/resolveArgs.js'), 80b6b91c50SEvan Bacon ]); 81b6b91c50SEvan Bacon 82b6b91c50SEvan Bacon return (async () => { 83b6b91c50SEvan Bacon const parsed = await resolveCustomBooleanArgsAsync(argv ?? [], rawArgsMap, { 84b6b91c50SEvan Bacon '--dev': Boolean, 85b6b91c50SEvan Bacon '--minify': Boolean, 86b6b91c50SEvan Bacon '--sourcemap-use-absolute-path': Boolean, 87b6b91c50SEvan Bacon '--reset-cache': Boolean, 88b6b91c50SEvan Bacon '--read-global-cache': Boolean, 89b6b91c50SEvan Bacon }); 90b6b91c50SEvan Bacon return exportEmbedAsync(path.resolve(parsed.projectRoot), resolveOptions(args, parsed)); 91b6b91c50SEvan Bacon })().catch(logCmdError); 92b6b91c50SEvan Bacon}; 93