appium 3.2.2 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/build/lib/appium.d.ts +147 -205
  2. package/build/lib/appium.d.ts.map +1 -1
  3. package/build/lib/appium.js +169 -282
  4. package/build/lib/appium.js.map +1 -1
  5. package/build/lib/bidi-commands.d.ts.map +1 -1
  6. package/build/lib/bidi-commands.js +11 -11
  7. package/build/lib/bidi-commands.js.map +1 -1
  8. package/build/lib/bootstrap/appium-initializer.d.ts +21 -0
  9. package/build/lib/bootstrap/appium-initializer.d.ts.map +1 -0
  10. package/build/lib/bootstrap/appium-initializer.js +146 -0
  11. package/build/lib/bootstrap/appium-initializer.js.map +1 -0
  12. package/build/lib/bootstrap/appium-main-runner.d.ts +22 -0
  13. package/build/lib/bootstrap/appium-main-runner.d.ts.map +1 -0
  14. package/build/lib/bootstrap/appium-main-runner.js +109 -0
  15. package/build/lib/bootstrap/appium-main-runner.js.map +1 -0
  16. package/build/lib/bootstrap/config-file.d.ts +37 -0
  17. package/build/lib/bootstrap/config-file.d.ts.map +1 -0
  18. package/build/lib/{config-file.js → bootstrap/config-file.js} +62 -138
  19. package/build/lib/bootstrap/config-file.js.map +1 -0
  20. package/build/lib/bootstrap/grid-v3-register.d.ts +20 -0
  21. package/build/lib/bootstrap/grid-v3-register.d.ts.map +1 -0
  22. package/build/lib/bootstrap/grid-v3-register.js +185 -0
  23. package/build/lib/bootstrap/grid-v3-register.js.map +1 -0
  24. package/build/lib/bootstrap/init-types.d.ts +16 -0
  25. package/build/lib/bootstrap/init-types.d.ts.map +1 -0
  26. package/build/lib/bootstrap/init-types.js +3 -0
  27. package/build/lib/bootstrap/init-types.js.map +1 -0
  28. package/build/lib/bootstrap/main-helpers.d.ts +55 -0
  29. package/build/lib/bootstrap/main-helpers.d.ts.map +1 -0
  30. package/build/lib/bootstrap/main-helpers.js +187 -0
  31. package/build/lib/bootstrap/main-helpers.js.map +1 -0
  32. package/build/lib/bootstrap/node-helpers.d.ts +32 -0
  33. package/build/lib/bootstrap/node-helpers.d.ts.map +1 -0
  34. package/build/lib/bootstrap/node-helpers.js +201 -0
  35. package/build/lib/bootstrap/node-helpers.js.map +1 -0
  36. package/build/lib/bootstrap/startup-config.d.ts +22 -0
  37. package/build/lib/bootstrap/startup-config.d.ts.map +1 -0
  38. package/build/lib/bootstrap/startup-config.js +111 -0
  39. package/build/lib/bootstrap/startup-config.js.map +1 -0
  40. package/build/lib/cli/args.d.ts +16 -12
  41. package/build/lib/cli/args.d.ts.map +1 -1
  42. package/build/lib/cli/args.js +20 -40
  43. package/build/lib/cli/args.js.map +1 -1
  44. package/build/lib/cli/driver-command.d.ts +51 -93
  45. package/build/lib/cli/driver-command.d.ts.map +1 -1
  46. package/build/lib/cli/driver-command.js +11 -66
  47. package/build/lib/cli/driver-command.js.map +1 -1
  48. package/build/lib/cli/extension-command.d.ts +173 -377
  49. package/build/lib/cli/extension-command.d.ts.map +1 -1
  50. package/build/lib/cli/extension-command.js +387 -656
  51. package/build/lib/cli/extension-command.js.map +1 -1
  52. package/build/lib/cli/extension.d.ts +10 -15
  53. package/build/lib/cli/extension.d.ts.map +1 -1
  54. package/build/lib/cli/extension.js +15 -33
  55. package/build/lib/cli/extension.js.map +1 -1
  56. package/build/lib/cli/parser.d.ts +37 -66
  57. package/build/lib/cli/parser.d.ts.map +1 -1
  58. package/build/lib/cli/parser.js +69 -104
  59. package/build/lib/cli/parser.js.map +1 -1
  60. package/build/lib/cli/plugin-command.d.ts +50 -90
  61. package/build/lib/cli/plugin-command.d.ts.map +1 -1
  62. package/build/lib/cli/plugin-command.js +11 -63
  63. package/build/lib/cli/plugin-command.js.map +1 -1
  64. package/build/lib/cli/setup-command.d.ts +21 -26
  65. package/build/lib/cli/setup-command.d.ts.map +1 -1
  66. package/build/lib/cli/setup-command.js +19 -61
  67. package/build/lib/cli/setup-command.js.map +1 -1
  68. package/build/lib/cli/utils.d.ts +33 -35
  69. package/build/lib/cli/utils.d.ts.map +1 -1
  70. package/build/lib/cli/utils.js +48 -50
  71. package/build/lib/cli/utils.js.map +1 -1
  72. package/build/lib/constants.d.ts +23 -23
  73. package/build/lib/constants.d.ts.map +1 -1
  74. package/build/lib/constants.js +10 -15
  75. package/build/lib/constants.js.map +1 -1
  76. package/build/lib/doctor/doctor.d.ts +40 -57
  77. package/build/lib/doctor/doctor.d.ts.map +1 -1
  78. package/build/lib/doctor/doctor.js +31 -62
  79. package/build/lib/doctor/doctor.js.map +1 -1
  80. package/build/lib/extension/driver-config.d.ts +18 -77
  81. package/build/lib/extension/driver-config.d.ts.map +1 -1
  82. package/build/lib/extension/driver-config.js +37 -125
  83. package/build/lib/extension/driver-config.js.map +1 -1
  84. package/build/lib/extension/extension-config.d.ts +103 -210
  85. package/build/lib/extension/extension-config.d.ts.map +1 -1
  86. package/build/lib/extension/extension-config.js +180 -342
  87. package/build/lib/extension/extension-config.js.map +1 -1
  88. package/build/lib/extension/index.d.ts +12 -29
  89. package/build/lib/extension/index.d.ts.map +1 -1
  90. package/build/lib/extension/index.js +33 -75
  91. package/build/lib/extension/index.js.map +1 -1
  92. package/build/lib/extension/manifest-migrations.d.ts +3 -20
  93. package/build/lib/extension/manifest-migrations.d.ts.map +1 -1
  94. package/build/lib/extension/manifest-migrations.js +20 -101
  95. package/build/lib/extension/manifest-migrations.js.map +1 -1
  96. package/build/lib/extension/manifest.d.ts +61 -107
  97. package/build/lib/extension/manifest.d.ts.map +1 -1
  98. package/build/lib/extension/manifest.js +181 -356
  99. package/build/lib/extension/manifest.js.map +1 -1
  100. package/build/lib/extension/package-changed.d.ts +1 -3
  101. package/build/lib/extension/package-changed.d.ts.map +1 -1
  102. package/build/lib/extension/package-changed.js +8 -15
  103. package/build/lib/extension/package-changed.js.map +1 -1
  104. package/build/lib/extension/plugin-config.d.ts +10 -52
  105. package/build/lib/extension/plugin-config.d.ts.map +1 -1
  106. package/build/lib/extension/plugin-config.js +11 -63
  107. package/build/lib/extension/plugin-config.js.map +1 -1
  108. package/build/lib/helpers/build.d.ts +22 -0
  109. package/build/lib/helpers/build.d.ts.map +1 -0
  110. package/build/lib/helpers/build.js +109 -0
  111. package/build/lib/helpers/build.js.map +1 -0
  112. package/build/lib/helpers/capability.d.ts +38 -0
  113. package/build/lib/helpers/capability.d.ts.map +1 -0
  114. package/build/lib/helpers/capability.js +128 -0
  115. package/build/lib/helpers/capability.js.map +1 -0
  116. package/build/lib/helpers/network.d.ts +14 -0
  117. package/build/lib/helpers/network.d.ts.map +1 -0
  118. package/build/lib/helpers/network.js +35 -0
  119. package/build/lib/helpers/network.js.map +1 -0
  120. package/build/lib/insecure-features.js +6 -6
  121. package/build/lib/insecure-features.js.map +1 -1
  122. package/build/lib/inspector-commands.d.ts +6 -0
  123. package/build/lib/inspector-commands.d.ts.map +1 -1
  124. package/build/lib/inspector-commands.js +6 -0
  125. package/build/lib/inspector-commands.js.map +1 -1
  126. package/build/lib/logger.d.ts +2 -3
  127. package/build/lib/logger.d.ts.map +1 -1
  128. package/build/lib/logger.js +2 -3
  129. package/build/lib/logger.js.map +1 -1
  130. package/build/lib/logsink.d.ts +13 -22
  131. package/build/lib/logsink.d.ts.map +1 -1
  132. package/build/lib/logsink.js +48 -103
  133. package/build/lib/logsink.js.map +1 -1
  134. package/build/lib/main.d.ts +15 -58
  135. package/build/lib/main.d.ts.map +1 -1
  136. package/build/lib/main.js +25 -425
  137. package/build/lib/main.js.map +1 -1
  138. package/build/lib/schema/arg-spec.d.ts +32 -107
  139. package/build/lib/schema/arg-spec.d.ts.map +1 -1
  140. package/build/lib/schema/arg-spec.js +11 -107
  141. package/build/lib/schema/arg-spec.js.map +1 -1
  142. package/build/lib/schema/cli-args-guards.d.ts +34 -0
  143. package/build/lib/schema/cli-args-guards.d.ts.map +1 -0
  144. package/build/lib/schema/cli-args-guards.js +49 -0
  145. package/build/lib/schema/cli-args-guards.js.map +1 -0
  146. package/build/lib/schema/cli-args.d.ts +3 -15
  147. package/build/lib/schema/cli-args.d.ts.map +1 -1
  148. package/build/lib/schema/cli-args.js +17 -107
  149. package/build/lib/schema/cli-args.js.map +1 -1
  150. package/build/lib/schema/cli-transformers.d.ts +15 -12
  151. package/build/lib/schema/cli-transformers.d.ts.map +1 -1
  152. package/build/lib/schema/cli-transformers.js +15 -45
  153. package/build/lib/schema/cli-transformers.js.map +1 -1
  154. package/build/lib/schema/format-errors.d.ts +28 -0
  155. package/build/lib/schema/format-errors.d.ts.map +1 -0
  156. package/build/lib/schema/format-errors.js +29 -0
  157. package/build/lib/schema/format-errors.js.map +1 -0
  158. package/build/lib/schema/index.d.ts +4 -2
  159. package/build/lib/schema/index.d.ts.map +1 -1
  160. package/build/lib/schema/index.js +2 -0
  161. package/build/lib/schema/index.js.map +1 -1
  162. package/build/lib/schema/keywords.d.ts +12 -20
  163. package/build/lib/schema/keywords.d.ts.map +1 -1
  164. package/build/lib/schema/keywords.js +6 -51
  165. package/build/lib/schema/keywords.js.map +1 -1
  166. package/build/lib/schema/schema.d.ts +106 -231
  167. package/build/lib/schema/schema.d.ts.map +1 -1
  168. package/build/lib/schema/schema.js +88 -358
  169. package/build/lib/schema/schema.js.map +1 -1
  170. package/build/lib/utils.d.ts +7 -267
  171. package/build/lib/utils.d.ts.map +1 -1
  172. package/build/lib/utils.js +10 -409
  173. package/build/lib/utils.js.map +1 -1
  174. package/lib/{appium.js → appium.ts} +297 -341
  175. package/lib/bidi-commands.ts +10 -14
  176. package/lib/bootstrap/appium-initializer.ts +212 -0
  177. package/lib/bootstrap/appium-main-runner.ts +172 -0
  178. package/lib/bootstrap/config-file.ts +178 -0
  179. package/lib/bootstrap/grid-v3-register.ts +250 -0
  180. package/lib/bootstrap/init-types.ts +31 -0
  181. package/lib/bootstrap/main-helpers.ts +223 -0
  182. package/lib/bootstrap/node-helpers.ts +180 -0
  183. package/lib/bootstrap/startup-config.ts +143 -0
  184. package/lib/cli/{args.js → args.ts} +45 -56
  185. package/lib/cli/driver-command.ts +122 -0
  186. package/lib/cli/{extension-command.js → extension-command.ts} +827 -906
  187. package/lib/cli/extension.ts +65 -0
  188. package/lib/cli/{parser.js → parser.ts} +93 -116
  189. package/lib/cli/plugin-command.ts +117 -0
  190. package/lib/cli/{setup-command.js → setup-command.ts} +59 -74
  191. package/lib/cli/utils.ts +97 -0
  192. package/lib/{constants.js → constants.ts} +30 -41
  193. package/lib/doctor/{doctor.js → doctor.ts} +82 -92
  194. package/lib/extension/driver-config.ts +165 -0
  195. package/lib/extension/{extension-config.js → extension-config.ts} +291 -405
  196. package/lib/extension/index.ts +143 -0
  197. package/lib/extension/manifest-migrations.ts +57 -0
  198. package/lib/extension/manifest.ts +369 -0
  199. package/lib/extension/{package-changed.js → package-changed.ts} +9 -18
  200. package/lib/extension/plugin-config.ts +62 -0
  201. package/lib/helpers/build.ts +111 -0
  202. package/lib/helpers/capability.ts +171 -0
  203. package/lib/helpers/network.ts +30 -0
  204. package/lib/insecure-features.ts +1 -1
  205. package/lib/inspector-commands.ts +6 -1
  206. package/lib/{logger.js → logger.ts} +1 -2
  207. package/lib/{logsink.js → logsink.ts} +91 -137
  208. package/lib/main.ts +60 -0
  209. package/lib/schema/arg-spec.ts +131 -0
  210. package/lib/schema/cli-args-guards.ts +67 -0
  211. package/lib/schema/cli-args.ts +171 -0
  212. package/lib/schema/cli-transformers.ts +83 -0
  213. package/lib/schema/format-errors.ts +43 -0
  214. package/lib/schema/index.ts +4 -0
  215. package/lib/schema/keywords.ts +96 -0
  216. package/lib/schema/schema.ts +448 -0
  217. package/lib/utils.ts +73 -0
  218. package/package.json +17 -18
  219. package/scripts/autoinstall-extensions.js +3 -0
  220. package/build/lib/config-file.d.ts +0 -100
  221. package/build/lib/config-file.d.ts.map +0 -1
  222. package/build/lib/config-file.js.map +0 -1
  223. package/build/lib/config.d.ts +0 -70
  224. package/build/lib/config.d.ts.map +0 -1
  225. package/build/lib/config.js +0 -390
  226. package/build/lib/config.js.map +0 -1
  227. package/build/lib/grid-register.d.ts +0 -10
  228. package/build/lib/grid-register.d.ts.map +0 -1
  229. package/build/lib/grid-register.js +0 -134
  230. package/build/lib/grid-register.js.map +0 -1
  231. package/lib/cli/driver-command.js +0 -174
  232. package/lib/cli/extension.js +0 -74
  233. package/lib/cli/plugin-command.js +0 -164
  234. package/lib/cli/utils.js +0 -91
  235. package/lib/config-file.js +0 -228
  236. package/lib/config.js +0 -389
  237. package/lib/extension/driver-config.js +0 -245
  238. package/lib/extension/index.js +0 -169
  239. package/lib/extension/manifest-migrations.js +0 -136
  240. package/lib/extension/manifest.js +0 -550
  241. package/lib/extension/plugin-config.js +0 -112
  242. package/lib/grid-register.js +0 -146
  243. package/lib/main.js +0 -545
  244. package/lib/schema/arg-spec.js +0 -229
  245. package/lib/schema/cli-args.js +0 -254
  246. package/lib/schema/cli-transformers.js +0 -113
  247. package/lib/schema/index.js +0 -2
  248. package/lib/schema/keywords.js +0 -136
  249. package/lib/schema/schema.js +0 -725
  250. package/lib/utils.js +0 -512
@@ -0,0 +1,143 @@
1
+ /* eslint-disable no-console */
2
+ import _ from 'lodash';
3
+ import {getDefaultsForSchema, getAllArgSpecs} from '../schema/schema';
4
+ import type {Args} from 'appium/types';
5
+ import type {ReadConfigFileResult} from './config-file';
6
+
7
+ interface FlattenedArg {
8
+ value: unknown;
9
+ argSpec: {dest: string};
10
+ }
11
+
12
+ /**
13
+ * Returns key/value pairs of server arguments that differ from schema defaults (flattened comparison).
14
+ *
15
+ * @param parsedArgs - Fully merged server args (CLI + config + defaults)
16
+ */
17
+ export function getNonDefaultServerArgs(parsedArgs: Args): Args {
18
+ /**
19
+ * Flattens parsed args into a single level object for comparison with
20
+ * flattened defaults across server args and extension args.
21
+ */
22
+ const flatten = (args: Args): Record<string, FlattenedArg> => {
23
+ const argSpecs = getAllArgSpecs();
24
+ const flattened = _.reduce(
25
+ [...argSpecs.values()],
26
+ (acc: Record<string, FlattenedArg>, argSpec: {dest: string}) => {
27
+ if (_.has(args, argSpec.dest)) {
28
+ acc[argSpec.dest] = {value: _.get(args, argSpec.dest), argSpec};
29
+ }
30
+ return acc;
31
+ },
32
+ {}
33
+ );
34
+
35
+ return flattened;
36
+ };
37
+
38
+ const args = flatten(parsedArgs);
39
+
40
+ // hopefully these function names are descriptive enough
41
+ const typesDiffer = (dest: string): boolean =>
42
+ typeof args[dest].value !== typeof defaultsFromSchema[dest];
43
+
44
+ const defaultValueIsArray = (dest: string): boolean => _.isArray(defaultsFromSchema[dest]);
45
+
46
+ const argsValueIsArray = (dest: string): boolean => _.isArray(args[dest].value);
47
+
48
+ const arraysDiffer = (dest: string): boolean =>
49
+ _.gt(_.size(_.difference(args[dest].value as any[], defaultsFromSchema[dest] as any[])), 0);
50
+
51
+ const valuesDiffer = (dest: string): boolean => args[dest].value !== defaultsFromSchema[dest];
52
+
53
+ const defaultIsDefined = (dest: string): boolean => !_.isUndefined(defaultsFromSchema[dest]);
54
+
55
+ // note that `_.overEvery` is like an "AND", and `_.overSome` is like an "OR"
56
+ const argValueNotArrayOrArraysDiffer = _.overSome([_.negate(argsValueIsArray), arraysDiffer]);
57
+
58
+ const defaultValueNotArrayAndValuesDiffer = _.overEvery([
59
+ _.negate(defaultValueIsArray),
60
+ valuesDiffer,
61
+ ]);
62
+
63
+ /**
64
+ * This used to be a hideous conditional, but it's broken up into a hideous function instead.
65
+ * hopefully this makes things a little more understandable.
66
+ * - checks if the default value is defined
67
+ * - if so, and the default is not an array:
68
+ * - ensures the types are the same
69
+ * - ensures the values are equal
70
+ * - if so, and the default is an array:
71
+ * - ensures the args value is an array
72
+ * - ensures the args values do not differ from the default values
73
+ */
74
+ const isNotDefault = _.overEvery([
75
+ defaultIsDefined,
76
+ _.overSome([
77
+ typesDiffer,
78
+ _.overEvery([defaultValueIsArray, argValueNotArrayOrArraysDiffer]),
79
+ defaultValueNotArrayAndValuesDiffer,
80
+ ]),
81
+ ]);
82
+
83
+ const defaultsFromSchema = getDefaultsForSchema(true) as Record<string, unknown>;
84
+
85
+ return _.reduce(
86
+ _.pickBy(args, (_v, key) => isNotDefault(key)),
87
+ // explodes the flattened object back into nested one
88
+ (acc: Args, {value, argSpec}: FlattenedArg) => _.set(acc, argSpec.dest, value),
89
+ {} as Args
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Prints a breakdown of configuration: defaults, config file, CLI/programmatic overrides, and final merged args.
95
+ *
96
+ * The actual shape of `nonDefaultPreConfigParsedArgs` and `defaults` does not matter for the purposes of this
97
+ * function, but it's intended to be called with values of type {@link ParsedArgs} and
98
+ * `DefaultValues<true>`, respectively.
99
+ *
100
+ * @param nonDefaultPreConfigParsedArgs - CLI-only (or programmatic) args that differ from defaults
101
+ * @param configResult - Result of {@link readConfigFile}
102
+ * @param defaults - Schema default values
103
+ * @param parsedArgs - Final merged configuration
104
+ */
105
+ export function showConfig(
106
+ nonDefaultPreConfigParsedArgs: Partial<Args>,
107
+ configResult: ReadConfigFileResult,
108
+ defaults: Partial<Args>,
109
+ parsedArgs: Args
110
+ ): void {
111
+ console.log('Appium Configuration\n');
112
+ console.log('from defaults:\n');
113
+ console.dir(compactConfig(defaults));
114
+ if (configResult.config) {
115
+ console.log(`\nfrom config file at ${configResult.filepath}:\n`);
116
+ console.dir(compactConfig(configResult.config));
117
+ } else {
118
+ console.log(`\n(no configuration file loaded)`);
119
+ }
120
+ const compactedNonDefaultPreConfigArgs = compactConfig(nonDefaultPreConfigParsedArgs);
121
+ if (_.isEmpty(compactedNonDefaultPreConfigArgs)) {
122
+ console.log(`\n(no CLI parameters provided)`);
123
+ } else {
124
+ console.log('\nvia CLI or function call:\n');
125
+ console.dir(compactedNonDefaultPreConfigArgs);
126
+ }
127
+ console.log('\nfinal configuration:\n');
128
+ console.dir(compactConfig(parsedArgs));
129
+ }
130
+
131
+ /**
132
+ * Compacts an object for {@link showConfig}:
133
+ * 1. Removes `subcommand` key/value
134
+ * 2. Removes `undefined` values
135
+ * 3. Removes empty objects (but not `false` values)
136
+ * Does not operate recursively.
137
+ */
138
+ const compactConfig = _.partial(
139
+ _.omitBy,
140
+ _,
141
+ (value: unknown, key: string) =>
142
+ key === 'subcommand' || _.isUndefined(value) || (_.isObject(value) && _.isEmpty(value))
143
+ );
@@ -1,4 +1,7 @@
1
1
  import _ from 'lodash';
2
+ import type {ArgumentOptions} from 'argparse';
3
+ import type {ExtensionType} from '@appium/types';
4
+ import type {CliExtensionSubcommand} from 'appium/types';
2
5
  import {
3
6
  DRIVER_TYPE,
4
7
  PLUGIN_TYPE,
@@ -14,18 +17,21 @@ import {toParserArgs} from '../schema/cli-args';
14
17
  const DRIVER_EXAMPLE = 'xcuitest';
15
18
  const PLUGIN_EXAMPLE = 'images';
16
19
 
20
+ export type ArgumentDefinitions = Map<
21
+ [name: string] | [name: string, alias: string],
22
+ ArgumentOptions
23
+ >;
24
+
17
25
  /**
18
26
  * This is necessary because we pass the array into `argparse`. `argparse` is bad and mutates things. We don't want that.
19
27
  * Bad `argparse`! Bad!
20
28
  */
21
29
  const INSTALL_TYPES_ARRAY = [...INSTALL_TYPES];
22
30
 
23
- /** @type {Set<ExtensionType>} */
24
- const EXTENSION_TYPES = new Set([DRIVER_TYPE, PLUGIN_TYPE]);
31
+ const EXTENSION_TYPES = new Set<ExtensionType>([DRIVER_TYPE, PLUGIN_TYPE]);
25
32
 
26
33
  // this set of args works for both drivers and plugins ('extensions')
27
- /** @type {ArgumentDefinitions} */
28
- const globalExtensionArgs = new Map([
34
+ const globalExtensionArgs: ArgumentDefinitions = new Map([
29
35
  [
30
36
  ['--json'],
31
37
  {
@@ -39,10 +45,18 @@ const globalExtensionArgs = new Map([
39
45
  ]);
40
46
 
41
47
  /**
42
- * Builds a Record of extension types to a Record of subcommands to their argument definitions
48
+ * Returns CLI argument definitions for extension commands by extension type.
49
+ *
50
+ * The result is memoized because parser setup is static across process lifetime.
43
51
  */
44
- const getExtensionArgs = _.memoize(function getExtensionArgs() {
45
- const extensionArgs = {};
52
+ export const getExtensionArgs = _.memoize(function getExtensionArgs(): Record<
53
+ ExtensionType,
54
+ Record<CliExtensionSubcommand, ArgumentDefinitions>
55
+ > {
56
+ const extensionArgs = {} as Record<
57
+ ExtensionType,
58
+ Record<CliExtensionSubcommand, ArgumentDefinitions>
59
+ >;
46
60
  for (const type of EXTENSION_TYPES) {
47
61
  extensionArgs[type] = {
48
62
  [EXT_SUBCOMMAND_LIST]: makeListArgs(type),
@@ -53,17 +67,23 @@ const getExtensionArgs = _.memoize(function getExtensionArgs() {
53
67
  [EXT_SUBCOMMAND_DOCTOR]: makeDoctorArgs(type),
54
68
  };
55
69
  }
56
- return /** @type {Record<ExtensionType, Record<import('appium/types').CliExtensionSubcommand,ArgumentDefinitions>>} */ (
57
- extensionArgs
58
- );
70
+ return extensionArgs;
59
71
  });
60
72
 
61
73
  /**
62
- * Makes the opts for the `list` subcommand for each extension type.
63
- * @param {ExtensionType} type
64
- * @returns {ArgumentDefinitions}
74
+ * Returns CLI argument definitions for the `server` command.
75
+ *
76
+ * This includes schema-derived options and additional CLI-only options which
77
+ * are intentionally disallowed in config files.
65
78
  */
66
- function makeListArgs(type) {
79
+ export function getServerArgs(): ArgumentDefinitions {
80
+ return new Map([...toParserArgs(), ...serverArgsDisallowedInConfig]);
81
+ }
82
+
83
+ /**
84
+ * Builds options for the `list` subcommand for an extension type.
85
+ */
86
+ function makeListArgs(type: ExtensionType): ArgumentDefinitions {
67
87
  return new Map([
68
88
  ...globalExtensionArgs,
69
89
  [
@@ -100,11 +120,9 @@ function makeListArgs(type) {
100
120
  }
101
121
 
102
122
  /**
103
- * Makes the opts for the `install` subcommand for each extension type
104
- * @param {ExtensionType} type
105
- * @returns {ArgumentDefinitions}
123
+ * Builds options for the `install` subcommand for an extension type.
106
124
  */
107
- function makeInstallArgs(type) {
125
+ function makeInstallArgs(type: ExtensionType): ArgumentDefinitions {
108
126
  return new Map([
109
127
  ...globalExtensionArgs,
110
128
  [
@@ -144,11 +162,9 @@ function makeInstallArgs(type) {
144
162
  }
145
163
 
146
164
  /**
147
- * Makes the opts for the `uninstall` subcommand for each extension type
148
- * @param {ExtensionType} type
149
- * @returns {ArgumentDefinitions}
165
+ * Builds options for the `uninstall` subcommand for an extension type.
150
166
  */
151
- function makeUninstallArgs(type) {
167
+ function makeUninstallArgs(type: ExtensionType): ArgumentDefinitions {
152
168
  return new Map([
153
169
  ...globalExtensionArgs,
154
170
  [
@@ -164,11 +180,9 @@ function makeUninstallArgs(type) {
164
180
  }
165
181
 
166
182
  /**
167
- * Makes the opts for the `doctor` subcommand for each extension type
168
- * @param {ExtensionType} type
169
- * @returns {ArgumentDefinitions}
183
+ * Builds options for the `doctor` subcommand for an extension type.
170
184
  */
171
- function makeDoctorArgs(type) {
185
+ function makeDoctorArgs(type: ExtensionType): ArgumentDefinitions {
172
186
  return new Map([
173
187
  ...globalExtensionArgs,
174
188
  [
@@ -184,11 +198,9 @@ function makeDoctorArgs(type) {
184
198
  }
185
199
 
186
200
  /**
187
- * Makes the opts for the `update` subcommand for each extension type
188
- * @param {ExtensionType} type
189
- * @returns {ArgumentDefinitions}
201
+ * Builds options for the `update` subcommand for an extension type.
190
202
  */
191
- function makeUpdateArgs(type) {
203
+ function makeUpdateArgs(type: ExtensionType): ArgumentDefinitions {
192
204
  return new Map([
193
205
  ...globalExtensionArgs,
194
206
  [
@@ -216,11 +228,9 @@ function makeUpdateArgs(type) {
216
228
  }
217
229
 
218
230
  /**
219
- * Makes the opts for the `run` subcommand for each extension type
220
- * @param {ExtensionType} type
221
- * @returns {ArgumentDefinitions}
231
+ * Builds options for the `run` subcommand for an extension type.
222
232
  */
223
- function makeRunArgs(type) {
233
+ function makeRunArgs(type: ExtensionType): ArgumentDefinitions {
224
234
  return new Map([
225
235
  ...globalExtensionArgs,
226
236
  [
@@ -246,20 +256,10 @@ function makeRunArgs(type) {
246
256
  ]);
247
257
  }
248
258
 
249
- /**
250
- * Derives the options for the `server` command from the schema, and adds the arguments
251
- * which are disallowed in the config file.
252
- * @returns {ArgumentDefinitions}
253
- */
254
- function getServerArgs() {
255
- return new Map([...toParserArgs(), ...serverArgsDisallowedInConfig]);
256
- }
257
-
258
259
  /**
259
260
  * These don't make sense in the context of a config file for obvious reasons.
260
- * @type {ArgumentDefinitions}
261
261
  */
262
- const serverArgsDisallowedInConfig = new Map([
262
+ const serverArgsDisallowedInConfig: ArgumentDefinitions = new Map([
263
263
  [
264
264
  ['--shell'],
265
265
  {
@@ -310,14 +310,3 @@ const serverArgsDisallowedInConfig = new Map([
310
310
  },
311
311
  ],
312
312
  ]);
313
-
314
- export {getServerArgs, getExtensionArgs};
315
-
316
- /**
317
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
318
- */
319
-
320
- /**
321
- * A tuple of argument aliases and argument options
322
- * @typedef {Map<[name: string]|[name: string, alias: string],import('argparse').ArgumentOptions>} ArgumentDefinitions
323
- */
@@ -0,0 +1,122 @@
1
+ import _ from 'lodash';
2
+ import type {ExtMetadata, ExtRecord, InstallType} from 'appium/types';
3
+ import ExtensionCliCommand from './extension-command';
4
+ import type {
5
+ ExtensionArgs,
6
+ ExtensionCommandOptions,
7
+ ExtensionUpdateResult,
8
+ PostInstallText,
9
+ RunOutput,
10
+ } from './extension-command';
11
+ import {KNOWN_DRIVERS} from '../constants';
12
+ import '@colors/colors';
13
+
14
+ const REQ_DRIVER_FIELDS = ['driverName', 'automationName', 'platformNames', 'mainClass'];
15
+ type DriverInstallOpts = {driver: string; installType: InstallType; packageName?: string};
16
+ type DriverUninstallOpts = {driver: string};
17
+ type DriverUpdateOpts = {driver: string; unsafe: boolean};
18
+ type DriverRunOptions = {driver: string; scriptName: string; extraArgs?: string[]};
19
+ type DriverDoctorOptions = {driver: string};
20
+
21
+ export default class DriverCliCommand extends ExtensionCliCommand<'driver'> {
22
+ constructor({config, json}: ExtensionCommandOptions<'driver'>) {
23
+ super({config, json});
24
+ this.knownExtensions = KNOWN_DRIVERS;
25
+ }
26
+
27
+ /**
28
+ * Install a driver
29
+ *
30
+ * @param opts - install options
31
+ */
32
+ async install({driver, installType, packageName}: DriverInstallOpts): Promise<ExtRecord<'driver'>> {
33
+ return await super._install({
34
+ installSpec: driver,
35
+ installType,
36
+ packageName,
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Uninstall a driver
42
+ *
43
+ * @param opts - uninstall options
44
+ */
45
+ async uninstall({driver}: DriverUninstallOpts): Promise<ExtRecord<'driver'>> {
46
+ return await super._uninstall({installSpec: driver});
47
+ }
48
+
49
+ /**
50
+ * Update a driver
51
+ *
52
+ * @param opts - update options
53
+ */
54
+ async update({driver, unsafe}: DriverUpdateOpts): Promise<ExtensionUpdateResult> {
55
+ return await super._update({installSpec: driver, unsafe});
56
+ }
57
+
58
+ /**
59
+ * Run a script from a driver
60
+ *
61
+ * @param opts - script execution options
62
+ * @throws {Error} if the script fails to run
63
+ */
64
+ async run({driver, scriptName, extraArgs}: DriverRunOptions): Promise<RunOutput> {
65
+ return await super._run({
66
+ installSpec: driver,
67
+ scriptName,
68
+ extraArgs,
69
+ bufferOutput: this.isJsonOutput,
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Runs doctor checks for the given driver.
75
+ *
76
+ * @param opts - doctor command options
77
+ * @returns The amount of executed doctor checks.
78
+ * @throws {Error} If any of the mandatory Doctor checks fails.
79
+ */
80
+ async doctor({driver}: DriverDoctorOptions): Promise<number> {
81
+ return await super._doctor({
82
+ installSpec: driver,
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Builds the success message displayed after a driver installation.
88
+ *
89
+ * @param args - installed extension name and metadata
90
+ * @returns formatted success text
91
+ */
92
+ override getPostInstallText({extName, extData}: ExtensionArgs<'driver'>): PostInstallText {
93
+ return (
94
+ `Driver ${extName}@${extData.version} successfully installed\n`.green +
95
+ `- automationName: ${extData.automationName.green}\n` +
96
+ `- platformNames: ${JSON.stringify(extData.platformNames).green}`
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Validates fields in `appium` field of `driverMetadata`
102
+ *
103
+ * For any `package.json` fields which a driver requires, validate the type of
104
+ * those fields on the `package.json` data, throwing an error if anything is
105
+ * amiss.
106
+ * @param driverMetadata - `appium` metadata from extension package
107
+ * @param installSpec - install spec from CLI
108
+ */
109
+ override validateExtensionFields(driverMetadata: ExtMetadata<'driver'>, installSpec: string): void {
110
+ const missingFields = REQ_DRIVER_FIELDS.reduce(
111
+ (acc, field) => (driverMetadata[field] ? acc : [...acc, field]),
112
+ []
113
+ );
114
+
115
+ if (!_.isEmpty(missingFields)) {
116
+ throw new Error(
117
+ `Driver "${installSpec}" did not expose correct fields for compatibility ` +
118
+ `with Appium. Missing fields: ${JSON.stringify(missingFields)}`
119
+ );
120
+ }
121
+ }
122
+ }