appium 3.2.2 → 3.3.0
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.
- package/build/lib/cli/args.d.ts +16 -12
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +15 -35
- package/build/lib/cli/args.js.map +1 -1
- package/build/lib/cli/driver-command.d.ts +51 -93
- package/build/lib/cli/driver-command.d.ts.map +1 -1
- package/build/lib/cli/driver-command.js +11 -66
- package/build/lib/cli/driver-command.js.map +1 -1
- package/build/lib/cli/extension-command.d.ts +211 -415
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +384 -653
- package/build/lib/cli/extension-command.js.map +1 -1
- package/build/lib/cli/extension.d.ts +11 -16
- package/build/lib/cli/extension.d.ts.map +1 -1
- package/build/lib/cli/extension.js +10 -28
- package/build/lib/cli/extension.js.map +1 -1
- package/build/lib/cli/parser.d.ts +40 -69
- package/build/lib/cli/parser.d.ts.map +1 -1
- package/build/lib/cli/parser.js +24 -59
- package/build/lib/cli/parser.js.map +1 -1
- package/build/lib/cli/plugin-command.d.ts +50 -90
- package/build/lib/cli/plugin-command.d.ts.map +1 -1
- package/build/lib/cli/plugin-command.js +11 -63
- package/build/lib/cli/plugin-command.js.map +1 -1
- package/build/lib/cli/setup-command.d.ts +21 -26
- package/build/lib/cli/setup-command.d.ts.map +1 -1
- package/build/lib/cli/setup-command.js +13 -55
- package/build/lib/cli/setup-command.js.map +1 -1
- package/build/lib/cli/utils.d.ts +27 -29
- package/build/lib/cli/utils.d.ts.map +1 -1
- package/build/lib/cli/utils.js +29 -31
- package/build/lib/cli/utils.js.map +1 -1
- package/build/lib/config-file.d.ts +24 -67
- package/build/lib/config-file.d.ts.map +1 -1
- package/build/lib/config-file.js +56 -115
- package/build/lib/config-file.js.map +1 -1
- package/build/lib/config.d.ts +42 -44
- package/build/lib/config.d.ts.map +1 -1
- package/build/lib/config.js +75 -107
- package/build/lib/config.js.map +1 -1
- package/build/lib/constants.d.ts +23 -23
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +10 -15
- package/build/lib/constants.js.map +1 -1
- package/build/lib/doctor/doctor.d.ts +40 -57
- package/build/lib/doctor/doctor.d.ts.map +1 -1
- package/build/lib/doctor/doctor.js +29 -60
- package/build/lib/doctor/doctor.js.map +1 -1
- package/build/lib/grid-register.d.ts +32 -7
- package/build/lib/grid-register.d.ts.map +1 -1
- package/build/lib/grid-register.js +84 -48
- package/build/lib/grid-register.js.map +1 -1
- package/build/lib/logsink.d.ts +13 -22
- package/build/lib/logsink.d.ts.map +1 -1
- package/build/lib/logsink.js +48 -103
- package/build/lib/logsink.js.map +1 -1
- package/build/lib/main.js +1 -1
- package/build/lib/main.js.map +1 -1
- package/build/lib/schema/arg-spec.d.ts +32 -107
- package/build/lib/schema/arg-spec.d.ts.map +1 -1
- package/build/lib/schema/arg-spec.js +11 -107
- package/build/lib/schema/arg-spec.js.map +1 -1
- package/build/lib/schema/cli-args.d.ts +3 -15
- package/build/lib/schema/cli-args.d.ts.map +1 -1
- package/build/lib/schema/cli-args.js +15 -105
- package/build/lib/schema/cli-args.js.map +1 -1
- package/build/lib/schema/cli-transformers.d.ts +15 -12
- package/build/lib/schema/cli-transformers.d.ts.map +1 -1
- package/build/lib/schema/cli-transformers.js +15 -45
- package/build/lib/schema/cli-transformers.js.map +1 -1
- package/build/lib/schema/index.d.ts +2 -2
- package/build/lib/schema/index.d.ts.map +1 -1
- package/build/lib/schema/index.js.map +1 -1
- package/build/lib/schema/keywords.d.ts +12 -20
- package/build/lib/schema/keywords.d.ts.map +1 -1
- package/build/lib/schema/keywords.js +6 -51
- package/build/lib/schema/keywords.js.map +1 -1
- package/build/lib/schema/schema.d.ts +106 -231
- package/build/lib/schema/schema.d.ts.map +1 -1
- package/build/lib/schema/schema.js +75 -345
- package/build/lib/schema/schema.js.map +1 -1
- package/build/lib/utils.d.ts +59 -238
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +55 -207
- package/build/lib/utils.js.map +1 -1
- package/lib/cli/{args.js → args.ts} +40 -51
- package/lib/cli/driver-command.ts +122 -0
- package/lib/cli/{extension-command.js → extension-command.ts} +610 -689
- package/lib/cli/extension.ts +65 -0
- package/lib/cli/{parser.js → parser.ts} +48 -71
- package/lib/cli/plugin-command.ts +117 -0
- package/lib/cli/{setup-command.js → setup-command.ts} +57 -72
- package/lib/cli/utils.ts +97 -0
- package/lib/config-file.ts +212 -0
- package/lib/{config.js → config.ts} +129 -141
- package/lib/{constants.js → constants.ts} +30 -41
- package/lib/doctor/{doctor.js → doctor.ts} +81 -91
- package/lib/grid-register.ts +250 -0
- package/lib/{logsink.js → logsink.ts} +91 -137
- package/lib/main.js +1 -1
- package/lib/schema/arg-spec.ts +131 -0
- package/lib/schema/cli-args.ts +171 -0
- package/lib/schema/cli-transformers.ts +83 -0
- package/lib/schema/keywords.ts +96 -0
- package/lib/schema/schema.ts +449 -0
- package/lib/utils.ts +404 -0
- package/package.json +16 -16
- package/lib/cli/driver-command.js +0 -174
- package/lib/cli/extension.js +0 -74
- package/lib/cli/plugin-command.js +0 -164
- package/lib/cli/utils.js +0 -91
- package/lib/config-file.js +0 -228
- package/lib/grid-register.js +0 -146
- package/lib/schema/arg-spec.js +0 -229
- package/lib/schema/cli-args.js +0 -254
- package/lib/schema/cli-transformers.js +0 -113
- package/lib/schema/keywords.js +0 -136
- package/lib/schema/schema.js +0 -725
- package/lib/utils.js +0 -512
- /package/lib/schema/{index.js → index.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-spec.d.ts","sourceRoot":"","sources":["../../../lib/schema/arg-spec.
|
|
1
|
+
{"version":3,"file":"arg-spec.d.ts","sourceRoot":"","sources":["../../../lib/schema/arg-spec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,uBAA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C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAInD;;OAEG;IACH,MAAM,CAAC,6BAA6B,CAClC,QAAQ,EAAE,MAAM,GACf;QAAC,OAAO,CAAC,EAAE,aAAa,CAAC;QAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAC;IAYxD;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAIxF,QAAQ,IAAI,MAAM;CAOnB"}
|
|
@@ -13,89 +13,33 @@ exports.APPIUM_CONFIG_SCHEMA_ID = 'appium.json';
|
|
|
13
13
|
/**
|
|
14
14
|
* The schema prop containing server-related options. Everything in here
|
|
15
15
|
* is "native" to Appium.
|
|
16
|
-
* Used by {@link flattenSchema} for transforming the schema into CLI args.
|
|
17
16
|
*/
|
|
18
17
|
exports.SERVER_PROP_NAME = 'server';
|
|
19
|
-
/**
|
|
20
|
-
* Used to parse extension info from a schema ID.
|
|
21
|
-
*/
|
|
22
18
|
const SCHEMA_ID_REGEXP = /^(?<extType>.+?)-(?<normalizedExtName>.+)\.json$/;
|
|
23
|
-
/**
|
|
24
|
-
* Avoid typos by using constants!
|
|
25
|
-
*/
|
|
26
19
|
const PROPERTIES = 'properties';
|
|
27
20
|
/**
|
|
28
21
|
* An `ArgSpec` is a class representing metadata about an argument (or config
|
|
29
22
|
* option) used for cross-referencing.
|
|
30
23
|
*
|
|
31
|
-
* This class has no instance methods
|
|
32
|
-
*
|
|
24
|
+
* This class has no instance methods beyond stringification and is effectively
|
|
25
|
+
* a read-only struct.
|
|
33
26
|
*/
|
|
34
27
|
class ArgSpec {
|
|
35
|
-
/**
|
|
36
|
-
* The canonical name of the argument. Corresponds to key in schema's `properties` prop.
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
28
|
name;
|
|
40
|
-
/**
|
|
41
|
-
* The `ExtensionType` of the argument. This will be set if the arg came from an extension;
|
|
42
|
-
* otherwise it will be `undefined`.
|
|
43
|
-
* @type {ExtensionType|undefined}
|
|
44
|
-
*/
|
|
45
29
|
extType;
|
|
46
|
-
/**
|
|
47
|
-
* The name of the extension, if this argument came from an extension.
|
|
48
|
-
*
|
|
49
|
-
* Otherwise `undefined`.
|
|
50
|
-
* @type {string|undefined}
|
|
51
|
-
*/
|
|
52
30
|
extName;
|
|
53
|
-
/**
|
|
54
|
-
* The schema ID (`$id`) for the argument. This is automatically determined, and any user-provided `$id`s will be overwritten.
|
|
55
|
-
*
|
|
56
|
-
* @type {string}
|
|
57
|
-
*/
|
|
58
31
|
ref;
|
|
59
|
-
/**
|
|
60
|
-
* The CLI argument, sans leading dashes.
|
|
61
|
-
* @type {string}
|
|
62
|
-
*/
|
|
63
32
|
arg;
|
|
64
|
-
/**
|
|
65
|
-
* The desired keypath for the argument after arguments have been parsed.
|
|
66
|
-
*
|
|
67
|
-
* Typically this is camelCased. If the arg came from an extension, it will be prefixed with
|
|
68
|
-
* `<extType>.<extName>.`
|
|
69
|
-
* @type {string}
|
|
70
|
-
*/
|
|
71
33
|
dest;
|
|
72
|
-
/**
|
|
73
|
-
* The same as {@link ArgSpec.dest} but without the leading `<extType>.<extName>.` prefix.
|
|
74
|
-
*/
|
|
75
34
|
rawDest;
|
|
76
|
-
/**
|
|
77
|
-
* Whatever the default value of this argument is, as specified by the
|
|
78
|
-
* `default` property of the schema.
|
|
79
|
-
* @type {D|undefined}
|
|
80
|
-
*/
|
|
81
35
|
defaultValue;
|
|
82
36
|
/**
|
|
83
|
-
* Builds
|
|
84
|
-
*
|
|
85
|
-
* Undefined properties are not assigned.
|
|
86
|
-
*
|
|
87
|
-
* The _constructor_ is private. Use {@link ArgSpec.create} instead.
|
|
88
|
-
* @private
|
|
89
|
-
* @param {string} name
|
|
90
|
-
* @param {ArgSpecOptions<D>} opts
|
|
37
|
+
* Builds computed fields and assigns them to the instance.
|
|
38
|
+
* Use {@link ArgSpec.create} instead of `new ArgSpec()`.
|
|
91
39
|
*/
|
|
92
40
|
constructor(name, { extType, extName, dest, defaultValue } = {}) {
|
|
93
|
-
// we must normalize the extension name to fit into our convention for CLI
|
|
94
|
-
// args.
|
|
95
41
|
const arg = ArgSpec.toArg(name, extType, extName);
|
|
96
42
|
const ref = ArgSpec.toSchemaRef(name, extType, extName);
|
|
97
|
-
// if no explicit `dest` provided, just camelCase the name to avoid needing
|
|
98
|
-
// to use bracket syntax when accessing props on the parsed args object.
|
|
99
43
|
const rawDest = lodash_1.default.camelCase(dest ?? name);
|
|
100
44
|
const destKeypath = extType && extName ? [extType, extName, rawDest].join('.') : rawDest;
|
|
101
45
|
this.defaultValue = defaultValue;
|
|
@@ -108,13 +52,7 @@ class ArgSpec {
|
|
|
108
52
|
this.rawDest = rawDest;
|
|
109
53
|
}
|
|
110
54
|
/**
|
|
111
|
-
* Return the schema ID (`$id`) for the
|
|
112
|
-
*
|
|
113
|
-
* If you need the "root" or "base" schema ID, use {@link ArgSpec.toSchemaBaseRef} instead.
|
|
114
|
-
* @param {string} name - Argument name
|
|
115
|
-
* @param {ExtensionType} [extType] - Extension type
|
|
116
|
-
* @param {string} [extName] - Extension name
|
|
117
|
-
* @returns {string} Schema ID
|
|
55
|
+
* Return the schema ID (`$id`) for the argument given the parameters.
|
|
118
56
|
*/
|
|
119
57
|
static toSchemaRef(name, extType, extName) {
|
|
120
58
|
const baseRef = ArgSpec.toSchemaBaseRef(extType, extName);
|
|
@@ -124,9 +62,7 @@ class ArgSpec {
|
|
|
124
62
|
return [`${baseRef}#`, PROPERTIES, exports.SERVER_PROP_NAME, PROPERTIES, name].join('/');
|
|
125
63
|
}
|
|
126
64
|
/**
|
|
127
|
-
* Return the schema ID for an extension or
|
|
128
|
-
* @param {ExtensionType} [extType] - Extension type
|
|
129
|
-
* @param {string} [extName] - Extension name
|
|
65
|
+
* Return the root schema ID for an extension or Appium base schema.
|
|
130
66
|
*/
|
|
131
67
|
static toSchemaBaseRef(extType, extName) {
|
|
132
68
|
if (extType && extName) {
|
|
@@ -135,11 +71,7 @@ class ArgSpec {
|
|
|
135
71
|
return exports.APPIUM_CONFIG_SCHEMA_ID;
|
|
136
72
|
}
|
|
137
73
|
/**
|
|
138
|
-
* Return the unique
|
|
139
|
-
* @param {string} name - Argument name
|
|
140
|
-
* @param {ExtensionType} [extType] - Extension type
|
|
141
|
-
* @param {string} [extName] - Extension name
|
|
142
|
-
* @returns {string} Unique ID
|
|
74
|
+
* Return the unique CLI argument key for the argument.
|
|
143
75
|
*/
|
|
144
76
|
static toArg(name, extType, extName) {
|
|
145
77
|
const properName = lodash_1.default.kebabCase(name.replace(/^--?/, ''));
|
|
@@ -149,44 +81,28 @@ class ArgSpec {
|
|
|
149
81
|
return properName;
|
|
150
82
|
}
|
|
151
83
|
/**
|
|
152
|
-
* Normalizes a raw extension name (not including
|
|
153
|
-
* @param {string} extName - Extension name
|
|
154
|
-
* @returns {string} Normalized extension name
|
|
84
|
+
* Normalizes a raw extension name (not including type).
|
|
155
85
|
*/
|
|
156
86
|
static toNormalizedExtName(extName) {
|
|
157
87
|
return lodash_1.default.kebabCase(extName);
|
|
158
88
|
}
|
|
159
89
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @param {string} schemaId - Root schema ID
|
|
162
|
-
* @returns { {extType?: ExtensionType, normalizedExtName?: string} }
|
|
90
|
+
* Parse root schema ID (`<extType>-<normalizedExtName>.json`) to extension info.
|
|
163
91
|
*/
|
|
164
92
|
static extensionInfoFromRootSchemaId(schemaId) {
|
|
165
93
|
const matches = schemaId.match(SCHEMA_ID_REGEXP);
|
|
166
94
|
if (matches?.groups) {
|
|
167
|
-
const { extType, normalizedExtName } =
|
|
168
|
-
/** @type { {extType: ExtensionType, normalizedExtName: string} } */ (matches.groups);
|
|
95
|
+
const { extType, normalizedExtName } = matches.groups;
|
|
169
96
|
return { extType, normalizedExtName };
|
|
170
97
|
}
|
|
171
98
|
return {};
|
|
172
99
|
}
|
|
173
100
|
/**
|
|
174
|
-
* Creates
|
|
175
|
-
*
|
|
176
|
-
* @param {string} name - The canonical name of the argument. Corresponds to a key in a schema's
|
|
177
|
-
* `properties` property.
|
|
178
|
-
* @template D
|
|
179
|
-
* @param {ArgSpecOptions<D>} [opts] - Options
|
|
180
|
-
* @returns {Readonly<ArgSpec>}
|
|
101
|
+
* Creates a frozen `ArgSpec`.
|
|
181
102
|
*/
|
|
182
103
|
static create(name, opts) {
|
|
183
104
|
return Object.freeze(new ArgSpec(name, opts));
|
|
184
105
|
}
|
|
185
|
-
/**
|
|
186
|
-
* String representation, useful for debugging
|
|
187
|
-
* @returns {string}
|
|
188
|
-
*/
|
|
189
|
-
/* istanbul ignore next */
|
|
190
106
|
toString() {
|
|
191
107
|
let str = `[ArgSpec] ${this.name} (${this.ref})`;
|
|
192
108
|
if (this.extType && this.extName) {
|
|
@@ -196,16 +112,4 @@ class ArgSpec {
|
|
|
196
112
|
}
|
|
197
113
|
}
|
|
198
114
|
exports.ArgSpec = ArgSpec;
|
|
199
|
-
/**
|
|
200
|
-
* Options for {@link ArgSpec.create}
|
|
201
|
-
* @template D
|
|
202
|
-
* @typedef ArgSpecOptions
|
|
203
|
-
* @property {string} [extName]
|
|
204
|
-
* @property {ExtensionType} [extType]
|
|
205
|
-
* @property {string} [dest]
|
|
206
|
-
* @property {D} [defaultValue]
|
|
207
|
-
*/
|
|
208
|
-
/**
|
|
209
|
-
* @typedef {import('@appium/types').ExtensionType} ExtensionType
|
|
210
|
-
*/
|
|
211
115
|
//# sourceMappingURL=arg-spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-spec.js","sourceRoot":"","sources":["../../../lib/schema/arg-spec.
|
|
1
|
+
{"version":3,"file":"arg-spec.js","sourceRoot":"","sources":["../../../lib/schema/arg-spec.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAGvB;;;GAGG;AACU,QAA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AM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACjD,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YACpB,MAAM,EAAC,OAAO,EAAE,iBAAiB,EAAC,GAAG,OAAO,CAAC,MAG5C,CAAC;YACF,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,CAAC;QACtC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAc,IAAY,EAAE,IAAwB;QAC/D,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,QAAQ;QACN,IAAI,GAAG,GAAG,aAAa,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC;QACjD,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,IAAI,UAAU,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC;QACnD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AApGD,0BAoGC"}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
+
import type { ArgumentDefinitions } from '../cli/args';
|
|
1
2
|
/**
|
|
2
3
|
* Converts the finalized, flattened schema representation into
|
|
3
|
-
* ArgumentDefinitions for handoff to `argparse`.
|
|
4
|
-
*
|
|
5
|
-
* @throws If schema has not been added to ajv (via `finalizeSchema()`)
|
|
6
|
-
* @returns {import('../cli/args').ArgumentDefinitions} A map of arrays of
|
|
7
|
-
* aliases to `argparse` arguments; empty if no schema found
|
|
4
|
+
* `ArgumentDefinitions` for handoff to `argparse`.
|
|
8
5
|
*/
|
|
9
|
-
export function toParserArgs():
|
|
10
|
-
/**
|
|
11
|
-
* <T>
|
|
12
|
-
*/
|
|
13
|
-
export type FormatValidator<T extends string | number> = import("ajv/dist/types").FormatValidator<T>;
|
|
14
|
-
/**
|
|
15
|
-
* A JSON 7 schema with our custom keywords.
|
|
16
|
-
*/
|
|
17
|
-
export type AppiumJSONSchema = import("./keywords").AppiumJSONSchemaKeywords & import("json-schema").JSONSchema7;
|
|
18
|
-
export type ArgSpec = import("./arg-spec").ArgSpec<any>;
|
|
6
|
+
export declare function toParserArgs(): ArgumentDefinitions;
|
|
19
7
|
//# sourceMappingURL=cli-args.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../../lib/schema/cli-args.
|
|
1
|
+
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../../lib/schema/cli-args.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAiBrD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,mBAAmB,CAKlD"}
|
|
@@ -9,15 +9,6 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
9
9
|
const config_file_1 = require("../config-file");
|
|
10
10
|
const schema_1 = require("./schema");
|
|
11
11
|
const cli_transformers_1 = require("./cli-transformers");
|
|
12
|
-
/**
|
|
13
|
-
* This module concerns functions which convert schema definitions to
|
|
14
|
-
* `argparse`-compatible data structures, for deriving CLI arguments from a
|
|
15
|
-
* schema.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Lookup of possible values for the `type` field in a JSON schema.
|
|
19
|
-
* @type {Readonly<Record<string, import('json-schema').JSONSchema7TypeName>>}
|
|
20
|
-
*/
|
|
21
12
|
const TYPENAMES = Object.freeze({
|
|
22
13
|
ARRAY: 'array',
|
|
23
14
|
OBJECT: 'object',
|
|
@@ -27,15 +18,17 @@ const TYPENAMES = Object.freeze({
|
|
|
27
18
|
NULL: 'null',
|
|
28
19
|
STRING: 'string',
|
|
29
20
|
});
|
|
21
|
+
const SHORT_ARG_CUTOFF = 3;
|
|
30
22
|
/**
|
|
31
|
-
*
|
|
23
|
+
* Converts the finalized, flattened schema representation into
|
|
24
|
+
* `ArgumentDefinitions` for handoff to `argparse`.
|
|
32
25
|
*/
|
|
33
|
-
|
|
26
|
+
function toParserArgs() {
|
|
27
|
+
const flattened = (0, schema_1.flattenSchema)().filter(({ schema }) => !schema.appiumCliIgnored);
|
|
28
|
+
return new Map(lodash_1.default.map(flattened, ({ schema, argSpec }) => subSchemaToArgDef(schema, argSpec)));
|
|
29
|
+
}
|
|
34
30
|
/**
|
|
35
|
-
* Convert an alias (`foo`) to a flag (`--foo`) or
|
|
36
|
-
* @param {ArgSpec} argSpec - the argument specification
|
|
37
|
-
* @param {string} [alias] - the alias to convert to a flag
|
|
38
|
-
* @returns {string} the flag
|
|
31
|
+
* Convert an alias (`foo`) to a flag (`--foo`) or short flag (`-f`).
|
|
39
32
|
*/
|
|
40
33
|
function aliasToFlag(argSpec, alias) {
|
|
41
34
|
const { extType, extName, name } = argSpec;
|
|
@@ -48,23 +41,11 @@ function aliasToFlag(argSpec, alias) {
|
|
|
48
41
|
}
|
|
49
42
|
return isShort ? `-${arg}` : `--${lodash_1.default.kebabCase(arg)}`;
|
|
50
43
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Converts a string to SCREAMING_SNAKE_CASE
|
|
53
|
-
*/
|
|
54
44
|
const screamingSnakeCase = lodash_1.default.flow(lodash_1.default.snakeCase, lodash_1.default.toUpper);
|
|
55
45
|
/**
|
|
56
|
-
* Given
|
|
57
|
-
* against a property within the schema.
|
|
58
|
-
* @template Coerced
|
|
59
|
-
* @param {ArgSpec} argSpec - Argument name
|
|
60
|
-
* @param {(value: string) => Coerced} [coerce] - Function to coerce to a different
|
|
61
|
-
* primitive
|
|
62
|
-
* @todo See if we can remove `coerce` by allowing Ajv to coerce in its
|
|
63
|
-
* constructor options
|
|
64
|
-
* @returns
|
|
46
|
+
* Given an argument spec, return a validator/coercer function backed by schema validation.
|
|
65
47
|
*/
|
|
66
48
|
function getSchemaValidator({ ref: schemaId }, coerce = lodash_1.default.identity) {
|
|
67
|
-
/** @param {string} value */
|
|
68
49
|
return (value) => {
|
|
69
50
|
const coerced = coerce(value);
|
|
70
51
|
const errors = (0, schema_1.validate)(coerced, schemaId);
|
|
@@ -74,11 +55,6 @@ function getSchemaValidator({ ref: schemaId }, coerce = lodash_1.default.identit
|
|
|
74
55
|
throw new argparse_1.ArgumentTypeError('\n\n' + (0, config_file_1.formatErrors)(errors, value, { schemaId }));
|
|
75
56
|
};
|
|
76
57
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Determine the description for display on the CLI, given the schema.
|
|
79
|
-
* @param {AppiumJSONSchema} schema
|
|
80
|
-
* @returns {string}
|
|
81
|
-
*/
|
|
82
58
|
function makeDescription(schema) {
|
|
83
59
|
const { appiumCliDescription, description = '', appiumDeprecated } = schema;
|
|
84
60
|
let desc = appiumCliDescription ?? description;
|
|
@@ -87,46 +63,22 @@ function makeDescription(schema) {
|
|
|
87
63
|
}
|
|
88
64
|
return desc;
|
|
89
65
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Given arg `name`, a JSON schema `subSchema`, and options, return an argument definition
|
|
92
|
-
* as understood by `argparse`.
|
|
93
|
-
* @param {AppiumJSONSchema} subSchema - JSON schema for the option
|
|
94
|
-
* @param {ArgSpec} argSpec - Argument spec tuple
|
|
95
|
-
* @returns {[[string]|[string, string], import('argparse').ArgumentOptions]} Tuple of flag and options
|
|
96
|
-
*/
|
|
97
66
|
function subSchemaToArgDef(subSchema, argSpec) {
|
|
98
|
-
|
|
67
|
+
const { type, appiumCliAliases, appiumCliTransformer, enum: enumValues } = subSchema;
|
|
99
68
|
const { name, arg } = argSpec;
|
|
100
69
|
const aliases = [
|
|
101
70
|
aliasToFlag(argSpec),
|
|
102
|
-
...
|
|
71
|
+
...(appiumCliAliases ?? []).map((alias) => aliasToFlag(argSpec, alias)),
|
|
103
72
|
];
|
|
104
|
-
|
|
105
|
-
let argOpts = {
|
|
73
|
+
const argOpts = {
|
|
106
74
|
required: false,
|
|
107
75
|
help: makeDescription(subSchema),
|
|
108
76
|
};
|
|
109
|
-
// argparse infers dest from the option string (e.g. --log-level → log_level).
|
|
110
|
-
// We need schema dest (e.g. loglevel) so merged server args and logsink use the right key.
|
|
111
77
|
if (!argSpec.extType) {
|
|
112
78
|
argOpts.dest = argSpec.rawDest;
|
|
113
79
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Generally we will provide a `type` to `argparse` as a function which
|
|
116
|
-
* validates using ajv (which is much more full-featured than what `argparse`
|
|
117
|
-
* can offer). The exception is `boolean`-type options, which have no
|
|
118
|
-
* `argType`.
|
|
119
|
-
*
|
|
120
|
-
* Not sure if this type is correct, but it's not doing what I want. I want
|
|
121
|
-
* to say "this is a function which returns something of type `T` where `T` is
|
|
122
|
-
* never a `Promise`". This function must be sync.
|
|
123
|
-
* @type {((value: string) => unknown)|undefined}
|
|
124
|
-
*/
|
|
125
80
|
let argTypeFunction;
|
|
126
|
-
// handle special cases for various types
|
|
127
81
|
switch (type) {
|
|
128
|
-
// booleans do not have a type per `ArgumentOptions`, just an "action"
|
|
129
|
-
// NOTE: due to limitations of `argparse`, we cannot provide fancy help text, and must rely on its internal error messaging.
|
|
130
82
|
case TYPENAMES.BOOLEAN: {
|
|
131
83
|
argOpts.action = 'store_const';
|
|
132
84
|
argOpts.const = true;
|
|
@@ -134,54 +86,40 @@ function subSchemaToArgDef(subSchema, argSpec) {
|
|
|
134
86
|
}
|
|
135
87
|
case TYPENAMES.OBJECT: {
|
|
136
88
|
argTypeFunction = lodash_1.default.flow(cli_transformers_1.transformers.json, (o) => {
|
|
137
|
-
// Arrays and plain strings are also valid JSON
|
|
138
89
|
if (!lodash_1.default.isPlainObject(o)) {
|
|
139
|
-
throw new argparse_1.ArgumentTypeError(`'${lodash_1.default.truncate(o, { length: 100 })}' must be a plain object`);
|
|
140
|
-
;
|
|
90
|
+
throw new argparse_1.ArgumentTypeError(`'${lodash_1.default.truncate(String(o), { length: 100 })}' must be a plain object`);
|
|
141
91
|
}
|
|
142
92
|
return o;
|
|
143
93
|
});
|
|
144
94
|
break;
|
|
145
95
|
}
|
|
146
|
-
// arrays are treated as CSVs, because `argparse` doesn't handle array data.
|
|
147
96
|
case TYPENAMES.ARRAY: {
|
|
148
97
|
argTypeFunction = cli_transformers_1.parseCsvLine;
|
|
149
98
|
break;
|
|
150
99
|
}
|
|
151
|
-
// "number" type is coerced to float. `argparse` does this for us if we use `float` type, but
|
|
152
|
-
// we don't.
|
|
153
100
|
case TYPENAMES.NUMBER: {
|
|
154
101
|
argTypeFunction = getSchemaValidator(argSpec, parseFloat);
|
|
155
102
|
break;
|
|
156
103
|
}
|
|
157
|
-
// "integer" is coerced to an .. integer. again, `argparse` would do this for us if we used `int`.
|
|
158
104
|
case TYPENAMES.INTEGER: {
|
|
159
105
|
argTypeFunction = getSchemaValidator(argSpec, lodash_1.default.parseInt);
|
|
160
106
|
break;
|
|
161
107
|
}
|
|
162
|
-
// strings (like number and integer) are subject to further validation
|
|
163
|
-
// (e.g., must satisfy a mask or regex or even some custom validation
|
|
164
|
-
// function)
|
|
165
108
|
case TYPENAMES.STRING: {
|
|
166
109
|
argTypeFunction = getSchemaValidator(argSpec);
|
|
167
110
|
break;
|
|
168
111
|
}
|
|
169
|
-
// TODO: there may be some way to restrict this at the Ajv level --
|
|
170
|
-
// that may involve patching the metaschema.
|
|
171
112
|
case TYPENAMES.NULL:
|
|
172
|
-
// falls through
|
|
173
113
|
default: {
|
|
174
114
|
throw new TypeError(`Schema property "${arg}": \`${type}\` type unknown or disallowed`);
|
|
175
115
|
}
|
|
176
116
|
}
|
|
177
|
-
// metavar is used in help text. `boolean` cannot have a metavar--it is not
|
|
178
|
-
// displayed--and `argparse` throws if you give it one.
|
|
179
117
|
if (type !== TYPENAMES.BOOLEAN) {
|
|
180
118
|
argOpts.metavar = screamingSnakeCase(name);
|
|
181
119
|
}
|
|
182
120
|
if (appiumCliTransformer && cli_transformers_1.transformers[appiumCliTransformer]) {
|
|
183
121
|
if (type === TYPENAMES.ARRAY) {
|
|
184
|
-
const csvTransformer =
|
|
122
|
+
const csvTransformer = argTypeFunction;
|
|
185
123
|
argTypeFunction = (val) => lodash_1.default.flatMap(csvTransformer(val).map(cli_transformers_1.transformers[appiumCliTransformer]));
|
|
186
124
|
}
|
|
187
125
|
else {
|
|
@@ -191,9 +129,6 @@ function subSchemaToArgDef(subSchema, argSpec) {
|
|
|
191
129
|
if (argTypeFunction) {
|
|
192
130
|
argOpts.type = argTypeFunction;
|
|
193
131
|
}
|
|
194
|
-
// convert JSON schema `enum` to `choices`. `enum` can contain any JSON type, but `argparse`
|
|
195
|
-
// is limited to a single type per arg (I think). so let's make everything a string.
|
|
196
|
-
// and might as well _require_ the `type: string` while we're at it.
|
|
197
132
|
if (enumValues && !lodash_1.default.isEmpty(enumValues)) {
|
|
198
133
|
if (type === TYPENAMES.STRING) {
|
|
199
134
|
argOpts.choices = enumValues.map(String);
|
|
@@ -202,32 +137,7 @@ function subSchemaToArgDef(subSchema, argSpec) {
|
|
|
202
137
|
throw new TypeError(`Problem with schema for ${arg}; \`enum\` is only supported for \`type: 'string'\``);
|
|
203
138
|
}
|
|
204
139
|
}
|
|
205
|
-
|
|
206
|
-
// will be silently discarded.
|
|
207
|
-
const finalAliases = /** @type {[string]|[string, string]} */ (aliases);
|
|
140
|
+
const finalAliases = aliases;
|
|
208
141
|
return [finalAliases, argOpts];
|
|
209
142
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Converts the finalized, flattened schema representation into
|
|
212
|
-
* ArgumentDefinitions for handoff to `argparse`.
|
|
213
|
-
*
|
|
214
|
-
* @throws If schema has not been added to ajv (via `finalizeSchema()`)
|
|
215
|
-
* @returns {import('../cli/args').ArgumentDefinitions} A map of arrays of
|
|
216
|
-
* aliases to `argparse` arguments; empty if no schema found
|
|
217
|
-
*/
|
|
218
|
-
function toParserArgs() {
|
|
219
|
-
const flattened = (0, schema_1.flattenSchema)().filter(({ schema }) => !schema.appiumCliIgnored);
|
|
220
|
-
return new Map(lodash_1.default.map(flattened, ({ schema, argSpec }) => subSchemaToArgDef(schema, argSpec)));
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @template {string|number} T
|
|
224
|
-
* @typedef {import('ajv/dist/types').FormatValidator<T>} FormatValidator<T>
|
|
225
|
-
*/
|
|
226
|
-
/**
|
|
227
|
-
* A JSON 7 schema with our custom keywords.
|
|
228
|
-
* @typedef {import('./keywords').AppiumJSONSchemaKeywords & import('json-schema').JSONSchema7} AppiumJSONSchema
|
|
229
|
-
*/
|
|
230
|
-
/**
|
|
231
|
-
* @typedef {import('./arg-spec').ArgSpec} ArgSpec
|
|
232
|
-
*/
|
|
233
143
|
//# sourceMappingURL=cli-args.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../../lib/schema/cli-args.
|
|
1
|
+
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../../lib/schema/cli-args.ts"],"names":[],"mappings":";;;;;AA6BA,oCAKC;AAlCD,uCAAiE;AACjE,oDAAuB;AAEvB,gDAA4C;AAC5C,qCAAiD;AACjD,yDAA8D;AAQ9D,MAAM,SAAS,GAAkD,MAAM,CAAC,MAAM,CAAC;IAC7E,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;GAGG;AACH,SAAgB,YAAY;IAC1B,MAAM,SAAS,GAAG,IAAA,sBAAa,GAAE,CAAC,MAAM,CAAC,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACjF,OAAO,IAAI,GAAG,CACZ,gBAAC,CAAC,GAAG,CA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ions for CLI arguments.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* are usable by extensions, as well.
|
|
4
|
+
* Use case: config schemas can accept richer types (arrays/objects), but CLI
|
|
5
|
+
* values are strings. Transformers convert string input into those richer types.
|
|
8
6
|
*/
|
|
9
7
|
/**
|
|
10
8
|
* Splits a CSV string into an array
|
|
11
|
-
* @param {string} value
|
|
12
|
-
* @returns {string[]}
|
|
13
9
|
*/
|
|
14
|
-
export function parseCsvLine(value: string): string[];
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export declare function parseCsvLine(value: string): string[];
|
|
11
|
+
export declare const transformers: {
|
|
12
|
+
/**
|
|
13
|
+
* Given a CSV-style string or pathname, parse it into an array.
|
|
14
|
+
* The file can also be split on newlines.
|
|
15
|
+
*/
|
|
16
|
+
readonly csv: (csvOrPath: string) => string[];
|
|
17
|
+
/**
|
|
18
|
+
* Parse a string which could be a path to a JSON file or a JSON string.
|
|
19
|
+
*/
|
|
20
|
+
readonly json: (jsonOrPath: string) => Record<string, any>;
|
|
21
|
+
};
|
|
19
22
|
//# sourceMappingURL=cli-transformers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-transformers.d.ts","sourceRoot":"","sources":["../../../lib/schema/cli-transformers.
|
|
1
|
+
{"version":3,"file":"cli-transformers.d.ts","sourceRoot":"","sources":["../../../lib/schema/cli-transformers.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKpD;AAED,eAAO,MAAM,YAAY;IACvB;;;OAGG;8BACc,MAAM,KAAG,MAAM,EAAE;IAsBlC;;OAEG;gCACgB,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAqBvC,CAAC"}
|
|
@@ -5,17 +5,13 @@ exports.parseCsvLine = parseCsvLine;
|
|
|
5
5
|
const argparse_1 = require("argparse");
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
/**
|
|
8
|
-
* This module provides
|
|
9
|
-
* "transformers" (see `argTransformers` below).
|
|
8
|
+
* This module provides transformer functions for CLI arguments.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* are usable by extensions, as well.
|
|
10
|
+
* Use case: config schemas can accept richer types (arrays/objects), but CLI
|
|
11
|
+
* values are strings. Transformers convert string input into those richer types.
|
|
14
12
|
*/
|
|
15
13
|
/**
|
|
16
14
|
* Splits a CSV string into an array
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @returns {string[]}
|
|
19
15
|
*/
|
|
20
16
|
function parseCsvLine(value) {
|
|
21
17
|
return value
|
|
@@ -23,45 +19,15 @@ function parseCsvLine(value) {
|
|
|
23
19
|
.map((v) => v.trim())
|
|
24
20
|
.filter(Boolean);
|
|
25
21
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Split a file by newline then calls {@link parseCsvLine} on each line.
|
|
28
|
-
* @param {string} value
|
|
29
|
-
* @returns {string[]}
|
|
30
|
-
*/
|
|
31
|
-
function parseCsvFile(value) {
|
|
32
|
-
return value
|
|
33
|
-
.split(/\r?\n/)
|
|
34
|
-
.map((v) => v.trim())
|
|
35
|
-
.filter(Boolean)
|
|
36
|
-
.flatMap(parseCsvLine);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Namespace containing _transformers_ for CLI arguments. "Validators" and
|
|
40
|
-
* "formatters" do not actually modify the value, but these do.
|
|
41
|
-
*
|
|
42
|
-
* Use case is for when the config file can accept e.g., a `string[]`, but the
|
|
43
|
-
* CLI can only take a `string` (as `argparse` seems to be limited in that
|
|
44
|
-
* fashion; it also cannot understand an argument having multiple types).
|
|
45
|
-
*
|
|
46
|
-
* For example, the `csv` transform takes a `string` and returns a `string[]` by
|
|
47
|
-
* splitting it by comma--_or_ if that `string` happens to be a
|
|
48
|
-
* filepath--reading the file as a `.csv`.
|
|
49
|
-
*
|
|
50
|
-
* This contains some copy-pasted code from `lib/cli/parser-helpers.js`, which was
|
|
51
|
-
* obliterated.
|
|
52
|
-
*/
|
|
53
22
|
exports.transformers = {
|
|
54
23
|
/**
|
|
55
24
|
* Given a CSV-style string or pathname, parse it into an array.
|
|
56
25
|
* The file can also be split on newlines.
|
|
57
|
-
* @param {string} csvOrPath
|
|
58
|
-
* @returns {string[]}
|
|
59
26
|
*/
|
|
60
27
|
csv: (csvOrPath) => {
|
|
61
28
|
let csv = csvOrPath;
|
|
62
29
|
let loadedFromFile = false;
|
|
63
|
-
//
|
|
64
|
-
// to attempt to parse it as a file _first_.
|
|
30
|
+
// Value could be a single CSV token or a filepath; attempt file first.
|
|
65
31
|
if ((0, node_fs_1.existsSync)(csvOrPath)) {
|
|
66
32
|
try {
|
|
67
33
|
csv = (0, node_fs_1.readFileSync)(csvOrPath, 'utf8');
|
|
@@ -83,19 +49,13 @@ exports.transformers = {
|
|
|
83
49
|
},
|
|
84
50
|
/**
|
|
85
51
|
* Parse a string which could be a path to a JSON file or a JSON string.
|
|
86
|
-
* @param {string} jsonOrPath
|
|
87
|
-
* @returns {object}
|
|
88
52
|
*/
|
|
89
53
|
json: (jsonOrPath) => {
|
|
90
54
|
let json = jsonOrPath;
|
|
91
55
|
let loadedFromFile = false;
|
|
92
56
|
if ((0, node_fs_1.existsSync)(jsonOrPath)) {
|
|
93
57
|
try {
|
|
94
|
-
//
|
|
95
|
-
// awaiting or using callbacks. This step happens in startup, in what is
|
|
96
|
-
// effectively command-line code, so nothing is blocked in terms of
|
|
97
|
-
// sessions, so holding up the event loop does not incur the usual
|
|
98
|
-
// drawbacks.
|
|
58
|
+
// Intentionally sync: argparse type hooks are synchronous.
|
|
99
59
|
json = (0, node_fs_1.readFileSync)(jsonOrPath, 'utf8');
|
|
100
60
|
}
|
|
101
61
|
catch (err) {
|
|
@@ -114,4 +74,14 @@ exports.transformers = {
|
|
|
114
74
|
}
|
|
115
75
|
},
|
|
116
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Split a file by newline then calls {@link parseCsvLine} on each line.
|
|
79
|
+
*/
|
|
80
|
+
function parseCsvFile(value) {
|
|
81
|
+
return value
|
|
82
|
+
.split(/\r?\n/)
|
|
83
|
+
.map((v) => v.trim())
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.flatMap(parseCsvLine);
|
|
86
|
+
}
|
|
117
87
|
//# sourceMappingURL=cli-transformers.js.map
|