appium 2.0.0-beta.2 → 2.0.0-beta.23

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 (122) hide show
  1. package/README.md +9 -9
  2. package/build/check-npm-pack-files.js +23 -0
  3. package/build/commands-yml/parse.js +319 -0
  4. package/build/commands-yml/validator.js +130 -0
  5. package/build/index.js +19 -0
  6. package/build/lib/appium-config.schema.json +0 -0
  7. package/build/lib/appium.js +160 -53
  8. package/build/lib/cli/args.js +115 -279
  9. package/build/lib/cli/driver-command.js +11 -1
  10. package/build/lib/cli/extension-command.js +60 -8
  11. package/build/lib/cli/extension.js +30 -7
  12. package/build/lib/cli/npm.js +43 -29
  13. package/build/lib/cli/parser.js +156 -89
  14. package/build/lib/cli/plugin-command.js +11 -1
  15. package/build/lib/cli/utils.js +29 -3
  16. package/build/lib/config-file.js +141 -0
  17. package/build/lib/config.js +53 -65
  18. package/build/lib/driver-config.js +42 -19
  19. package/build/lib/drivers.js +8 -4
  20. package/build/lib/ext-config-io.js +165 -0
  21. package/build/lib/extension-config.js +130 -61
  22. package/build/lib/grid-register.js +22 -24
  23. package/build/lib/logger.js +3 -3
  24. package/build/lib/logsink.js +11 -13
  25. package/build/lib/main.js +197 -77
  26. package/build/lib/plugin-config.js +21 -11
  27. package/build/lib/plugins.js +4 -2
  28. package/build/lib/schema/appium-config-schema.js +253 -0
  29. package/build/lib/schema/arg-spec.js +120 -0
  30. package/build/lib/schema/cli-args.js +188 -0
  31. package/build/lib/schema/cli-transformers.js +76 -0
  32. package/build/lib/schema/index.js +36 -0
  33. package/build/lib/schema/keywords.js +72 -0
  34. package/build/lib/schema/schema.js +357 -0
  35. package/build/lib/utils.js +44 -99
  36. package/build/postinstall.js +90 -0
  37. package/build/test/cli/cli-e2e-specs.js +221 -0
  38. package/build/test/cli/cli-helpers.js +86 -0
  39. package/build/test/cli/cli-specs.js +71 -0
  40. package/build/test/cli/fixtures/test-driver/package.json +27 -0
  41. package/build/test/cli/schema-args-specs.js +48 -0
  42. package/build/test/cli/schema-e2e-specs.js +47 -0
  43. package/build/test/config-e2e-specs.js +112 -0
  44. package/build/test/config-file-e2e-specs.js +209 -0
  45. package/build/test/config-file-specs.js +281 -0
  46. package/build/test/config-specs.js +159 -0
  47. package/build/test/driver-e2e-specs.js +435 -0
  48. package/build/test/driver-specs.js +321 -0
  49. package/build/test/ext-config-io-specs.js +181 -0
  50. package/build/test/extension-config-specs.js +365 -0
  51. package/build/test/fixtures/allow-feat.txt +5 -0
  52. package/build/test/fixtures/caps.json +3 -0
  53. package/build/test/fixtures/config/allow-insecure.txt +3 -0
  54. package/build/test/fixtures/config/appium.config.bad-nodeconfig.json +5 -0
  55. package/build/test/fixtures/config/appium.config.bad.json +32 -0
  56. package/build/test/fixtures/config/appium.config.ext-good.json +9 -0
  57. package/build/test/fixtures/config/appium.config.ext-unknown-props.json +10 -0
  58. package/build/test/fixtures/config/appium.config.good.js +40 -0
  59. package/build/test/fixtures/config/appium.config.good.json +33 -0
  60. package/build/test/fixtures/config/appium.config.good.yaml +30 -0
  61. package/build/test/fixtures/config/appium.config.invalid.json +31 -0
  62. package/build/test/fixtures/config/appium.config.security-array.json +5 -0
  63. package/build/test/fixtures/config/appium.config.security-delimited.json +5 -0
  64. package/build/test/fixtures/config/appium.config.security-path.json +5 -0
  65. package/build/test/fixtures/config/driver-fake.config.json +8 -0
  66. package/build/test/fixtures/config/nodeconfig.json +3 -0
  67. package/build/test/fixtures/config/plugin-fake.config.json +0 -0
  68. package/build/test/fixtures/default-args.js +35 -0
  69. package/build/test/fixtures/deny-feat.txt +5 -0
  70. package/build/test/fixtures/driver.schema.js +20 -0
  71. package/build/test/fixtures/extensions.yaml +27 -0
  72. package/build/test/fixtures/flattened-schema.js +504 -0
  73. package/build/test/fixtures/plugin.schema.js +20 -0
  74. package/build/test/fixtures/schema-with-extensions.js +28 -0
  75. package/build/test/grid-register-specs.js +74 -0
  76. package/build/test/helpers.js +75 -0
  77. package/build/test/logger-specs.js +76 -0
  78. package/build/test/npm-specs.js +20 -0
  79. package/build/test/parser-specs.js +314 -0
  80. package/build/test/plugin-e2e-specs.js +316 -0
  81. package/build/test/schema/arg-spec-specs.js +70 -0
  82. package/build/test/schema/cli-args-specs.js +431 -0
  83. package/build/test/schema/schema-specs.js +389 -0
  84. package/build/test/utils-specs.js +266 -0
  85. package/index.js +11 -0
  86. package/lib/appium-config.schema.json +278 -0
  87. package/lib/appium.js +207 -65
  88. package/lib/cli/args.js +174 -375
  89. package/lib/cli/driver-command.js +4 -0
  90. package/lib/cli/extension-command.js +70 -5
  91. package/lib/cli/extension.js +25 -5
  92. package/lib/cli/npm.js +86 -18
  93. package/lib/cli/parser.js +257 -79
  94. package/lib/cli/plugin-command.js +4 -0
  95. package/lib/cli/utils.js +21 -1
  96. package/lib/config-file.js +227 -0
  97. package/lib/config.js +84 -63
  98. package/lib/driver-config.js +66 -11
  99. package/lib/drivers.js +4 -1
  100. package/lib/ext-config-io.js +287 -0
  101. package/lib/extension-config.js +225 -67
  102. package/lib/grid-register.js +27 -24
  103. package/lib/logger.js +1 -1
  104. package/lib/logsink.js +10 -7
  105. package/lib/main.js +214 -77
  106. package/lib/plugin-config.js +35 -6
  107. package/lib/plugins.js +1 -0
  108. package/lib/schema/appium-config-schema.js +287 -0
  109. package/lib/schema/arg-spec.js +222 -0
  110. package/lib/schema/cli-args.js +285 -0
  111. package/lib/schema/cli-transformers.js +123 -0
  112. package/lib/schema/index.js +2 -0
  113. package/lib/schema/keywords.js +135 -0
  114. package/lib/schema/schema.js +577 -0
  115. package/lib/utils.js +42 -88
  116. package/package.json +55 -84
  117. package/postinstall.js +71 -0
  118. package/types/appium-config.d.ts +197 -0
  119. package/types/types.d.ts +201 -0
  120. package/CHANGELOG.md +0 -3515
  121. package/build/lib/cli/parser-helpers.js +0 -82
  122. package/lib/cli/parser-helpers.js +0 -79
@@ -0,0 +1,285 @@
1
+ // @ts-check
2
+
3
+ import {ArgumentTypeError} from 'argparse';
4
+ import _ from 'lodash';
5
+ import {formatErrors as formatErrors} from '../config-file';
6
+ import {flattenSchema, validate} from './schema';
7
+ import {transformers} from './cli-transformers';
8
+
9
+ /**
10
+ * This module concerns functions which convert schema definitions to
11
+ * `argparse`-compatible data structures, for deriving CLI arguments from a
12
+ * schema.
13
+ */
14
+
15
+ /**
16
+ * Lookup of possible values for the `type` field in a JSON schema.
17
+ * @type {Readonly<Record<string, import('json-schema').JSONSchema7TypeName>>}
18
+ */
19
+ const TYPENAMES = Object.freeze({
20
+ ARRAY: 'array',
21
+ OBJECT: 'object',
22
+ BOOLEAN: 'boolean',
23
+ INTEGER: 'integer',
24
+ NUMBER: 'number',
25
+ NULL: 'null',
26
+ STRING: 'string',
27
+ });
28
+
29
+ /**
30
+ * Options with alias lengths less than this will be considered "short" flags.
31
+ */
32
+ const SHORT_ARG_CUTOFF = 3;
33
+
34
+ /**
35
+ * Convert an alias (`foo`) to a flag (`--foo`) or a short flag (`-f`).
36
+ * @param {ArgSpec} argSpec - the argument specification
37
+ * @param {string} [alias] - the alias to convert to a flag
38
+ * @returns {string} the flag
39
+ */
40
+ function aliasToFlag (argSpec, alias) {
41
+ const {extType, extName, name} = argSpec;
42
+ const arg = alias ?? name;
43
+ const isShort = arg.length < SHORT_ARG_CUTOFF;
44
+ if (extType && extName) {
45
+ return isShort
46
+ ? `--${extType}-${_.kebabCase(extName)}-${arg}`
47
+ : `--${extType}-${_.kebabCase(extName)}-${_.kebabCase(arg)}`;
48
+ }
49
+ return isShort ? `-${arg}` : `--${_.kebabCase(arg)}`;
50
+ }
51
+
52
+ /**
53
+ * Converts a string to SCREAMING_SNAKE_CASE
54
+ */
55
+ const screamingSnakeCase = _.flow(_.snakeCase, _.toUpper);
56
+
57
+ /**
58
+ * Given unique property name `name`, return a function which validates a value
59
+ * against a property within the schema.
60
+ * @template Coerced
61
+ * @param {ArgSpec} argSpec - Argument name
62
+ * @param {(value: string) => Coerced} [coerce] - Function to coerce to a different
63
+ * primitive
64
+ * @todo See if we can remove `coerce` by allowing Ajv to coerce in its
65
+ * constructor options
66
+ * @returns
67
+ */
68
+ function getSchemaValidator ({ref: schemaId}, coerce = _.identity) {
69
+ /** @param {string} value */
70
+ return (value) => {
71
+ const coerced = coerce(value);
72
+ const errors = validate(coerced, schemaId);
73
+ if (_.isEmpty(errors)) {
74
+ return coerced;
75
+ }
76
+ throw new ArgumentTypeError(
77
+ '\n\n' + formatErrors(errors, value, {schemaId}),
78
+ );
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Determine the description for display on the CLI, given the schema.
84
+ * @param {AppiumJSONSchema} schema
85
+ * @returns {string}
86
+ */
87
+ function makeDescription (schema) {
88
+ const {appiumCliDescription, description = '', appiumDeprecated} = schema;
89
+ let desc = appiumCliDescription ?? description;
90
+ if (appiumDeprecated) {
91
+ desc = `[DEPRECATED] ${desc}`;
92
+ }
93
+ return desc;
94
+ }
95
+
96
+ /**
97
+ * Given arg `name`, a JSON schema `subSchema`, and options, return an argument definition
98
+ * as understood by `argparse`.
99
+ * @param {AppiumJSONSchema} subSchema - JSON schema for the option
100
+ * @param {ArgSpec} argSpec - Argument spec tuple
101
+ * @param {SubSchemaToArgDefOptions} [opts] - Options
102
+ * @returns {[string[], import('argparse').ArgumentOptions]} Tuple of flag and options
103
+ */
104
+ function subSchemaToArgDef (subSchema, argSpec, opts = {}) {
105
+ const {overrides = {}} = opts;
106
+ let {
107
+ type,
108
+ appiumCliAliases,
109
+ appiumCliTransformer,
110
+ enum: enumValues,
111
+ } = subSchema;
112
+
113
+ const {name, arg, dest} = argSpec;
114
+
115
+ const aliases = [
116
+ aliasToFlag(argSpec),
117
+ .../** @type {string[]} */ (appiumCliAliases ?? []).map((alias) =>
118
+ aliasToFlag(argSpec, alias),
119
+ ),
120
+ ];
121
+
122
+ /** @type {import('argparse').ArgumentOptions} */
123
+ let argOpts = {
124
+ required: false,
125
+ help: makeDescription(subSchema)
126
+ };
127
+
128
+ /**
129
+ * Generally we will provide a `type` to `argparse` as a function which
130
+ * validates using ajv (which is much more full-featured than what `argparse`
131
+ * can offer). The exception is `boolean`-type options, which have no
132
+ * `argType`.
133
+ *
134
+ * Not sure if this type is correct, but it's not doing what I want. I want
135
+ * to say "this is a function which returns something of type `T` where `T` is
136
+ * never a `Promise`". This function must be sync.
137
+ * @type {((value: string) => unknown)|undefined}
138
+ */
139
+ let argTypeFunction;
140
+
141
+ // handle special cases for various types
142
+ switch (type) {
143
+ // booleans do not have a type per `ArgumentOptions`, just an "action"
144
+ case TYPENAMES.BOOLEAN: {
145
+ argOpts.action = 'store_true';
146
+ break;
147
+ }
148
+
149
+ case TYPENAMES.OBJECT: {
150
+ argTypeFunction = transformers.json;
151
+ break;
152
+ }
153
+
154
+ // arrays are treated as CSVs, because `argparse` doesn't handle array data.
155
+ case TYPENAMES.ARRAY: {
156
+ argTypeFunction = transformers.csv;
157
+ break;
158
+ }
159
+
160
+ // "number" type is coerced to float. `argparse` does this for us if we use `float` type, but
161
+ // we don't.
162
+ case TYPENAMES.NUMBER: {
163
+ argTypeFunction = getSchemaValidator(argSpec, parseFloat);
164
+ break;
165
+ }
166
+
167
+ // "integer" is coerced to an .. integer. again, `argparse` would do this for us if we used `int`.
168
+ case TYPENAMES.INTEGER: {
169
+ argTypeFunction = getSchemaValidator(argSpec, _.parseInt);
170
+ break;
171
+ }
172
+
173
+ // strings (like number and integer) are subject to further validation
174
+ // (e.g., must satisfy a mask or regex or even some custom validation
175
+ // function)
176
+ case TYPENAMES.STRING: {
177
+ argTypeFunction = getSchemaValidator(argSpec);
178
+ break;
179
+ }
180
+
181
+ // TODO: there may be some way to restrict this at the Ajv level --
182
+ // that may involve patching the metaschema.
183
+ case TYPENAMES.NULL:
184
+ // falls through
185
+ default: {
186
+ throw new TypeError(
187
+ `Schema property "${arg}": \`${type}\` type unknown or disallowed`,
188
+ );
189
+ }
190
+ }
191
+
192
+ // metavar is used in help text. `boolean` cannot have a metavar--it is not
193
+ // displayed--and `argparse` throws if you give it one.
194
+ if (type !== TYPENAMES.BOOLEAN) {
195
+ argOpts.metavar = screamingSnakeCase(name);
196
+ }
197
+
198
+ // the validity of "appiumCliTransformer" should already have been determined
199
+ // by ajv during schema validation in `finalizeSchema()`. the `array` &
200
+ // `object` types have already added a formatter (see above, so we don't do it
201
+ // twice).
202
+ if (
203
+ type !== TYPENAMES.ARRAY &&
204
+ type !== TYPENAMES.OBJECT &&
205
+ appiumCliTransformer
206
+ ) {
207
+ argTypeFunction = _.flow(
208
+ argTypeFunction ?? _.identity,
209
+ transformers[appiumCliTransformer],
210
+ );
211
+ }
212
+
213
+ if (argTypeFunction) {
214
+ argOpts.type = argTypeFunction;
215
+ }
216
+
217
+ // convert JSON schema `enum` to `choices`. `enum` can contain any JSON type, but `argparse`
218
+ // is limited to a single type per arg (I think). so let's make everything a string.
219
+ // and might as well _require_ the `type: string` while we're at it.
220
+ if (enumValues && !_.isEmpty(enumValues)) {
221
+ if (type === TYPENAMES.STRING) {
222
+ argOpts.choices = enumValues.map(String);
223
+ } else {
224
+ throw new TypeError(
225
+ `Problem with schema for ${arg}; \`enum\` is only supported for \`type: 'string'\``,
226
+ );
227
+ }
228
+ }
229
+
230
+ // overrides override anything we computed here. usually this involves "custom types",
231
+ // which are really just transform functions.
232
+ argOpts = _.merge(
233
+ argOpts,
234
+ /** should the override keys correspond to the prop name or the prop dest?
235
+ * the prop dest is computed by {@link aliasToDest}.
236
+ */
237
+ overrides[dest] ?? {},
238
+ );
239
+
240
+ return [aliases, argOpts];
241
+ }
242
+
243
+ /**
244
+ * Converts the finalized, flattened schema representation into
245
+ * ArgumentDefinitions for handoff to `argparse`.
246
+ *
247
+ * @param {ToParserArgsOptions} opts - Options
248
+ * @throws If schema has not been added to ajv (via `finalizeSchema()`)
249
+ * @returns {import('../cli/args').ArgumentDefinitions} A map of arryas of
250
+ * aliases to `argparse` arguments; empty if no schema found
251
+ */
252
+ export function toParserArgs (opts = {}) {
253
+ const flattened = flattenSchema().filter(({schema}) => !schema.appiumCliIgnored);
254
+ return new Map(
255
+ _.map(flattened, ({schema, argSpec}) =>
256
+ subSchemaToArgDef(schema, argSpec, opts),
257
+ ),
258
+ );
259
+ }
260
+
261
+ /**
262
+ * Options for {@link toParserArgs}
263
+ * @typedef {SubSchemaToArgDefOptions} ToParserArgsOptions
264
+ */
265
+
266
+ /**
267
+ * Options for {@link subSchemaToArgDef}.
268
+ * @typedef {Object} SubSchemaToArgDefOptions
269
+ * @property {string} [prefix] - The prefix to use for the flag, if any
270
+ * @property {{[key: string]: import('argparse').ArgumentOptions}} [overrides] - An object of key/value pairs to override the default values
271
+ */
272
+
273
+ /**
274
+ * @template T
275
+ * @typedef {import('ajv/dist/types').FormatValidator<T>} FormatValidator<T>
276
+ */
277
+
278
+ /**
279
+ * A JSON 7 schema with our custom keywords.
280
+ * @typedef {import('./keywords').AppiumJSONSchemaKeywords & import('json-schema').JSONSchema7} AppiumJSONSchema
281
+ */
282
+
283
+ /**
284
+ * @typedef {import('./arg-spec').ArgSpec} ArgSpec
285
+ */
@@ -0,0 +1,123 @@
1
+ // @ts-check
2
+
3
+ import { ArgumentTypeError } from 'argparse';
4
+ import { readFileSync } from 'fs';
5
+ import _ from 'lodash';
6
+
7
+ /**
8
+ * This module provides custom keywords for Appium schemas, as well as
9
+ * "transformers" (see `argTransformers` below).
10
+ *
11
+ * Custom keywords are just properties that will appear in a schema (e.g.,
12
+ * `appium-config-schema.js`) beyond what the JSON Schema spec offers. These
13
+ * are usable by extensions, as well.
14
+ */
15
+
16
+ /**
17
+ * Splits a CSV string into an array
18
+ * @param {string} value
19
+ * @returns {string[]}
20
+ */
21
+ function parseCsvLine (value) {
22
+ return value
23
+ .split(',')
24
+ .map((v) => v.trim())
25
+ .filter(Boolean);
26
+ }
27
+
28
+ /**
29
+ * Split a file by newline then calls {@link parseCsvLine} on each line.
30
+ * @param {string} value
31
+ * @returns {string[]}
32
+ */
33
+ function parseCsvFile (value) {
34
+ return value
35
+ .split(/\r?\n/)
36
+ .map((v) => v.trim())
37
+ .filter(Boolean)
38
+ .flatMap(parseCsvLine);
39
+ }
40
+
41
+ /**
42
+ * Namespace containing _transformers_ for CLI arguments. "Validators" and
43
+ * "formatters" do not actually modify the value, but these do.
44
+ *
45
+ * Use case is for when the config file can accept e.g., a `string[]`, but the
46
+ * CLI can only take a `string` (as `argparse` seems to be limited in that
47
+ * fashion; it also cannot understand an argument having multiple types).
48
+ *
49
+ * For example, the `csv` transform takes a `string` and returns a `string[]` by
50
+ * splitting it by comma--_or_ if that `string` happens to be a
51
+ * filepath--reading the file as a `.csv`.
52
+ *
53
+ * This contains some copy-pasted code from `lib/cli/parser-helpers.js`, which was
54
+ * obliterated.
55
+ */
56
+ export const transformers = {
57
+ /**
58
+ * Given a CSV-style string or pathname, parse it into an array.
59
+ * The file can also be split on newlines.
60
+ * @param {string} value
61
+ * @returns {string[]}
62
+ */
63
+ csv: (value) => {
64
+ let body;
65
+ // since this value could be a single string (no commas) _or_ a pathname, we will need
66
+ // to attempt to parse it as a file _first_.
67
+ try {
68
+ body = readFileSync(value, 'utf8');
69
+ } catch (err) {
70
+ if (err.code !== 'ENOENT') {
71
+ throw new ArgumentTypeError(
72
+ `Could not read file ${body}: ${err.message}`,
73
+ );
74
+ }
75
+ }
76
+
77
+ try {
78
+ return body ? parseCsvFile(body) : parseCsvLine(value);
79
+ } catch (err) {
80
+ throw new ArgumentTypeError(
81
+ 'Must be a comma-delimited string, e.g., "foo,bar,baz"',
82
+ );
83
+ }
84
+ },
85
+
86
+ /**
87
+ * Parse a string which could be a path to a JSON file or a JSON string.
88
+ * @param {string} jsonOrPath
89
+ * @returns {object}
90
+ */
91
+ json: (jsonOrPath) => {
92
+ let json = jsonOrPath;
93
+ let loadedFromFile = false;
94
+ try {
95
+ // use synchronous file access, as `argparse` provides no way of either
96
+ // awaiting or using callbacks. This step happens in startup, in what is
97
+ // effectively command-line code, so nothing is blocked in terms of
98
+ // sessions, so holding up the event loop does not incur the usual
99
+ // drawbacks.
100
+ json = readFileSync(jsonOrPath, 'utf8');
101
+ loadedFromFile = true;
102
+ } catch (err) {
103
+ // unreadable files don't count... but other problems do.
104
+ if (err.code !== 'ENOENT') {
105
+ throw err;
106
+ }
107
+ }
108
+ try {
109
+ const result = JSON.parse(json);
110
+ if (!_.isPlainObject(result)) {
111
+ throw new Error(
112
+ `'${_.truncate(result, {length: 100})}' is not an object`,
113
+ );
114
+ }
115
+ return result;
116
+ } catch (e) {
117
+ const msg = loadedFromFile
118
+ ? `The provided value of '${jsonOrPath}' must be a valid JSON`
119
+ : `The provided value must be a valid JSON`;
120
+ throw new TypeError(`${msg}. Original error: ${e.message}`);
121
+ }
122
+ },
123
+ };
@@ -0,0 +1,2 @@
1
+ export * from './schema';
2
+ export * from './cli-args';
@@ -0,0 +1,135 @@
1
+ // @ts-check
2
+
3
+ import { transformers } from './cli-transformers';
4
+
5
+ /**
6
+ * Collection of keyword definitions to add to the singleton `Ajv` instance.
7
+ * @type {Record<string,KeywordDefinition>}
8
+ */
9
+ export const keywords = {
10
+ /**
11
+ * Keyword to provide a list of command alias names for the CLI.
12
+ *
13
+ * If defined, there must be at least one item in the array and it must be non-empty.
14
+ * All items in the array must be unique.
15
+ *
16
+ * @todo Avoid alias collisions!
17
+ * @type {KeywordDefinition}
18
+ * @example
19
+ * {appiumCliAliases: ['B', 'bobby', 'robert']}
20
+ */
21
+ appiumCliAliases: {
22
+ keyword: 'appiumCliAliases',
23
+ metaSchema: {
24
+ type: 'array',
25
+ items: {
26
+ type: 'string',
27
+ minLength: 1,
28
+ },
29
+ minItems: 1,
30
+ uniqueItems: true,
31
+ description: 'List of aliases for the argument. Aliases shorter than three (3) characters will be prefixed with a single dash; otherwise two (2).'
32
+ },
33
+ },
34
+ /**
35
+ * Keyword to provide the name of the property in the destination (parsed
36
+ * args) object. By default, this value will be whatever the property name is,
37
+ * but camel-cased. If a flag needs something _other_ than just camel-casing,
38
+ * use this.
39
+ * @type {KeywordDefinition}
40
+ * @example
41
+ * // for prop 'no-color'
42
+ * {appiumCliDest: 'NOCOLOR'} // value will be stored as property `NOCOLOR` instead of `noColor`
43
+ */
44
+ appiumCliDest: {
45
+ keyword: 'appiumCliDest',
46
+ metaSchema: {
47
+ type: 'string',
48
+ minLength: 1,
49
+ description: 'Name of the associated property in the parsed CLI arguments object'
50
+ },
51
+ },
52
+
53
+ /**
54
+ * CLI-specific description of the property. Sometimes the allowed type can
55
+ * be different enough on the CLI that providing a description written for a
56
+ * config file context wouldn't make sense.
57
+ * @type {KeywordDefinition}
58
+ * @example
59
+ * {appiumCliDescription: 'This is a comma-delimited string, but in the config file it is an array'}
60
+ */
61
+ appiumCliDescription: {
62
+ keyword: 'appiumCliDescription',
63
+ schemaType: 'string',
64
+ metaSchema: {
65
+ type: 'string',
66
+ minLength: 1,
67
+ description: 'Description to provide in the --help text of the CLI. Overrides `description`'
68
+ },
69
+ },
70
+
71
+ /**
72
+ * Transformers for CLI args. These usually take strings then do something with them, like
73
+ * read a file or parse further.
74
+ * @type {KeywordDefinition}
75
+ */
76
+ appiumCliTransformer: {
77
+ keyword: 'appiumCliTransformer',
78
+ metaSchema: {
79
+ type: 'string',
80
+ enum: Object.keys(transformers),
81
+ description: 'The name of a custom transformer to run against the value as provided via the CLI.'
82
+ },
83
+ },
84
+
85
+ /**
86
+ * Flag to tell Appium to _not_ provide this property as a CLI argument.
87
+ * @type {KeywordDefinition}
88
+ */
89
+ appiumCliIgnored: {
90
+ keyword: 'appiumCliIgnored',
91
+ metaSchema: {
92
+ type: 'boolean',
93
+ description: 'If `true`, Appium will not provide this property as a CLI argument. This is NOT the same as a "hidden" argument.',
94
+ enum: [true]
95
+ }
96
+ },
97
+
98
+ /**
99
+ * Mark this property as deprecated.
100
+ * @type {KeywordDefinition}
101
+ */
102
+ appiumDeprecated: {
103
+ keyword: 'appiumDeprecated',
104
+ metaSchema: {
105
+ type: 'boolean',
106
+ description: 'If `true`, this property will be displayed as "deprecated" to the user',
107
+ enum: [true],
108
+ $comment: 'JSON schema draft-2019-09 keyword `deprecated` serves the same purpose. This keyword should itself be deprecated if we move to draft-2019-09!'
109
+ }
110
+ }
111
+ };
112
+
113
+ /**
114
+ * These are the valid values for the `appiumCliTransformer` keyword.
115
+ * Unfortunately, TS cannot infer this in a JS context. In TS, we'd use
116
+ * `as const` when defining `argTransformers`, then get `keyof typeof argTransformers`. alas.
117
+ * @typedef {'csv'|'json'} AppiumCliTransformerName
118
+ */
119
+
120
+ /**
121
+ * These are the custom keywords that Appium recognizes.
122
+ *
123
+ * @typedef {Object} AppiumJSONSchemaKeywords
124
+ * @property {string} [appiumCliDest]
125
+ * @property {string} [appiumCliDescription]
126
+ * @property {string[]} [appiumCliAliases]
127
+ * @property {boolean} [appiumCliIgnored]
128
+ * @property {AppiumCliTransformerName} [appiumCliTransformer]
129
+ * @property {boolean} [appiumDeprecated]
130
+ */
131
+
132
+
133
+ /**
134
+ * @typedef {import('ajv').KeywordDefinition} KeywordDefinition
135
+ */