appium 2.0.0-beta.8 → 2.0.0-rc.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 (206) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +149 -58
  3. package/build/lib/appium.d.ts +229 -0
  4. package/build/lib/appium.d.ts.map +1 -0
  5. package/build/lib/appium.js +678 -441
  6. package/build/lib/appium.js.map +1 -0
  7. package/build/lib/cli/args.d.ts +17 -0
  8. package/build/lib/cli/args.d.ts.map +1 -0
  9. package/build/lib/cli/args.js +263 -300
  10. package/build/lib/cli/args.js.map +1 -0
  11. package/build/lib/cli/driver-command.d.ts +102 -0
  12. package/build/lib/cli/driver-command.d.ts.map +1 -0
  13. package/build/lib/cli/driver-command.js +131 -81
  14. package/build/lib/cli/driver-command.js.map +1 -0
  15. package/build/lib/cli/extension-command.d.ts +402 -0
  16. package/build/lib/cli/extension-command.d.ts.map +1 -0
  17. package/build/lib/cli/extension-command.js +799 -383
  18. package/build/lib/cli/extension-command.js.map +1 -0
  19. package/build/lib/cli/extension.d.ts +23 -0
  20. package/build/lib/cli/extension.d.ts.map +1 -0
  21. package/build/lib/cli/extension.js +71 -60
  22. package/build/lib/cli/extension.js.map +1 -0
  23. package/build/lib/cli/parser.d.ts +84 -0
  24. package/build/lib/cli/parser.d.ts.map +1 -0
  25. package/build/lib/cli/parser.js +252 -148
  26. package/build/lib/cli/parser.js.map +1 -0
  27. package/build/lib/cli/plugin-command.d.ts +99 -0
  28. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  29. package/build/lib/cli/plugin-command.js +125 -81
  30. package/build/lib/cli/plugin-command.js.map +1 -0
  31. package/build/lib/cli/utils.d.ts +29 -0
  32. package/build/lib/cli/utils.d.ts.map +1 -0
  33. package/build/lib/cli/utils.js +72 -51
  34. package/build/lib/cli/utils.js.map +1 -0
  35. package/build/lib/config-file.d.ts +100 -0
  36. package/build/lib/config-file.d.ts.map +1 -0
  37. package/build/lib/config-file.js +207 -0
  38. package/build/lib/config-file.js.map +1 -0
  39. package/build/lib/config.d.ts +49 -0
  40. package/build/lib/config.d.ts.map +1 -0
  41. package/build/lib/config.js +262 -223
  42. package/build/lib/config.js.map +1 -0
  43. package/build/lib/constants.d.ts +56 -0
  44. package/build/lib/constants.d.ts.map +1 -0
  45. package/build/lib/constants.js +73 -0
  46. package/build/lib/constants.js.map +1 -0
  47. package/build/lib/extension/driver-config.d.ts +82 -0
  48. package/build/lib/extension/driver-config.d.ts.map +1 -0
  49. package/build/lib/extension/driver-config.js +210 -0
  50. package/build/lib/extension/driver-config.js.map +1 -0
  51. package/build/lib/extension/extension-config.d.ts +270 -0
  52. package/build/lib/extension/extension-config.d.ts.map +1 -0
  53. package/build/lib/extension/extension-config.js +601 -0
  54. package/build/lib/extension/extension-config.js.map +1 -0
  55. package/build/lib/extension/index.d.ts +48 -0
  56. package/build/lib/extension/index.d.ts.map +1 -0
  57. package/build/lib/extension/index.js +105 -0
  58. package/build/lib/extension/index.js.map +1 -0
  59. package/build/lib/extension/manifest-migrations.d.ts +27 -0
  60. package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
  61. package/build/lib/extension/manifest-migrations.js +134 -0
  62. package/build/lib/extension/manifest-migrations.js.map +1 -0
  63. package/build/lib/extension/manifest.d.ts +145 -0
  64. package/build/lib/extension/manifest.d.ts.map +1 -0
  65. package/build/lib/extension/manifest.js +528 -0
  66. package/build/lib/extension/manifest.js.map +1 -0
  67. package/build/lib/extension/package-changed.d.ts +11 -0
  68. package/build/lib/extension/package-changed.d.ts.map +1 -0
  69. package/build/lib/extension/package-changed.js +62 -0
  70. package/build/lib/extension/package-changed.js.map +1 -0
  71. package/build/lib/extension/plugin-config.d.ts +56 -0
  72. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  73. package/build/lib/extension/plugin-config.js +102 -0
  74. package/build/lib/extension/plugin-config.js.map +1 -0
  75. package/build/lib/grid-register.d.ts +10 -0
  76. package/build/lib/grid-register.d.ts.map +1 -0
  77. package/build/lib/grid-register.js +122 -144
  78. package/build/lib/grid-register.js.map +1 -0
  79. package/build/lib/logger.d.ts +3 -0
  80. package/build/lib/logger.d.ts.map +1 -0
  81. package/build/lib/logger.js +5 -17
  82. package/build/lib/logger.js.map +1 -0
  83. package/build/lib/logsink.d.ts +4 -0
  84. package/build/lib/logsink.d.ts.map +1 -0
  85. package/build/lib/logsink.js +189 -184
  86. package/build/lib/logsink.js.map +1 -0
  87. package/build/lib/main.d.ts +62 -0
  88. package/build/lib/main.d.ts.map +1 -0
  89. package/build/lib/main.js +406 -234
  90. package/build/lib/main.js.map +1 -0
  91. package/build/lib/schema/arg-spec.d.ts +143 -0
  92. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  93. package/build/lib/schema/arg-spec.js +164 -0
  94. package/build/lib/schema/arg-spec.js.map +1 -0
  95. package/build/lib/schema/cli-args.d.ts +19 -0
  96. package/build/lib/schema/cli-args.d.ts.map +1 -0
  97. package/build/lib/schema/cli-args.js +220 -0
  98. package/build/lib/schema/cli-args.js.map +1 -0
  99. package/build/lib/schema/cli-transformers.d.ts +5 -0
  100. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  101. package/build/lib/schema/cli-transformers.js +124 -0
  102. package/build/lib/schema/cli-transformers.js.map +1 -0
  103. package/build/lib/schema/index.d.ts +3 -0
  104. package/build/lib/schema/index.d.ts.map +1 -0
  105. package/build/lib/schema/index.js +19 -0
  106. package/build/lib/schema/index.js.map +1 -0
  107. package/build/lib/schema/keywords.d.ts +24 -0
  108. package/build/lib/schema/keywords.d.ts.map +1 -0
  109. package/build/lib/schema/keywords.js +128 -0
  110. package/build/lib/schema/keywords.js.map +1 -0
  111. package/build/lib/schema/schema.d.ts +260 -0
  112. package/build/lib/schema/schema.d.ts.map +1 -0
  113. package/build/lib/schema/schema.js +640 -0
  114. package/build/lib/schema/schema.js.map +1 -0
  115. package/build/lib/utils.d.ts +276 -0
  116. package/build/lib/utils.d.ts.map +1 -0
  117. package/build/lib/utils.js +373 -271
  118. package/build/lib/utils.js.map +1 -0
  119. package/build/types/cli.d.ts +134 -0
  120. package/build/types/cli.d.ts.map +1 -0
  121. package/build/types/cli.js +3 -0
  122. package/build/types/cli.js.map +1 -0
  123. package/build/types/index.d.ts +15 -0
  124. package/build/types/index.d.ts.map +1 -0
  125. package/build/types/index.js +19 -0
  126. package/build/types/index.js.map +1 -0
  127. package/build/types/manifest/base.d.ts +135 -0
  128. package/build/types/manifest/base.d.ts.map +1 -0
  129. package/build/types/manifest/base.js +3 -0
  130. package/build/types/manifest/base.js.map +1 -0
  131. package/build/types/manifest/index.d.ts +21 -0
  132. package/build/types/manifest/index.d.ts.map +1 -0
  133. package/build/types/manifest/index.js +42 -0
  134. package/build/types/manifest/index.js.map +1 -0
  135. package/build/types/manifest/v3.d.ts +139 -0
  136. package/build/types/manifest/v3.d.ts.map +1 -0
  137. package/build/types/manifest/v3.js +3 -0
  138. package/build/types/manifest/v3.js.map +1 -0
  139. package/build/types/manifest/v4.d.ts +139 -0
  140. package/build/types/manifest/v4.d.ts.map +1 -0
  141. package/build/types/manifest/v4.js +3 -0
  142. package/build/types/manifest/v4.js.map +1 -0
  143. package/driver.d.ts +1 -0
  144. package/driver.js +14 -0
  145. package/index.js +11 -0
  146. package/lib/appium.js +555 -185
  147. package/lib/cli/args.js +275 -407
  148. package/lib/cli/driver-command.js +132 -24
  149. package/lib/cli/extension-command.js +751 -272
  150. package/lib/cli/extension.js +47 -20
  151. package/lib/cli/parser.js +267 -95
  152. package/lib/cli/plugin-command.js +122 -22
  153. package/lib/cli/utils.js +24 -10
  154. package/lib/config-file.js +220 -0
  155. package/lib/config.js +243 -132
  156. package/lib/constants.js +79 -0
  157. package/lib/extension/driver-config.js +247 -0
  158. package/lib/extension/extension-config.js +709 -0
  159. package/lib/extension/index.js +116 -0
  160. package/lib/extension/manifest-migrations.js +136 -0
  161. package/lib/extension/manifest.js +580 -0
  162. package/lib/extension/package-changed.js +64 -0
  163. package/lib/extension/plugin-config.js +112 -0
  164. package/lib/grid-register.js +49 -35
  165. package/lib/logger.js +1 -2
  166. package/lib/logsink.js +59 -36
  167. package/lib/main.js +392 -104
  168. package/lib/schema/arg-spec.js +229 -0
  169. package/lib/schema/cli-args.js +241 -0
  170. package/lib/schema/cli-transformers.js +119 -0
  171. package/lib/schema/index.js +2 -0
  172. package/lib/schema/keywords.js +136 -0
  173. package/lib/schema/schema.js +725 -0
  174. package/lib/utils.js +315 -167
  175. package/package.json +84 -82
  176. package/plugin.d.ts +1 -0
  177. package/plugin.js +13 -0
  178. package/scripts/autoinstall-extensions.js +243 -0
  179. package/support.d.ts +1 -0
  180. package/support.js +13 -0
  181. package/tsconfig.json +25 -0
  182. package/types/cli.ts +193 -0
  183. package/types/index.ts +20 -0
  184. package/types/manifest/README.md +30 -0
  185. package/types/manifest/base.ts +158 -0
  186. package/types/manifest/index.ts +28 -0
  187. package/types/manifest/v3.ts +161 -0
  188. package/types/manifest/v4.ts +161 -0
  189. package/CHANGELOG.md +0 -3669
  190. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  191. package/build/lib/cli/argparse-actions.js +0 -104
  192. package/build/lib/cli/npm.js +0 -207
  193. package/build/lib/cli/parser-helpers.js +0 -93
  194. package/build/lib/driver-config.js +0 -77
  195. package/build/lib/drivers.js +0 -99
  196. package/build/lib/extension-config.js +0 -253
  197. package/build/lib/plugin-config.js +0 -59
  198. package/build/lib/plugins.js +0 -14
  199. package/lib/cli/argparse-actions.js +0 -77
  200. package/lib/cli/npm.js +0 -183
  201. package/lib/cli/parser-helpers.js +0 -91
  202. package/lib/driver-config.js +0 -46
  203. package/lib/drivers.js +0 -84
  204. package/lib/extension-config.js +0 -209
  205. package/lib/plugin-config.js +0 -34
  206. package/lib/plugins.js +0 -10
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "appium",
3
+ "version": "2.0.0-rc.1",
3
4
  "description": "Automation for Apps.",
4
- "tags": [
5
+ "keywords": [
5
6
  "automation",
6
7
  "javascript",
7
8
  "selenium",
@@ -11,100 +12,101 @@
11
12
  "firefoxos",
12
13
  "testing"
13
14
  ],
14
- "version": "2.0.0-beta.8",
15
- "author": "https://github.com/appium",
16
- "license": "Apache-2.0",
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/appium/appium.git"
20
- },
15
+ "homepage": "https://appium.io",
21
16
  "bugs": {
22
17
  "url": "https://github.com/appium/appium/issues"
23
18
  },
24
- "engines": {
25
- "node": ">=8",
26
- "npm": ">=6"
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/appium/appium.git",
22
+ "directory": "packages/appium"
27
23
  },
28
- "main": "./build/lib/main.js",
24
+ "license": "Apache-2.0",
25
+ "author": "https://github.com/appium",
26
+ "types": "./build/lib/main.d.ts",
29
27
  "bin": {
30
- "appium": "./build/lib/main.js"
28
+ "appium": "index.js"
31
29
  },
32
30
  "directories": {
33
- "lib": "./lib",
34
- "doc": "./docs"
31
+ "lib": "./lib"
35
32
  },
36
33
  "files": [
37
- "bin",
38
34
  "lib",
39
- "build/lib",
40
- "npm-shrinkwrap.json"
35
+ "build",
36
+ "index.js",
37
+ "driver.*",
38
+ "support.*",
39
+ "plugin.*",
40
+ "scripts/autoinstall-extensions.js",
41
+ "types",
42
+ "tsconfig.json",
43
+ "!build/tsconfig.tsbuildinfo"
41
44
  ],
45
+ "scripts": {
46
+ "build:docs": "node docs/scripts/build-docs.js",
47
+ "build:docs:preview": "cross-env APPIUM_DOCS_PREVIEW=1 npm run build:docs",
48
+ "build:docs:assets": "node docs/scripts/copy-assets.js",
49
+ "build:docs:cli": "node docs/scripts/gen-cli-args-docs.js",
50
+ "build:docs:reference": "node docs/scripts/build-reference.js",
51
+ "dev:docs": "npm run build:docs:assets && npm run dev:docs:en",
52
+ "dev:docs:en": "appium-docs build --serve --mkdocs-yml ./docs/mkdocs-en.yml",
53
+ "dev:docs:ja": "appium-docs build --serve --mkdocs-yml ./docs/mkdocs-ja.yml",
54
+ "dev:docs:zh": "appium-docs build --serve --mkdocs-yml ./docs/mkdocs-zh.yml",
55
+ "postinstall": "node ./scripts/autoinstall-extensions.js",
56
+ "publish:docs": "cross-env APPIUM_DOCS_PUBLISH=1 npm run build:docs",
57
+ "test": "npm run test:unit",
58
+ "test:e2e": "mocha -p --timeout 1m --slow 30s \"./test/e2e/**/*.spec.js\"",
59
+ "test:smoke": "cross-env APPIUM_HOME=./local_appium_home node ./index.js driver install uiautomator2 && cross-env APPIUM_HOME=./local_appium_home node ./index.js driver list",
60
+ "test:unit": "mocha \"./test/unit/**/*.spec.js\""
61
+ },
42
62
  "dependencies": {
43
- "@appium/base-plugin": "^1.0.0",
44
- "@babel/runtime": "^7.6.0",
45
- "appium-base-driver": "8.0.0-beta.0",
46
- "appium-support": "2.x",
47
- "argparse": "^2.0.1",
48
- "async-lock": "^1.0.0",
49
- "asyncbox": "2.x",
50
- "axios": "^0.21.0",
51
- "bluebird": "3.x",
52
- "continuation-local-storage": "3.x",
53
- "find-root": "^1.1.0",
54
- "lodash": "^4.17.11",
55
- "longjohn": "^0.2.12",
56
- "npmlog": "4.x",
57
- "ora": "^4.0.4",
58
- "semver": "^7.0.0",
59
- "source-map-support": "0.x",
60
- "teen_process": "1.x",
61
- "winston": "3.x",
62
- "word-wrap": "^1.2.3",
63
- "yaml": "^1.7.2"
63
+ "@appium/base-driver": "^9.3.11",
64
+ "@appium/base-plugin": "^2.2.11",
65
+ "@appium/docutils": "^0.4.0",
66
+ "@appium/schema": "^0.3.0",
67
+ "@appium/support": "^4.0.2",
68
+ "@appium/types": "^0.12.0",
69
+ "@sidvind/better-ajv-errors": "2.1.0",
70
+ "@types/argparse": "2.0.10",
71
+ "@types/bluebird": "3.5.38",
72
+ "@types/fancy-log": "2.0.0",
73
+ "@types/semver": "7.5.0",
74
+ "@types/teen_process": "2.0.0",
75
+ "@types/wrap-ansi": "3.0.0",
76
+ "ajv": "8.12.0",
77
+ "ajv-formats": "2.1.1",
78
+ "argparse": "2.0.1",
79
+ "async-lock": "1.4.0",
80
+ "asyncbox": "2.9.4",
81
+ "axios": "1.4.0",
82
+ "bluebird": "3.7.2",
83
+ "cross-env": "7.0.3",
84
+ "find-up": "5.0.0",
85
+ "glob": "8.1.0",
86
+ "lilconfig": "2.1.0",
87
+ "lodash": "4.17.21",
88
+ "npmlog": "7.0.1",
89
+ "ora": "5.4.1",
90
+ "package-changed": "3.0.0",
91
+ "resolve-from": "5.0.0",
92
+ "semver": "7.5.1",
93
+ "source-map-support": "0.5.21",
94
+ "teen_process": "2.0.2",
95
+ "type-fest": "3.11.1",
96
+ "winston": "3.9.0",
97
+ "wrap-ansi": "7.0.0",
98
+ "yaml": "2.3.1"
64
99
  },
65
- "scripts": {
66
- "clean": "rm -rf node_modules && rm -f package-lock.json && npm install",
67
- "prepare": "gulp prepublish",
68
- "prepublishOnly": "npm run prune-shrinkwrap && gulp fixShrinkwrap",
69
- "postpublish": "npm run restore-shrinkwrap",
70
- "prune-shrinkwrap": "!(test -e npm-shrinkwrap.json) || (npm ci --production --ignore-scripts && npm run backup-shrinkwrap && npm shrinkwrap && npm install --only=dev --no-shrinkwrap)",
71
- "restore-shrinkwrap": "!(test -e npm-shrinkwrap.json) || (mv npm-shrinkwrap-backup.json npm-shrinkwrap.json)",
72
- "backup-shrinkwrap": "mv npm-shrinkwrap.json npm-shrinkwrap-backup.json",
73
- "check-pruned-shrinkwrap": "node check-pruned-shrinkwrap.js",
74
- "test": "gulp once",
75
- "e2e-test": "gulp e2e-test",
76
- "watch": "gulp watch",
77
- "build": "gulp transpile",
78
- "mocha": "mocha",
79
- "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
80
- "precommit-test": "REPORTER=dot gulp once",
81
- "lint": "gulp lint",
82
- "lint:fix": "gulp lint --fix",
83
- "coverage": "gulp coveralls",
84
- "generate-docs": "node ./build/commands-yml/parse.js",
85
- "zip": "zip -qr appium.zip .",
86
- "upload": "gulp github-upload",
87
- "zip-and-upload": "npm run zip && npm run upload"
100
+ "engines": {
101
+ "node": "^14.17.0 || ^16.13.0 || >=18.0.0",
102
+ "npm": ">=8"
88
103
  },
89
- "pre-commit": [
90
- "precommit-msg",
91
- "precommit-test"
92
- ],
93
- "devDependencies": {
94
- "@appium/fake-plugin": "^0.2.0",
95
- "appium-fake-driver": "^1.0.1",
96
- "appium-gulp-plugins": "^5.2.1",
97
- "chai": "4.x",
98
- "chai-as-promised": "7.x",
99
- "eslint-config-appium": "^4.0.1",
100
- "fancy-log": "^1.3.2",
101
- "gulp": "^4.0.0",
102
- "handlebars": "^4.2.0",
103
- "mocha": "^8.0.1",
104
- "pre-commit": "1.x",
105
- "sinon": "^9.0.0",
106
- "validate.js": "^0.13.0",
107
- "wd": "^1.10.0",
108
- "yaml-js": "^0.2.0"
104
+ "publishConfig": {
105
+ "access": "public",
106
+ "tag": "next"
107
+ },
108
+ "gitHead": "d0ebbaa0c683eeba04d9d967af2d0fde76197950",
109
+ "typedoc": {
110
+ "entryPoint": "./lib/main.js"
109
111
  }
110
112
  }
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@appium/base-plugin';
package/plugin.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ // @ts-check
4
+
5
+ /**
6
+ * This module is here to re-export `@appium/base-plugin` for Appium extensions.
7
+ *
8
+ * @see https://npm.im/@appium/base-plugin
9
+ * @example
10
+ * const { BasePlugin } = require('appium/plugin');
11
+ */
12
+
13
+ module.exports = require('@appium/base-plugin');
@@ -0,0 +1,243 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-check
4
+
5
+ /* eslint-disable no-console, promise/prefer-await-to-then */
6
+
7
+ /**
8
+ * This script is intended to be run as a `postinstall` lifecycle script,
9
+ * and will automatically install extensions if requested by the user.
10
+ *
11
+ * If the current working directory is within a project which has `appium`
12
+ * as a dependency, this script does nothing; extensions must be managed
13
+ * via `npm` or another package manager.
14
+ *
15
+ * If `CI=1` is in the environment, this script will exit with a non-zero
16
+ * code upon failure (which will typically break a build). Otherwise, it
17
+ * will always exit with code 0, even if errors occur.
18
+ *
19
+ * @module
20
+ * @example
21
+ * `npm install -g appium --drivers=uiautomator2,xcuitest --plugins=images`
22
+ */
23
+
24
+ const B = require('bluebird');
25
+ const path = require('node:path');
26
+ const {realpath} = require('node:fs/promises');
27
+
28
+ B.config({
29
+ cancellation: true,
30
+ });
31
+
32
+ /** @type {typeof import('../lib/cli/extension').runExtensionCommand} */
33
+ let runExtensionCommand;
34
+ /** @type {typeof import('../lib/constants').DRIVER_TYPE} */
35
+ let DRIVER_TYPE;
36
+ /** @type {typeof import('../lib/constants').PLUGIN_TYPE} */
37
+ let PLUGIN_TYPE;
38
+ /** @type {typeof import('../lib/extension').loadExtensions} */
39
+ let loadExtensions;
40
+
41
+ const _ = require('lodash');
42
+ const wrap = _.partial(
43
+ require('wrap-ansi'),
44
+ _,
45
+ process.stderr.columns ?? process.stdout.columns ?? 80
46
+ );
47
+ const ora = require('ora');
48
+
49
+ /** @type {typeof import('@appium/support').env} */
50
+ let env;
51
+ /** @type {typeof import('@appium/support').util} */
52
+ let util;
53
+ /** @type {typeof import('@appium/support').logger} */
54
+ let logger;
55
+
56
+ function log(message) {
57
+ console.error(wrap(`[Appium] ${message}`));
58
+ }
59
+
60
+ /**
61
+ * This is a naive attempt at determining whether or not we are in a dev environment; in other
62
+ * words, is `postinstall` being run from within the `appium` monorepo?
63
+ *
64
+ * When we're in the monorepo, `npm_config_local_prefix` will be set to the root of the monorepo root
65
+ * dir when running this lifecycle script from an `npm install` in the monorepo root.
66
+ *
67
+ * `realpath` is necessary due to macOS omitting `/private` from paths
68
+ */
69
+ async function isDevEnvironment() {
70
+ return (
71
+ process.env.npm_config_local_prefix &&
72
+ path.join(process.env.npm_config_local_prefix, 'packages', 'appium') ===
73
+ (await realpath(path.join(__dirname, '..')))
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Setup / check environment if we should do anything here
79
+ * @returns {Promise<boolean>} `true` if Appium is built and ready to go
80
+ */
81
+ async function init() {
82
+ if (await isDevEnvironment()) {
83
+ log('Dev environment likely; skipping automatic installation of extensions');
84
+ return false;
85
+ }
86
+ try {
87
+ ({env, util, logger} = require('@appium/support'));
88
+ // @ts-ignore
89
+ ({runExtensionCommand} = require('../build/lib/cli/extension'));
90
+ ({DRIVER_TYPE, PLUGIN_TYPE} = require('../build/lib/constants'));
91
+ // @ts-ignore
92
+ ({loadExtensions} = require('../build/lib/extension'));
93
+ logger.getLogger('Appium').level = 'error';
94
+
95
+ // if we're doing `npm install -g appium` then we will assume we don't have a local appium.
96
+ if (!process.env.npm_config_global && (await env.hasAppiumDependency(process.cwd()))) {
97
+ log(`Found local Appium installation; skipping automatic installation of extensions.`);
98
+ return false;
99
+ }
100
+ return true;
101
+ } catch {
102
+ log('Dev environment likely; skipping automatic installation of extensions');
103
+ return false;
104
+ }
105
+ }
106
+
107
+ async function main() {
108
+ if (!(await init())) {
109
+ return;
110
+ }
111
+
112
+ const driverEnv = process.env.npm_config_drivers;
113
+ const pluginEnv = process.env.npm_config_plugins;
114
+
115
+ const spinner = ora({
116
+ text: 'Looking for extensions to automatically install...',
117
+ prefixText: '[Appium]',
118
+ }).start();
119
+
120
+ if (!driverEnv && !pluginEnv) {
121
+ spinner.succeed(
122
+ wrap(`No drivers or plugins to automatically install.
123
+ If desired, provide arguments with comma-separated values "--drivers=<known_driver>[,known_driver...]" and/or "--plugins=<known_plugin>[,known_plugin...]" to the "npm install appium" command. The specified extensions will be installed automatically with Appium. Note: to see the list of known extensions, run "appium <driver|plugin> list".`)
124
+ );
125
+ return;
126
+ }
127
+
128
+ /**
129
+ * @type {[[typeof DRIVER_TYPE, string?], [typeof PLUGIN_TYPE, string?]]}
130
+ */
131
+ const specs = [
132
+ [DRIVER_TYPE, driverEnv],
133
+ [PLUGIN_TYPE, pluginEnv],
134
+ ];
135
+
136
+ spinner.start('Resolving Appium home directory...');
137
+ const appiumHome = await env.resolveAppiumHome();
138
+ spinner.succeed(`Found Appium home: ${appiumHome}`);
139
+
140
+ spinner.start('Loading extension data...');
141
+ const {driverConfig, pluginConfig} = await loadExtensions(appiumHome);
142
+ spinner.succeed('Loaded extension data.');
143
+
144
+ const installedStats = {[DRIVER_TYPE]: 0, [PLUGIN_TYPE]: 0};
145
+ for (const [type, extEnv] of specs) {
146
+ if (extEnv) {
147
+ for await (let ext of extEnv.split(',')) {
148
+ ext = ext.trim();
149
+ try {
150
+ await checkAndInstallExtension({
151
+ runExtensionCommand,
152
+ appiumHome,
153
+ type,
154
+ ext,
155
+ driverConfig,
156
+ pluginConfig,
157
+ spinner,
158
+ });
159
+ installedStats[type]++;
160
+ } catch (e) {
161
+ spinner.fail(`Could not install ${type} "${ext}": ${e.message}`);
162
+ if (process.env.CI) {
163
+ process.exitCode = 1;
164
+ }
165
+ return;
166
+ }
167
+ }
168
+ }
169
+ }
170
+ spinner.succeed(
171
+ `Done. ${installedStats[DRIVER_TYPE]} ${util.pluralize(
172
+ 'driver',
173
+ installedStats[DRIVER_TYPE]
174
+ )} and ${installedStats[PLUGIN_TYPE]} ${util.pluralize(
175
+ 'plugin',
176
+ installedStats[PLUGIN_TYPE]
177
+ )} are installed.`
178
+ );
179
+ }
180
+
181
+ /**
182
+ * @privateRemarks the two `@ts-ignore` directives here are because I have no idea what's wrong with
183
+ * the types and don't want to spend more time on it. regardless, it seems to work for now.
184
+ * @param {CheckAndInstallExtensionsOpts} opts
185
+ */
186
+ async function checkAndInstallExtension({
187
+ runExtensionCommand,
188
+ appiumHome,
189
+ type,
190
+ ext,
191
+ driverConfig,
192
+ pluginConfig,
193
+ spinner,
194
+ }) {
195
+ const extList = await runExtensionCommand(
196
+ // @ts-ignore
197
+ {
198
+ appiumHome,
199
+ subcommand: type,
200
+ [`${type}Command`]: 'list',
201
+ showInstalled: true,
202
+ suppressOutput: true,
203
+ },
204
+ type === DRIVER_TYPE ? driverConfig : pluginConfig
205
+ );
206
+ if (extList[ext]) {
207
+ spinner.info(`The ${type} "${ext}" is already installed.`);
208
+ return;
209
+ }
210
+ spinner.start(`Installing ${type} "${ext}"...`);
211
+ await runExtensionCommand(
212
+ // @ts-ignore
213
+ {
214
+ subcommand: type,
215
+ appiumHome,
216
+ [`${type}Command`]: 'install',
217
+ suppressOutput: true,
218
+ [type]: ext,
219
+ },
220
+ type === DRIVER_TYPE ? driverConfig : pluginConfig
221
+ );
222
+ spinner.succeed(`Installed ${type} "${ext}".`);
223
+ }
224
+
225
+ if (require.main === module) {
226
+ main().catch((e) => {
227
+ log(e);
228
+ process.exitCode = 1;
229
+ });
230
+ }
231
+
232
+ module.exports = main;
233
+
234
+ /**
235
+ * @typedef CheckAndInstallExtensionsOpts
236
+ * @property {typeof runExtensionCommand} runExtensionCommand
237
+ * @property {string} appiumHome
238
+ * @property {DRIVER_TYPE | PLUGIN_TYPE} type
239
+ * @property {string} ext
240
+ * @property {import('../lib/extension/driver-config').DriverConfig} driverConfig
241
+ * @property {import('../lib/extension/plugin-config').PluginConfig} pluginConfig
242
+ * @property {import('ora').Ora} spinner
243
+ */
package/support.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@appium/support';
package/support.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ // @ts-check
4
+
5
+ /**
6
+ * This module is here to re-export `@appium/support` for Appium extensions.
7
+ *
8
+ * @see https://npm.im/@appium/support
9
+ * @example
10
+ * const { fs, npm } = require('appium/support');
11
+ */
12
+
13
+ module.exports = require('@appium/support');
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": "@appium/tsconfig/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "outDir": "build",
6
+ "paths": {
7
+ "@appium/support": ["../support"],
8
+ "@appium/base-driver": ["../base-driver"],
9
+ "@appium/base-plugin": ["../base-plugin"],
10
+ "@appium/types": ["../types"],
11
+ "@appium/schema": ["../schema"],
12
+ "appium": ["."]
13
+ },
14
+ "checkJs": true
15
+ },
16
+ "include": ["lib", "types"],
17
+ "references": [
18
+ {"path": "../schema"},
19
+ {"path": "../types"},
20
+ {"path": "../support"},
21
+ {"path": "../base-driver"},
22
+ {"path": "../base-plugin"},
23
+ {"path": "../test-support"}
24
+ ]
25
+ }
package/types/cli.ts ADDED
@@ -0,0 +1,193 @@
1
+ import {DriverType, PluginType, ServerArgs} from '@appium/types';
2
+ import {SetOptional} from 'type-fest';
3
+ import {InstallType} from './manifest';
4
+ export type CliCommandServer = 'server';
5
+ export type CliCommandDriver = DriverType;
6
+ export type CliCommandPlugin = PluginType;
7
+
8
+ /**
9
+ * Extension-specific commands
10
+ */
11
+ export type CliExtensionCommand = CliCommandDriver | CliCommandPlugin;
12
+
13
+ /**
14
+ * Possible commands for the `appium` CLI.
15
+ */
16
+ export type CliCommand = CliCommandServer | CliExtensionCommand;
17
+
18
+ /**
19
+ * Possible subcommands of {@linkcode CliCommandDriver} or
20
+ * {@linkcode CliCommandPlugin}.
21
+ */
22
+ export type CliExtensionSubcommand = 'install' | 'list' | 'run' | 'uninstall' | 'update';
23
+
24
+ export interface CliExtensionSubcommandListArgs {
25
+ showInstalled?: boolean;
26
+ showUpdates?: boolean;
27
+ }
28
+
29
+ export interface CliExtensionSubcommandInstallArgs {
30
+ installType: InstallType;
31
+ packageName?: string;
32
+ }
33
+
34
+ export interface CliExtensionSubcommandUpdateArgs {
35
+ unsafe?: boolean;
36
+ }
37
+
38
+ /**
39
+ * Random stuff that may appear in the parsed args which has no equivalent in a
40
+ * config file.
41
+ */
42
+ export interface MoreArgs {
43
+ /**
44
+ * Possible subcommands. If empty, defaults to {@linkcode CliCommandServer}.
45
+ */
46
+ subcommand?: CliCommand;
47
+
48
+ /**
49
+ * Path to config file, if any. Does not make sense for this to be allowed in a config file!
50
+ */
51
+ configFile?: string;
52
+
53
+ /**
54
+ * If true, show the config and exit
55
+ */
56
+ showConfig?: boolean;
57
+
58
+ /**
59
+ * If true, open a REPL
60
+ */
61
+ shell?: boolean;
62
+ }
63
+
64
+ /**
65
+ * These arguments are _not_ supported by the CLI, but only via programmatic usage / tests.
66
+ */
67
+ export interface ProgrammaticArgs {
68
+ /**
69
+ * If `true`, throw on error instead of exit.
70
+ */
71
+ throwInsteadOfExit?: boolean;
72
+
73
+ /**
74
+ * Seems to only be used in tests or standalone driver calls
75
+ */
76
+ logHandler?: (...args: any[]) => void;
77
+
78
+ /**
79
+ * Alternate way to set `APPIUM_HOME` for tests. Since we don't want to muck about
80
+ * with the environment, we just set it here.
81
+ *
82
+ * Setting this means that any discovery of the proper `APPIUM_HOME` path is bypassed
83
+ * and is equivalent to setting `APPIUM_HOME` in the environment.
84
+ */
85
+ appiumHome?: string;
86
+
87
+ /**
88
+ * If true, show the {@link BuildInfo build info} and exit
89
+ */
90
+ showBuildInfo?: boolean;
91
+
92
+ /**
93
+ * If true, show config and exit
94
+ */
95
+ showConfig?: boolean;
96
+ }
97
+
98
+ export interface DriverExtArgs {
99
+ driverCommand: CliExtensionSubcommand;
100
+ driver?: string;
101
+ }
102
+
103
+ export interface PluginExtArgs {
104
+ pluginCommand: CliExtensionSubcommand;
105
+ plugin?: string;
106
+ }
107
+
108
+ /**
109
+ * These are args which the user will specify if using an extension command
110
+ */
111
+ export interface BaseExtArgs<Cmd extends CliExtensionCommand> {
112
+ subcommand: Cmd;
113
+
114
+ /**
115
+ * Output JSON instead of human-readable text
116
+ */
117
+ json?: boolean;
118
+
119
+ /**
120
+ * Output nothing
121
+ */
122
+ suppressOutput?: boolean;
123
+
124
+ /**
125
+ * Extra args to pass to extension scripts
126
+ */
127
+ extraArgs?: string[];
128
+ }
129
+
130
+ /**
131
+ * Args for extension commands; includes a subcommand
132
+ */
133
+ export type ExtArgs<
134
+ Cmd extends CliExtensionCommand,
135
+ SubCmd extends CliExtensionSubcommand
136
+ > = BaseExtArgs<Cmd> &
137
+ (Cmd extends CliCommandDriver
138
+ ? DriverExtArgs
139
+ : Cmd extends CliCommandPlugin
140
+ ? PluginExtArgs
141
+ : never) &
142
+ (SubCmd extends 'install'
143
+ ? CliExtensionSubcommandInstallArgs
144
+ : SubCmd extends 'list'
145
+ ? CliExtensionSubcommandListArgs
146
+ : SubCmd extends 'update'
147
+ ? CliExtensionSubcommandUpdateArgs
148
+ : never);
149
+
150
+ /**
151
+ * Some generic bits of arguments; should not be used outside this declaration
152
+ */
153
+ export type CommonArgs<
154
+ Cmd extends CliCommand = CliCommandServer,
155
+ SubCmd extends CliExtensionSubcommand | void = void
156
+ > = MoreArgs &
157
+ ProgrammaticArgs &
158
+ (Cmd extends CliCommandServer
159
+ ? ServerArgs
160
+ : Cmd extends CliExtensionCommand
161
+ ? SubCmd extends CliExtensionSubcommand
162
+ ? ExtArgs<Cmd, SubCmd>
163
+ : never
164
+ : never);
165
+
166
+ /**
167
+ * Fully-parsed arguments, containing defaults, computed args, and config file values.
168
+ */
169
+ export type ParsedArgs<
170
+ Cmd extends CliCommand = CliCommandServer,
171
+ SubCmd extends CliExtensionSubcommand | void = void
172
+ > = CommonArgs<Cmd, SubCmd>;
173
+
174
+ /**
175
+ * Like {@linkcode ParsedArgs} except server arguments are all optional.
176
+ *
177
+ * _May_ have defaults applied; _may_ contain config values; _may_ contain computed args.
178
+ */
179
+ export type Args<
180
+ Cmd extends CliCommand = CliCommandServer,
181
+ SubCmd extends CliExtensionSubcommand | void = void
182
+ > = Cmd extends CliCommandServer
183
+ ? SetOptional<CommonArgs<Cmd>, keyof ServerArgs>
184
+ : ParsedArgs<Cmd, SubCmd>;
185
+
186
+ /**
187
+ * Shown by `appium --build-info`
188
+ */
189
+ export type BuildInfo = {
190
+ version: string;
191
+ 'git-sha'?: string;
192
+ built?: string;
193
+ };