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