1import { Command } from '@expo/commander';
2
3import androidUpdateNativeDependencies, { Options } from '../android-update-native-dependencies';
4import { REVISIONS } from '../android-update-native-dependencies/androidProjectReports';
5
6const PLATFORMS = ['android', 'ios'];
7
8function validateOptions(options: Options) {
9  if (!REVISIONS.includes(options.revision)) {
10    throw new Error(`--revision must be one of ${REVISIONS.join(', ')}`);
11  }
12  if (!PLATFORMS.includes(options.platform)) {
13    throw new Error(`--platform must be one of ${PLATFORMS.join(', ')}`);
14  }
15}
16
17async function asyncAction(options: Options): Promise<void> {
18  validateOptions(options);
19  switch (options.platform) {
20    case 'android':
21      await androidUpdateNativeDependencies(options);
22      break;
23    case 'ios':
24      throw new Error('Not implemented yet');
25    default:
26  }
27}
28
29export default (program: Command) => {
30  program
31    .command('update-native-dependencies')
32    .option(
33      '-r, --revision <release>',
34      `The revision controls the Ivy resolution strategy for determining what constitutes the latest version of a native dependency. See https://github.com/ben-manes/gradle-versions-plugin#revisions for more. Available values are: ${REVISIONS.join(
35        ', '
36      )}`,
37      'release'
38    )
39    .option('-l, --list', 'List all available native dependencies updates.', false)
40    .option(
41      '-c, --clear-cache',
42      'By default gradle task results are cached using date-based cache. You can use this flag to clear this cache.',
43      false
44    )
45    .option(
46      '-p, --platform [string]',
47      'Platform for which the client will be installed.',
48      'android'
49    )
50    .description(
51      'Updates Android native dependencies in all projects/packages. This command bases heavily on results produced by https://github.com/ben-manes/gradle-versions-plugin.'
52    )
53    .asyncAction(asyncAction);
54};
55