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
@@ -1,174 +0,0 @@
1
- import _ from 'lodash';
2
- import ExtensionCliCommand from './extension-command';
3
- import {KNOWN_DRIVERS} from '../constants';
4
- import '@colors/colors';
5
-
6
- const REQ_DRIVER_FIELDS = ['driverName', 'automationName', 'platformNames', 'mainClass'];
7
-
8
- /**
9
- * @extends {ExtensionCliCommand<DriverType>}
10
- */
11
-
12
- export default class DriverCliCommand extends ExtensionCliCommand {
13
- /**
14
- * @param {import('./extension-command').ExtensionCommandOptions<DriverType>} opts
15
- */
16
- constructor({config, json}) {
17
- super({config, json});
18
- this.knownExtensions = KNOWN_DRIVERS;
19
- }
20
-
21
- /**
22
- * Install a driver
23
- *
24
- * @param {DriverInstallOpts} opts
25
- * @return {Promise<ExtRecord<DriverType>>}
26
- */
27
- async install({driver, installType, packageName}) {
28
- return await super._install({
29
- installSpec: driver,
30
- installType,
31
- packageName,
32
- });
33
- }
34
-
35
- /**
36
- * Uninstall a driver
37
- *
38
- * @param {DriverUninstallOpts} opts
39
- * @return {Promise<ExtRecord<DriverType>>}
40
- */
41
- async uninstall({driver}) {
42
- return await super._uninstall({installSpec: driver});
43
- }
44
-
45
- /**
46
- * Update a driver
47
- *
48
- * @param {DriverUpdateOpts} opts
49
- * @return {Promise<import('./extension-command').ExtensionUpdateResult>}
50
- */
51
- async update({driver, unsafe}) {
52
- return await super._update({installSpec: driver, unsafe});
53
- }
54
-
55
- /**
56
- * Run a script from a driver
57
- *
58
- * @param {DriverRunOptions} opts
59
- * @return {Promise<import('./extension-command').RunOutput>}
60
- * @throws {Error} if the script fails to run
61
- */
62
- async run({driver, scriptName, extraArgs}) {
63
- return await super._run({
64
- installSpec: driver,
65
- scriptName,
66
- extraArgs,
67
- bufferOutput: this.isJsonOutput,
68
- });
69
- }
70
-
71
- /**
72
- * Runs doctor checks for the given driver.
73
- *
74
- * @param {DriverDoctorOptions} opts
75
- * @returns {Promise<number>} The amount of executed doctor checks.
76
- * @throws {Error} If any of the mandatory Doctor checks fails.
77
- */
78
- async doctor({driver}) {
79
- return await super._doctor({
80
- installSpec: driver,
81
- });
82
- }
83
-
84
- /**
85
- *
86
- * @param {import('./extension-command').ExtensionArgs} opts
87
- * @returns {string}
88
- */
89
- getPostInstallText({extName, extData}) {
90
- return (
91
- `Driver ${extName}@${extData.version} successfully installed\n`.green +
92
- `- automationName: ${extData.automationName.green}\n` +
93
- `- platformNames: ${JSON.stringify(extData.platformNames).green}`
94
- );
95
- }
96
-
97
- /**
98
- * Validates fields in `appium` field of `driverMetadata`
99
- *
100
- * For any `package.json` fields which a driver requires, validate the type of
101
- * those fields on the `package.json` data, throwing an error if anything is
102
- * amiss.
103
- * @param {import('appium/types').ExtMetadata<DriverType>} driverMetadata
104
- * @param {string} installSpec
105
- */
106
- validateExtensionFields(driverMetadata, installSpec) {
107
- const missingFields = REQ_DRIVER_FIELDS.reduce(
108
- (acc, field) => (driverMetadata[field] ? acc : [...acc, field]),
109
- []
110
- );
111
-
112
- if (!_.isEmpty(missingFields)) {
113
- throw new Error(
114
- `Driver "${installSpec}" did not expose correct fields for compatibility ` +
115
- `with Appium. Missing fields: ${JSON.stringify(missingFields)}`
116
- );
117
- }
118
- }
119
- }
120
-
121
- /**
122
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
123
- * @typedef {import('@appium/types').DriverType} DriverType
124
- */
125
-
126
- /**
127
- * @template {ExtensionType} ExtType
128
- * @typedef {import('appium/types').ExtRecord<ExtType>} ExtRecord
129
- */
130
-
131
- /**
132
- * @typedef DriverCommandOptions
133
- * @property {import('../extension/extension-config').ExtensionConfig<DriverType>} config
134
- * @property {boolean} json
135
- */
136
-
137
- /**
138
- * Options for {@linkcode DriverCliCommand.install}
139
- * @typedef DriverInstallOpts
140
- * @property {string} driver - the name or spec of a driver to install
141
- * @property {InstallType} installType - how to install this driver. One of the INSTALL_TYPES
142
- * @property {string} [packageName] - for git/github installs, the driver node package name
143
- */
144
-
145
- /**
146
- * @typedef {import('appium/types').InstallType} InstallType
147
- */
148
-
149
- /**
150
- * Options for {@linkcode DriverCliCommand.uninstall}
151
- * @typedef DriverUninstallOpts
152
- * @property {string} driver - the name or spec of a driver to uninstall
153
- */
154
-
155
- /**
156
- * Options for {@linkcode DriverCliCommand.update}
157
- * @typedef DriverUpdateOpts
158
- * @property {string} driver - the name of the driver to update
159
- * @property {boolean} unsafe - if true, will perform unsafe updates past major revision boundaries
160
- */
161
-
162
- /**
163
- * Options for {@linkcode DriverCliCommand.run}.
164
- * @typedef DriverRunOptions
165
- * @property {string} driver - name of the driver to run a script from
166
- * @property {string} scriptName - name of the script to run
167
- * @property {string[]} [extraArgs] - arguments to pass to the script
168
- */
169
-
170
- /**
171
- * Options for {@linkcode DriverCliCommand.doctor}.
172
- * @typedef DriverDoctorOptions
173
- * @property {string} driver - name of the driver to run doctor checks for
174
- */
@@ -1,74 +0,0 @@
1
- /* eslint-disable no-console */
2
- import {DRIVER_TYPE, PLUGIN_TYPE} from '../constants';
3
- import {isExtensionCommandArgs} from '../utils';
4
- import DriverCliCommand from './driver-command';
5
- import PluginCliCommand from './plugin-command';
6
- import {errAndQuit, JSON_SPACES} from './utils';
7
-
8
- export const commandClasses = Object.freeze(
9
- /** @type {const} */ ({
10
- [DRIVER_TYPE]: DriverCliCommand,
11
- [PLUGIN_TYPE]: PluginCliCommand,
12
- })
13
- );
14
-
15
- /**
16
- * Run a subcommand of the 'appium driver' type. Each subcommand has its own set of arguments which
17
- * can be represented as a JS object.
18
- *
19
- * @template {import('appium/types').CliExtensionCommand} Cmd
20
- * @template {import('appium/types').CliExtensionSubcommand} SubCmd
21
- * @param {import('appium/types').Args<Cmd, SubCmd>} args - JS object where the key is the parameter name (as defined in
22
- * driver-parser.js)
23
- * @param {import('../extension/extension-config').ExtensionConfig<Cmd>} config - Extension config object
24
- */
25
- async function runExtensionCommand(args, config) {
26
- // TODO driver config file should be locked while any of these commands are
27
- // running to prevent weird situations
28
- let jsonResult = null;
29
- const {extensionType: type} = config; // NOTE this is the same as `args.subcommand`
30
- if (!isExtensionCommandArgs(args)) {
31
- throw new TypeError(`Cannot call ${type} command without a subcommand like 'install'`);
32
- }
33
- let {json, suppressOutput} = args;
34
- json = Boolean(json);
35
- if (suppressOutput) {
36
- json = true;
37
- }
38
- const CommandClass = /** @type {ExtCommand<Cmd>} */ (commandClasses[type]);
39
- const cmd = new CommandClass({config, json});
40
- try {
41
- jsonResult = await cmd.execute(args);
42
- } catch (err) {
43
- // in the suppress output case, we are calling this function internally and should
44
- // just throw instead of printing an error and ending the process
45
- if (suppressOutput) {
46
- throw err;
47
- }
48
- errAndQuit(json, err);
49
- }
50
-
51
- if (json && !suppressOutput) {
52
- console.log(JSON.stringify(jsonResult, null, JSON_SPACES));
53
- }
54
-
55
- return jsonResult;
56
- }
57
-
58
- export {runExtensionCommand};
59
-
60
- /**
61
- * @template {ExtensionType} ExtType
62
- * @typedef {ExtType extends DriverType ? Class<DriverCliCommand> : ExtType extends PluginType ? Class<PluginCliCommand> : never} ExtCommand
63
- */
64
-
65
- /**
66
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
67
- * @typedef {import('@appium/types').DriverType} DriverType
68
- * @typedef {import('@appium/types').PluginType} PluginType
69
- */
70
-
71
- /**
72
- * @template T
73
- * @typedef {import('@appium/types').Class<T>} Class
74
- */
@@ -1,164 +0,0 @@
1
- import _ from 'lodash';
2
- import ExtensionCliCommand from './extension-command';
3
- import {KNOWN_PLUGINS} from '../constants';
4
-
5
- const REQ_PLUGIN_FIELDS = ['pluginName', 'mainClass'];
6
-
7
- /**
8
- * @extends {ExtensionCliCommand<PluginType>}
9
- */
10
- export default class PluginCliCommand extends ExtensionCliCommand {
11
- /**
12
- *
13
- * @param {import('./extension-command').ExtensionCommandOptions<PluginType>} opts
14
- */
15
- constructor({config, json}) {
16
- super({config, json});
17
- this.knownExtensions = KNOWN_PLUGINS;
18
- }
19
-
20
- /**
21
- * Install a plugin
22
- *
23
- * @param {PluginInstallOpts} opts
24
- * @returns {Promise<ExtRecord<PluginType>>}
25
- */
26
- async install({plugin, installType, packageName}) {
27
- return await super._install({
28
- installSpec: plugin,
29
- installType,
30
- packageName,
31
- });
32
- }
33
-
34
- /**
35
- * Uninstall a plugin
36
- *
37
- * @param {PluginUninstallOpts} opts
38
- * @returns {Promise<ExtRecord<PluginType>>}
39
- */
40
- async uninstall({plugin}) {
41
- return await super._uninstall({installSpec: plugin});
42
- }
43
-
44
- /**
45
- * Update a plugin
46
- *
47
- * @param {PluginUpdateOpts} opts
48
- * @returns {Promise<import('./extension-command').ExtensionUpdateResult>}
49
- */
50
- async update({plugin, unsafe}) {
51
- return await super._update({installSpec: plugin, unsafe});
52
- }
53
-
54
- /**
55
- * Run a script from a plugin
56
- *
57
- * @param {PluginRunOptions} opts
58
- * @returns {Promise<import('./extension-command').RunOutput>}
59
- * @throws {Error} if the script fails to run
60
- */
61
- async run({plugin, scriptName, extraArgs}) {
62
- return await super._run({
63
- installSpec: plugin,
64
- scriptName,
65
- extraArgs,
66
- bufferOutput: this.isJsonOutput,
67
- });
68
- }
69
-
70
- /**
71
- * Runs doctor checks for the given plugin
72
- *
73
- * @param {PluginDoctorOptions} opts
74
- * @returns {Promise<number>} The amount of executed doctor checks.
75
- * @throws {Error} If any of the mandatory Doctor checks fails.
76
- */
77
- async doctor({plugin}) {
78
- return await super._doctor({
79
- installSpec: plugin,
80
- });
81
- }
82
-
83
- /**
84
- *
85
- * @param {import('./extension-command').ExtensionArgs} opts
86
- * @returns {string}
87
- */
88
- getPostInstallText({extName, extData}) {
89
- return `Plugin ${extName}@${extData.version} successfully installed`.green;
90
- }
91
-
92
- /**
93
- * Validates fields in `appium` field of `pluginMetadata`
94
- *
95
- * For any `package.json` fields which a plugin requires, validate the type of
96
- * those fields on the `package.json` data, throwing an error if anything is
97
- * amiss.
98
- * @param {import('appium/types').ExtMetadata<PluginType>} pluginMetadata
99
- * @param {string} installSpec
100
- * @returns {void}
101
- */
102
- validateExtensionFields(pluginMetadata, installSpec) {
103
- const missingFields = REQ_PLUGIN_FIELDS.reduce(
104
- (acc, field) => (pluginMetadata[field] ? acc : [...acc, field]),
105
- []
106
- );
107
-
108
- if (!_.isEmpty(missingFields)) {
109
- throw new Error(
110
- `Installed plugin "${installSpec}" did not expose correct fields for compatibility ` +
111
- `with Appium. Missing fields: ${JSON.stringify(missingFields)}`
112
- );
113
- }
114
- }
115
- }
116
-
117
- /**
118
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
119
- * @typedef {import('@appium/types').PluginType} PluginType
120
- */
121
-
122
- /**
123
- * @template {ExtensionType} ExtType
124
- * @typedef {import('appium/types').ExtRecord<ExtType>} ExtRecord
125
- */
126
-
127
- /**
128
- * Options for {@linkcode PluginCliCommand.install}
129
- * @typedef PluginInstallOpts
130
- * @property {string} plugin - the name or spec of a plugin to install
131
- * @property {InstallType} installType - how to install this plugin. One of the INSTALL_TYPES
132
- * @property {string} [packageName] - for git/github installs, the plugin node package name
133
- */
134
-
135
- /**
136
- * @typedef {import('appium/types').InstallType} InstallType
137
- */
138
-
139
- /**
140
- * Options for {@linkcode PluginCliCommand.uninstall}
141
- * @typedef PluginUninstallOpts
142
- * @property {string} plugin - the name or spec of a plugin to uninstall
143
- */
144
-
145
- /**
146
- * Options for {@linkcode PluginCliCommand.update}
147
- * @typedef PluginUpdateOpts
148
- * @property {string} plugin - the name of the plugin to update
149
- * @property {boolean} unsafe - if true, will perform unsafe updates past major revision boundaries
150
- */
151
-
152
- /**
153
- * Options for {@linkcode PluginCliCommand.run}.
154
- * @typedef PluginRunOptions
155
- * @property {string} plugin - name of the plugin to run a script from
156
- * @property {string} scriptName - name of the script to run
157
- * @property {string[]} [extraArgs] - arguments to pass to the script
158
- */
159
-
160
- /**
161
- * Options for {@linkcode PluginCliCommand.doctor}.
162
- * @typedef PluginDoctorOptions
163
- * @property {string} plugin - name of the plugin to run doctor checks for
164
- */
package/lib/cli/utils.js DELETED
@@ -1,91 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import ora from 'ora';
4
-
5
- export const JSON_SPACES = 4;
6
-
7
- /***
8
- * Log an error to the console and exit the process.
9
- * @param {boolean} json - whether we should log json or text
10
- * @param {any} msg - error message, object, Error instance, etc.
11
- */
12
- export function errAndQuit(json, msg) {
13
- if (json) {
14
- console.log(JSON.stringify({error: `${msg}`}, null, JSON_SPACES));
15
- } else {
16
- console.error(`${msg}`.red);
17
- if (msg.stderr) {
18
- console.error(`${msg.stderr}`.red);
19
- }
20
- }
21
- process.exit(1);
22
- }
23
-
24
- /**
25
- * Conditionally log something to the console
26
- * @param {boolean} json - whether we are in json mode (and should therefore not log)
27
- * @param {string} msg - string to log
28
- */
29
- export function log(json, msg) {
30
- if (!json) {
31
- console.log(msg);
32
- }
33
- }
34
-
35
- /**
36
- * Start a spinner, execute an async function, and then stop the spinner
37
- * @param {boolean} json - whether we are in json mode (and should therefore not log)
38
- * @param {string} msg - string to log
39
- * @param {function} fn - function to wrap with spinning
40
- */
41
- export async function spinWith(json, msg, fn) {
42
- if (json) {
43
- return await fn();
44
- }
45
- const spinner = ora(msg).start();
46
- let res;
47
- try {
48
- res = await fn();
49
- spinner.succeed();
50
- return res;
51
- } catch (err) {
52
- spinner.fail();
53
- throw err;
54
- }
55
- }
56
-
57
- export class RingBuffer {
58
- constructor(size = 50) {
59
- this.size = size;
60
- this.buffer = [];
61
- }
62
-
63
- /**
64
- * Get the current buffer contents
65
- *
66
- * @returns {any[]}
67
- */
68
- getBuff() {
69
- return this.buffer;
70
- }
71
-
72
- /**
73
- * Remove the oldest item from the buffer
74
- *
75
- * @returns {void}
76
- */
77
- dequeue() {
78
- this.buffer.shift();
79
- }
80
- /**
81
- * Add an item to the buffer
82
- *
83
- * @param {any} item
84
- */
85
- enqueue(item) {
86
- if (this.buffer.length >= this.size) {
87
- this.dequeue();
88
- }
89
- this.buffer.push(item);
90
- }
91
- }