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