xref: /expo/tools/src/commands/PromotePackages.ts (revision a272999e)
1import { Command } from '@expo/commander';
2
3import { TaskRunner, Task } from '../TasksRunner';
4import { listPackagesToPromote } from '../promote-packages/tasks/listPackagesToPromote';
5import { promotePackages } from '../promote-packages/tasks/promotePackages';
6import { CommandOptions, TaskArgs } from '../promote-packages/types';
7
8export default (program: Command) => {
9  program
10    .command('promote-packages [packageNames...]')
11    .alias('promote-pkgs')
12    .option(
13      '-e, --exclude <packageName>',
14      'Name of the package to be excluded from promoting. Can be passed multiple times to exclude more than one package. It has higher priority than the list of package names to promote.',
15      (value, previous) => previous.concat(value),
16      []
17    )
18    .option(
19      '-t, --tag <tag>',
20      'Tag to which packages should be promoted. Defaults to `latest`.',
21      'latest'
22    )
23    .option(
24      '--no-select',
25      'With this flag the script will not prompt to select packages, they all will be selected by default.',
26      false
27    )
28    .option(
29      '--no-drop',
30      'Without this flag, existing tags for the local version would be dropped after all.',
31      false
32    )
33    .option(
34      '-d, --demote',
35      'Enables tag demoting. If passed, the tag can be overriden even if its current version is higher than locally.',
36      false
37    )
38    .option(
39      '-l, --list',
40      'Lists packages with unpublished changes since the previous version.',
41      false
42    )
43
44    /* debug */
45    .option('-D, --dry', 'Whether to skip `npm dist-tag add` command.', false)
46
47    .description('Promotes local versions of monorepo packages to given tag on NPM repository.')
48    .asyncAction(async (packageNames: string[], options: CommandOptions) => {
49      // Commander doesn't put arguments to options object, let's add it for convenience. In fact, this is an option.
50      options.packageNames = packageNames;
51
52      const taskRunner = new TaskRunner<TaskArgs>({
53        tasks: tasksForOptions(options),
54      });
55
56      await taskRunner.runAndExitAsync([], options);
57    });
58};
59
60/**
61 * Returns target task instances based on provided command options.
62 */
63function tasksForOptions(options: CommandOptions): Task<TaskArgs>[] {
64  if (options.list) {
65    return [listPackagesToPromote];
66  }
67  return [promotePackages];
68}
69