appium 2.0.0-beta.4 → 2.0.0-beta.40

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 (151) hide show
  1. package/README.md +10 -11
  2. package/build/lib/appium.d.ts +204 -0
  3. package/build/lib/appium.d.ts.map +1 -0
  4. package/build/lib/appium.js +257 -131
  5. package/build/lib/cli/args.d.ts +20 -0
  6. package/build/lib/cli/args.d.ts.map +1 -0
  7. package/build/lib/cli/args.js +96 -282
  8. package/build/lib/cli/driver-command.d.ts +36 -0
  9. package/build/lib/cli/driver-command.d.ts.map +1 -0
  10. package/build/lib/cli/driver-command.js +25 -18
  11. package/build/lib/cli/extension-command.d.ts +372 -0
  12. package/build/lib/cli/extension-command.d.ts.map +1 -0
  13. package/build/lib/cli/extension-command.js +286 -156
  14. package/build/lib/cli/extension.d.ts +18 -0
  15. package/build/lib/cli/extension.d.ts.map +1 -0
  16. package/build/lib/cli/extension.js +30 -17
  17. package/build/lib/cli/parser.d.ts +80 -0
  18. package/build/lib/cli/parser.d.ts.map +1 -0
  19. package/build/lib/cli/parser.js +152 -95
  20. package/build/lib/cli/plugin-command.d.ts +33 -0
  21. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  22. package/build/lib/cli/plugin-command.js +24 -19
  23. package/build/lib/cli/utils.d.ts +29 -0
  24. package/build/lib/cli/utils.d.ts.map +1 -0
  25. package/build/lib/cli/utils.js +27 -3
  26. package/build/lib/config-file.d.ts +100 -0
  27. package/build/lib/config-file.d.ts.map +1 -0
  28. package/build/lib/config-file.js +136 -0
  29. package/build/lib/config.d.ts +41 -0
  30. package/build/lib/config.d.ts.map +1 -0
  31. package/build/lib/config.js +92 -67
  32. package/build/lib/constants.d.ts +48 -0
  33. package/build/lib/constants.d.ts.map +1 -0
  34. package/build/lib/constants.js +60 -0
  35. package/build/lib/extension/driver-config.d.ts +81 -0
  36. package/build/lib/extension/driver-config.d.ts.map +1 -0
  37. package/build/lib/extension/driver-config.js +177 -0
  38. package/build/lib/extension/extension-config.d.ts +242 -0
  39. package/build/lib/extension/extension-config.d.ts.map +1 -0
  40. package/build/lib/extension/extension-config.js +436 -0
  41. package/build/lib/extension/index.d.ts +48 -0
  42. package/build/lib/extension/index.d.ts.map +1 -0
  43. package/build/lib/extension/index.js +74 -0
  44. package/build/lib/extension/manifest.d.ts +174 -0
  45. package/build/lib/extension/manifest.d.ts.map +1 -0
  46. package/build/lib/extension/manifest.js +256 -0
  47. package/build/lib/extension/package-changed.d.ts +11 -0
  48. package/build/lib/extension/package-changed.d.ts.map +1 -0
  49. package/build/lib/extension/package-changed.js +68 -0
  50. package/build/lib/extension/plugin-config.d.ts +57 -0
  51. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  52. package/build/lib/extension/plugin-config.js +78 -0
  53. package/build/lib/grid-register.d.ts +10 -0
  54. package/build/lib/grid-register.d.ts.map +1 -0
  55. package/build/lib/grid-register.js +21 -25
  56. package/build/lib/logger.d.ts +3 -0
  57. package/build/lib/logger.d.ts.map +1 -0
  58. package/build/lib/logger.js +4 -6
  59. package/build/lib/logsink.d.ts +4 -0
  60. package/build/lib/logsink.d.ts.map +1 -0
  61. package/build/lib/logsink.js +14 -17
  62. package/build/lib/main.d.ts +55 -0
  63. package/build/lib/main.d.ts.map +1 -0
  64. package/build/lib/main.js +189 -90
  65. package/build/lib/schema/arg-spec.d.ts +143 -0
  66. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  67. package/build/lib/schema/arg-spec.js +119 -0
  68. package/build/lib/schema/cli-args.d.ts +19 -0
  69. package/build/lib/schema/cli-args.d.ts.map +1 -0
  70. package/build/lib/schema/cli-args.js +180 -0
  71. package/build/lib/schema/cli-transformers.d.ts +5 -0
  72. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  73. package/build/lib/schema/cli-transformers.js +74 -0
  74. package/build/lib/schema/index.d.ts +3 -0
  75. package/build/lib/schema/index.d.ts.map +1 -0
  76. package/build/lib/schema/index.js +34 -0
  77. package/build/lib/schema/keywords.d.ts +24 -0
  78. package/build/lib/schema/keywords.d.ts.map +1 -0
  79. package/build/lib/schema/keywords.js +70 -0
  80. package/build/lib/schema/schema.d.ts +259 -0
  81. package/build/lib/schema/schema.d.ts.map +1 -0
  82. package/build/lib/schema/schema.js +452 -0
  83. package/build/lib/utils.d.ts +66 -0
  84. package/build/lib/utils.d.ts.map +1 -0
  85. package/build/lib/utils.js +35 -139
  86. package/build/tsconfig.tsbuildinfo +1 -0
  87. package/build/types/appium-manifest.d.ts +59 -0
  88. package/build/types/appium-manifest.d.ts.map +1 -0
  89. package/build/types/cli.d.ts +112 -0
  90. package/build/types/cli.d.ts.map +1 -0
  91. package/build/types/extension-manifest.d.ts +55 -0
  92. package/build/types/extension-manifest.d.ts.map +1 -0
  93. package/build/types/index.d.ts +16 -0
  94. package/build/types/index.d.ts.map +1 -0
  95. package/driver.d.ts +1 -0
  96. package/driver.js +14 -0
  97. package/index.js +11 -0
  98. package/lib/appium.js +517 -186
  99. package/lib/cli/args.js +269 -422
  100. package/lib/cli/driver-command.js +58 -23
  101. package/lib/cli/extension-command.js +612 -260
  102. package/lib/cli/extension.js +34 -16
  103. package/lib/cli/parser.js +241 -83
  104. package/lib/cli/plugin-command.js +48 -20
  105. package/lib/cli/utils.js +24 -10
  106. package/lib/config-file.js +219 -0
  107. package/lib/config.js +210 -91
  108. package/lib/constants.js +69 -0
  109. package/lib/extension/driver-config.js +249 -0
  110. package/lib/extension/extension-config.js +679 -0
  111. package/lib/extension/index.js +116 -0
  112. package/lib/extension/manifest.js +475 -0
  113. package/lib/extension/package-changed.js +64 -0
  114. package/lib/extension/plugin-config.js +113 -0
  115. package/lib/grid-register.js +49 -35
  116. package/lib/logger.js +1 -2
  117. package/lib/logsink.js +38 -33
  118. package/lib/main.js +303 -100
  119. package/lib/schema/arg-spec.js +229 -0
  120. package/lib/schema/cli-args.js +238 -0
  121. package/lib/schema/cli-transformers.js +115 -0
  122. package/lib/schema/index.js +2 -0
  123. package/lib/schema/keywords.js +136 -0
  124. package/lib/schema/schema.js +717 -0
  125. package/lib/utils.js +121 -140
  126. package/package.json +75 -85
  127. package/plugin.d.ts +1 -0
  128. package/plugin.js +13 -0
  129. package/scripts/autoinstall-extensions.js +177 -0
  130. package/support.d.ts +1 -0
  131. package/support.js +13 -0
  132. package/types/appium-manifest.ts +73 -0
  133. package/types/cli.ts +146 -0
  134. package/types/extension-manifest.ts +64 -0
  135. package/types/index.ts +21 -0
  136. package/CHANGELOG.md +0 -3515
  137. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  138. package/build/lib/cli/npm.js +0 -206
  139. package/build/lib/cli/parser-helpers.js +0 -82
  140. package/build/lib/driver-config.js +0 -77
  141. package/build/lib/drivers.js +0 -96
  142. package/build/lib/extension-config.js +0 -253
  143. package/build/lib/plugin-config.js +0 -59
  144. package/build/lib/plugins.js +0 -14
  145. package/lib/cli/npm.js +0 -183
  146. package/lib/cli/parser-helpers.js +0 -79
  147. package/lib/driver-config.js +0 -46
  148. package/lib/drivers.js +0 -81
  149. package/lib/extension-config.js +0 -209
  150. package/lib/plugin-config.js +0 -34
  151. package/lib/plugins.js +0 -10
@@ -1,11 +1,15 @@
1
1
  /* eslint-disable no-console */
2
-
3
2
  import DriverCommand from './driver-command';
4
3
  import PluginCommand from './plugin-command';
5
- import DriverConfig from '../driver-config';
6
- import PluginConfig from '../plugin-config';
7
- import { DRIVER_TYPE } from '../extension-config';
8
- import { errAndQuit, log, JSON_SPACES } from './utils';
4
+ import {DRIVER_TYPE, PLUGIN_TYPE} from '../constants';
5
+ import {errAndQuit, JSON_SPACES} from './utils';
6
+
7
+ export const commandClasses = Object.freeze(
8
+ /** @type {const} */ ({
9
+ [DRIVER_TYPE]: DriverCommand,
10
+ [PLUGIN_TYPE]: PluginCommand,
11
+ })
12
+ );
9
13
 
10
14
  /**
11
15
  * Run a subcommand of the 'appium driver' type. Each subcommand has its own set of arguments which
@@ -13,31 +17,45 @@ import { errAndQuit, log, JSON_SPACES } from './utils';
13
17
  *
14
18
  * @param {Object} args - JS object where the key is the parameter name (as defined in
15
19
  * driver-parser.js)
20
+ * @template {import('../extension/manifest').ExtensionType} ExtType
21
+ * @param {import('../extension/extension-config').ExtensionConfig<ExtType>} config - Extension config object
16
22
  */
17
- async function runExtensionCommand (args, type) {
23
+ async function runExtensionCommand(args, config) {
18
24
  // TODO driver config file should be locked while any of these commands are
19
25
  // running to prevent weird situations
20
26
  let jsonResult = null;
21
- const {json, appiumHome} = args;
22
- const logFn = (msg) => log(json, msg);
23
- const ConfigClass = type === DRIVER_TYPE ? DriverConfig : PluginConfig;
24
- const CommandClass = type === DRIVER_TYPE ? DriverCommand : PluginCommand;
25
- const config = new ConfigClass(appiumHome, logFn);
27
+ const {extensionType: type} = config;
28
+ const extCmd = args[`${type}Command`];
29
+ if (!extCmd) {
30
+ throw new TypeError(`Cannot call ${type} command without a subcommand like 'install'`);
31
+ }
32
+ let {json, suppressOutput} = args;
33
+ if (suppressOutput) {
34
+ json = true;
35
+ }
36
+ const CommandClass = /** @type {ExtCommand<ExtType>} */ (commandClasses[type]);
26
37
  const cmd = new CommandClass({config, json});
27
38
  try {
28
- await config.read();
29
39
  jsonResult = await cmd.execute(args);
30
40
  } catch (err) {
41
+ // in the suppress output case, we are calling this function internally and should
42
+ // just throw instead of printing an error and ending the process
43
+ if (suppressOutput) {
44
+ throw err;
45
+ }
31
46
  errAndQuit(json, err);
32
47
  }
33
48
 
34
- if (json) {
49
+ if (json && !suppressOutput) {
35
50
  console.log(JSON.stringify(jsonResult, null, JSON_SPACES));
36
51
  }
37
52
 
38
53
  return jsonResult;
39
54
  }
40
55
 
41
- export {
42
- runExtensionCommand,
43
- };
56
+ export {runExtensionCommand};
57
+
58
+ /**
59
+ * @template {import('@appium/types').ExtensionType} ExtType
60
+ * @typedef {ExtType extends import('@appium/types').DriverType ? import('@appium/types').Class<DriverCommand> : ExtType extends import('@appium/types').PluginType ? import('@appium/types').Class<PluginCommand> : never} ExtCommand
61
+ */
package/lib/cli/parser.js CHANGED
@@ -1,98 +1,256 @@
1
- import path from 'path';
1
+ import {fs} from '@appium/support';
2
+ import {ArgumentParser} from 'argparse';
2
3
  import _ from 'lodash';
3
- import { ArgumentParser } from 'argparse';
4
- import { sharedArgs, serverArgs, extensionArgs } from './args';
5
- import { DRIVER_TYPE, PLUGIN_TYPE } from '../extension-config';
6
- import { rootDir } from '../utils';
7
-
8
- function getParser (debug = false) {
9
- const parser = new ArgumentParser({
10
- version: require(path.resolve(rootDir, 'package.json')).version,
11
- addHelp: true,
12
- description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
13
- prog: process.argv[1] ? path.basename(process.argv[1]) : 'appium',
14
- debug
15
- });
16
- const subParsers = parser.addSubparsers({dest: 'subcommand', debug});
17
-
18
- // add the 'server' subcommand, and store the raw arguments on the parser
19
- // object as a way for other parts of the code to work with the arguments
20
- // conceptually rather than just through argparse
21
- const serverArgs = addServerToParser(sharedArgs, subParsers, debug);
22
- parser.rawArgs = serverArgs;
23
-
24
- // add the 'driver' and 'plugin' subcommands
25
- addExtensionsToParser(sharedArgs, subParsers, debug);
26
-
27
- // modify the parseArgs function to insert the 'server' subcommand if the
28
- // user hasn't specified a subcommand or the global help command
29
- parser._parseArgs = parser.parseArgs;
30
- parser.parseArgs = function (args, namespace) {
31
- if (_.isUndefined(args)) {
32
- args = [...process.argv.slice(2)];
33
- }
34
- if (!_.includes([DRIVER_TYPE, PLUGIN_TYPE, 'server', '-h'], args[0])) {
35
- args.splice(0, 0, 'server');
4
+ import path from 'path';
5
+ import {DRIVER_TYPE, PLUGIN_TYPE, SERVER_SUBCOMMAND} from '../constants';
6
+ import {finalizeSchema, getArgSpec, hasArgSpec} from '../schema';
7
+ import {rootDir} from '../config';
8
+ import {getExtensionArgs, getServerArgs} from './args';
9
+
10
+ /**
11
+ * If the parsed args do not contain any of these values, then we
12
+ * will automatially inject the `server` subcommand.
13
+ */
14
+ const NON_SERVER_ARGS = Object.freeze(
15
+ new Set([DRIVER_TYPE, PLUGIN_TYPE, SERVER_SUBCOMMAND, '-h', '--help', '-v', '--version'])
16
+ );
17
+
18
+ const version = fs.readPackageJsonFrom(rootDir).version;
19
+
20
+ /**
21
+ * A wrapper around `argparse`
22
+ *
23
+ * - Handles instantiation, configuration, and monkeypatching of an
24
+ * `ArgumentParser` instance for Appium server and its extensions
25
+ * - Handles error conditions, messages, and exit behavior
26
+ */
27
+ class ArgParser {
28
+ /**
29
+ * @param {boolean} [debug] - If true, throw instead of exit on error.
30
+ */
31
+ constructor(debug = false) {
32
+ const prog = process.argv[1] ? path.basename(process.argv[1]) : 'appium';
33
+ const parser = new ArgumentParser({
34
+ add_help: true,
35
+ description:
36
+ 'A webdriver-compatible server that facilitates automation of web, mobile, and other types of apps across various platforms.',
37
+ prog,
38
+ });
39
+
40
+ ArgParser._patchExit(parser);
41
+
42
+ /**
43
+ * Program name (typically `appium`)
44
+ * @type {string}
45
+ */
46
+ this.prog = prog;
47
+
48
+ /**
49
+ * If `true`, throw an error on parse failure instead of printing help
50
+ * @type {boolean}
51
+ */
52
+ this.debug = debug;
53
+
54
+ /**
55
+ * Wrapped `ArgumentParser` instance
56
+ * @type {ArgumentParser}
57
+ */
58
+ this.parser = parser;
59
+
60
+ parser.add_argument('-v', '--version', {
61
+ action: 'version',
62
+ version,
63
+ });
64
+
65
+ const subParsers = parser.add_subparsers({dest: 'subcommand'});
66
+
67
+ // add the 'server' subcommand, and store the raw arguments on the parser
68
+ // object as a way for other parts of the code to work with the arguments
69
+ // conceptually rather than just through argparse
70
+ const serverArgs = ArgParser._addServerToParser(subParsers);
71
+
72
+ this.rawArgs = serverArgs;
73
+
74
+ // add the 'driver' and 'plugin' subcommands
75
+ ArgParser._addExtensionCommandsToParser(subParsers);
76
+
77
+ // backwards compatibility / drop-in wrapper
78
+ /**
79
+ * @type {ArgParser['parseArgs']}
80
+ */
81
+ this.parse_args = this.parseArgs;
82
+ }
83
+
84
+ /**
85
+ * Parse arguments from the command line.
86
+ *
87
+ * If no subcommand is passed in, this method will inject the `server` subcommand.
88
+ *
89
+ * `ArgParser.prototype.parse_args` is an alias of this method.
90
+ * @template [T=import('appium/types').WithServerSubcommand]
91
+ * @param {string[]} [args] - Array of arguments, ostensibly from `process.argv`. Gathers args from `process.argv` if not provided.
92
+ * @returns {import('appium/types').Args<T>} - The parsed arguments
93
+ */
94
+ parseArgs(args = process.argv.slice(2)) {
95
+ if (!NON_SERVER_ARGS.has(args[0])) {
96
+ args.unshift(SERVER_SUBCOMMAND);
36
97
  }
37
- return this._parseArgs(args, namespace);
38
- }.bind(parser);
39
- return parser;
40
- }
41
98
 
42
- function addServerToParser (sharedArgs, subParsers, debug) {
43
- const serverParser = subParsers.addParser('server', {
44
- addHelp: true,
45
- help: 'Run an Appium server',
46
- debug
47
- });
99
+ try {
100
+ const parsed = this.parser.parse_args(args);
101
+ return ArgParser._transformParsedArgs(parsed);
102
+ } catch (err) {
103
+ if (this.debug) {
104
+ throw err;
105
+ }
106
+ // this isn't tested via unit tests (we use `debug: true`) so may escape coverage.
48
107
 
49
- for (const [flags, opts] of [...sharedArgs, ...serverArgs]) {
50
- // addArgument mutates arguments so make copies
51
- serverParser.addArgument([...flags], {...opts});
108
+ /* istanbul ignore next */
109
+ {
110
+ // eslint-disable-next-line no-console
111
+ console.error(); // need an extra space since argparse prints usage.
112
+ // eslint-disable-next-line no-console
113
+ console.error(err.message);
114
+ process.exit(1);
115
+ }
116
+ }
52
117
  }
53
118
 
54
- return serverArgs;
55
- }
119
+ /**
120
+ * Given an object full of arguments as returned by `argparser.parse_args`,
121
+ * expand the ones for extensions into a nested object structure and rename
122
+ * keys to match the intended destination.
123
+ *
124
+ * E.g., `{'driver-foo-bar': baz}` becomes `{driver: {foo: {bar: 'baz'}}}`
125
+ * @param {object} args
126
+ * @returns {object}
127
+ */
128
+ static _transformParsedArgs(args) {
129
+ return _.reduce(
130
+ args,
131
+ (unpacked, value, key) => {
132
+ if (!_.isUndefined(value) && hasArgSpec(key)) {
133
+ const {dest} = /** @type {import('../schema/arg-spec').ArgSpec} */ (getArgSpec(key));
134
+ _.set(unpacked, dest, value);
135
+ } else {
136
+ // this could be anything that _isn't_ a server arg
137
+ unpacked[key] = value;
138
+ }
139
+ return unpacked;
140
+ },
141
+ {}
142
+ );
143
+ }
56
144
 
57
- function getDefaultServerArgs () {
58
- let defaults = {};
59
- for (let [, arg] of serverArgs) {
60
- defaults[arg.dest] = arg.defaultValue;
145
+ /**
146
+ * Patches the `exit()` method of the parser to throw an error, so we can handle it manually.
147
+ * @param {ArgumentParser} parser
148
+ */
149
+ static _patchExit(parser) {
150
+ parser.exit = (code, msg) => {
151
+ if (code) {
152
+ throw new Error(msg);
153
+ }
154
+ process.exit();
155
+ };
61
156
  }
62
- return defaults;
63
- }
64
157
 
65
- function addExtensionsToParser (sharedArgs, subParsers, debug) {
66
- for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
67
- const extParser = subParsers.addParser(type, {
68
- addHelp: true,
69
- help: `Access the ${type} management CLI commands`,
70
- debug
158
+ /**
159
+ *
160
+ * @param {import('argparse').SubParser} subParser
161
+ * @returns {import('./args').ArgumentDefinitions}
162
+ */
163
+ static _addServerToParser(subParser) {
164
+ const serverParser = subParser.add_parser('server', {
165
+ add_help: true,
166
+ help: 'Run an Appium server',
71
167
  });
72
- const extSubParsers = extParser.addSubparsers({
73
- dest: `${type}Command`,
74
- debug
75
- });
76
- const parserSpecs = [
77
- {command: 'list', args: extensionArgs[type].list,
78
- help: `List available and installed ${type}s`},
79
- {command: 'install', args: extensionArgs[type].install,
80
- help: `Install a ${type}`},
81
- {command: 'uninstall', args: extensionArgs[type].uninstall,
82
- help: `Uninstall a ${type}`},
83
- {command: 'update', args: extensionArgs[type].update,
84
- help: `Update installed ${type}s to the latest version`},
85
- ];
86
-
87
- for (const {command, args, help} of parserSpecs) {
88
- const parser = extSubParsers.addParser(command, {help, debug});
89
- for (const [flags, opts] of [...sharedArgs, ...args]) {
90
- // addArgument mutates params so make sure to send in copies instead
91
- parser.addArgument([...flags], {...opts});
168
+
169
+ ArgParser._patchExit(serverParser);
170
+
171
+ const serverArgs = getServerArgs();
172
+ for (const [flagsOrNames, opts] of serverArgs) {
173
+ // TS doesn't like the spread operator here.
174
+ // @ts-ignore
175
+ serverParser.add_argument(...flagsOrNames, {...opts});
176
+ }
177
+
178
+ return serverArgs;
179
+ }
180
+
181
+ /**
182
+ * Adds extension sub-sub-commands to `driver`/`plugin` subcommands
183
+ * @param {import('argparse').SubParser} subParsers
184
+ */
185
+ static _addExtensionCommandsToParser(subParsers) {
186
+ for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
187
+ const extParser = subParsers.add_parser(type, {
188
+ add_help: true,
189
+ help: `Access the ${type} management CLI commands`,
190
+ });
191
+
192
+ ArgParser._patchExit(extParser);
193
+
194
+ const extSubParsers = extParser.add_subparsers({
195
+ dest: `${type}Command`,
196
+ });
197
+ const extensionArgs = getExtensionArgs();
198
+ const parserSpecs = [
199
+ {
200
+ command: 'list',
201
+ args: extensionArgs[type].list,
202
+ help: `List available and installed ${type}s`,
203
+ },
204
+ {
205
+ command: 'install',
206
+ args: extensionArgs[type].install,
207
+ help: `Install a ${type}`,
208
+ },
209
+ {
210
+ command: 'uninstall',
211
+ args: extensionArgs[type].uninstall,
212
+ help: `Uninstall a ${type}`,
213
+ },
214
+ {
215
+ command: 'update',
216
+ args: extensionArgs[type].update,
217
+ help: `Update installed ${type}s to the latest version`,
218
+ },
219
+ {
220
+ command: 'run',
221
+ args: extensionArgs[type].run,
222
+ help:
223
+ `Run a script (defined inside the ${type}'s package.json under the ` +
224
+ `“scripts” field inside the “appium” field) from an installed ${type}`,
225
+ },
226
+ ];
227
+
228
+ for (const {command, args, help} of parserSpecs) {
229
+ const parser = extSubParsers.add_parser(command, {help});
230
+
231
+ ArgParser._patchExit(parser);
232
+
233
+ for (const [flagsOrNames, opts] of args) {
234
+ // add_argument mutates params so make sure to send in copies instead
235
+ // @ts-ignore
236
+ parser.add_argument(...flagsOrNames, {...opts});
237
+ }
92
238
  }
93
239
  }
94
240
  }
95
241
  }
96
242
 
97
- export default getParser;
98
- export { getParser, getDefaultServerArgs };
243
+ /**
244
+ * Creates a {@link ArgParser} instance; finalizes the config schema.
245
+ *
246
+ * @constructs ArgParser
247
+ * @param {boolean} [debug] - If `true`, throw instead of exit upon parsing error
248
+ * @returns {ArgParser}
249
+ */
250
+ function getParser(debug) {
251
+ finalizeSchema();
252
+
253
+ return new ArgParser(debug);
254
+ }
255
+
256
+ export {getParser, ArgParser};
@@ -1,43 +1,71 @@
1
1
  import _ from 'lodash';
2
2
  import ExtensionCommand from './extension-command';
3
- import { PLUGIN_TYPE } from '../extension-config';
4
- import { KNOWN_PLUGINS } from '../plugins';
3
+ import {KNOWN_PLUGINS} from '../constants';
5
4
 
6
5
  const REQ_PLUGIN_FIELDS = ['pluginName', 'mainClass'];
7
6
 
7
+ /**
8
+ * @extends {ExtensionCommand<PluginType>}
9
+ */
8
10
  export default class PluginCommand extends ExtensionCommand {
9
-
10
- constructor ({config, json}) {
11
- super({config, json, type: PLUGIN_TYPE});
11
+ /**
12
+ *
13
+ * @param {import('./extension-command').ExtensionCommandOptions<PluginType>} opts
14
+ */
15
+ constructor({config, json}) {
16
+ super({config, json});
12
17
  this.knownExtensions = KNOWN_PLUGINS;
13
18
  }
14
19
 
15
- async install ({plugin, installType, packageName}) {
16
- return await super.install({ext: plugin, installType, packageName});
20
+ async install({plugin, installType, packageName}) {
21
+ return await super._install({
22
+ installSpec: plugin,
23
+ installType,
24
+ packageName,
25
+ });
26
+ }
27
+
28
+ async uninstall({plugin}) {
29
+ return await super._uninstall({installSpec: plugin});
17
30
  }
18
31
 
19
- async uninstall ({plugin}) {
20
- return await super.uninstall({ext: plugin});
32
+ async update({plugin, unsafe}) {
33
+ return await super._update({installSpec: plugin, unsafe});
21
34
  }
22
35
 
23
- async update ({plugin, unsafe}) {
24
- return await super.update({ext: plugin, unsafe});
36
+ async run({plugin, scriptName}) {
37
+ return await super._run({installSpec: plugin, scriptName});
25
38
  }
26
39
 
27
- getPostInstallText ({extName, extData}) {
40
+ getPostInstallText({extName, extData}) {
28
41
  return `Plugin ${extName}@${extData.version} successfully installed`.green;
29
42
  }
30
43
 
31
- validateExtensionFields (appiumPkgData) {
32
- const missingFields = REQ_PLUGIN_FIELDS.reduce((acc, field) => (
33
- appiumPkgData[field] ? acc : [...acc, field]
34
- ), []);
44
+ /**
45
+ * Validates fields in `appium` field of `driverMetadata`
46
+ *
47
+ * For any `package.json` fields which a driver requires, validate the type of
48
+ * those fields on the `package.json` data, throwing an error if anything is
49
+ * amiss.
50
+ * @param {import('appium/types').ExtMetadata<PluginType>} pluginMetadata
51
+ * @param {string} installSpec
52
+ * @returns {void}
53
+ */
54
+ validateExtensionFields(pluginMetadata, installSpec) {
55
+ const missingFields = REQ_PLUGIN_FIELDS.reduce(
56
+ (acc, field) => (pluginMetadata[field] ? acc : [...acc, field]),
57
+ []
58
+ );
35
59
 
36
60
  if (!_.isEmpty(missingFields)) {
37
- throw new Error(`Installed plugin did not expose correct fields for compability ` +
38
- `with Appium. Missing fields: ${JSON.stringify(missingFields)}`);
61
+ throw new Error(
62
+ `Installed plugin "${installSpec}" did not expose correct fields for compability ` +
63
+ `with Appium. Missing fields: ${JSON.stringify(missingFields)}`
64
+ );
39
65
  }
40
-
41
66
  }
42
-
43
67
  }
68
+
69
+ /**
70
+ * @typedef {import('@appium/types').PluginType} PluginType
71
+ */
package/lib/cli/utils.js CHANGED
@@ -7,9 +7,9 @@ const JSON_SPACES = 4;
7
7
  /***
8
8
  * Log an error to the console and exit the process.
9
9
  * @param {boolean} json - whether we should log json or text
10
- * @param {string} msg - error message
10
+ * @param {any} msg - error message, object, Error instance, etc.
11
11
  */
12
- function errAndQuit (json, msg) {
12
+ function errAndQuit(json, msg) {
13
13
  if (json) {
14
14
  console.log(JSON.stringify({error: `${msg}`}, null, JSON_SPACES));
15
15
  } else {
@@ -26,7 +26,7 @@ function errAndQuit (json, msg) {
26
26
  * @param {boolean} json - whether we are in json mode (and should therefore not log)
27
27
  * @param {string} msg - string to log
28
28
  */
29
- function log (json, msg) {
29
+ function log(json, msg) {
30
30
  !json && console.log(msg);
31
31
  }
32
32
 
@@ -36,7 +36,7 @@ function log (json, msg) {
36
36
  * @param {string} msg - string to log
37
37
  * @param {function} fn - function to wrap with spinning
38
38
  */
39
- async function spinWith (json, msg, fn) {
39
+ async function spinWith(json, msg, fn) {
40
40
  if (json) {
41
41
  return await fn();
42
42
  }
@@ -52,9 +52,23 @@ async function spinWith (json, msg, fn) {
52
52
  }
53
53
  }
54
54
 
55
- export {
56
- errAndQuit,
57
- log,
58
- spinWith,
59
- JSON_SPACES
60
- };
55
+ class RingBuffer {
56
+ constructor(size = 50) {
57
+ this.size = size;
58
+ this.buffer = [];
59
+ }
60
+ getBuff() {
61
+ return this.buffer;
62
+ }
63
+ dequeue() {
64
+ this.buffer.shift();
65
+ }
66
+ enqueue(item) {
67
+ if (this.buffer.length >= this.size) {
68
+ this.dequeue();
69
+ }
70
+ this.buffer.push(item);
71
+ }
72
+ }
73
+
74
+ export {errAndQuit, log, spinWith, JSON_SPACES, RingBuffer};