1#!/usr/bin/env node 2import chalk from 'chalk'; 3 4import { Command } from '../../bin/cli'; 5import * as Log from '../log'; 6import { assertArgs, getProjectRoot } from '../utils/args'; 7 8export const expoPrebuild: Command = async (argv) => { 9 const args = assertArgs( 10 { 11 // Types 12 '--help': Boolean, 13 '--clean': Boolean, 14 '--npm': Boolean, 15 '--no-install': Boolean, 16 '--template': String, 17 '--platform': String, 18 '--skip-dependency-update': String, 19 // Aliases 20 '-h': '--help', 21 '-p': '--platform', 22 '-t': '--type', 23 }, 24 argv 25 ); 26 27 if (args['--help']) { 28 Log.exit( 29 chalk` 30 {bold Description} 31 Create native iOS and Android project files before building natively. 32 33 {bold Usage} 34 $ npx expo prebuild <dir> 35 36 <dir> is the directory of the Expo project. 37 Defaults to the current working directory. 38 39 Options 40 --no-install Skip installing npm packages and CocoaPods. 41 --clean Delete the native folders and regenerate them before applying changes 42 --npm Use npm to install dependencies. (default when Yarn is not installed) 43 --template <template> Project template to clone from. File path pointing to a local tar file or a github repo 44 -p, --platform <all|android|ios> Platforms to sync: ios, android, all. Default: all 45 --skip-dependency-update <dependencies> Preserves versions of listed packages in package.json (comma separated list) 46 -h, --help Output usage information 47 48 `, 49 0 50 ); 51 } 52 53 // Load modules after the help prompt so `npx expo prebuild -h` shows as fast as possible. 54 const [ 55 // ./prebuildAsync 56 { prebuildAsync }, 57 // ./resolveOptions 58 { resolvePlatformOption, resolveSkipDependencyUpdate }, 59 // ../utils/errors 60 { logCmdError }, 61 ] = await Promise.all([ 62 import('./prebuildAsync'), 63 import('./resolveOptions'), 64 import('../utils/errors'), 65 ]); 66 67 return prebuildAsync(getProjectRoot(args), { 68 // Parsed options 69 clean: args['--clean'], 70 packageManager: args['--npm'] ? 'npm' : 'yarn', 71 install: !args['--no-install'], 72 platforms: resolvePlatformOption(args['--platform']), 73 // TODO: Parse 74 skipDependencyUpdate: resolveSkipDependencyUpdate(args['--skip-dependency-update']), 75 template: args['--template'], 76 }).catch(logCmdError); 77}; 78