appium 2.0.0-beta.2 → 2.0.0-beta.20

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 (70) hide show
  1. package/README.md +9 -9
  2. package/build/lib/appium-config.schema.json +0 -0
  3. package/build/lib/appium.js +157 -53
  4. package/build/lib/cli/argparse-actions.js +104 -0
  5. package/build/lib/cli/args.js +115 -279
  6. package/build/lib/cli/driver-command.js +11 -1
  7. package/build/lib/cli/extension-command.js +60 -8
  8. package/build/lib/cli/extension.js +30 -7
  9. package/build/lib/cli/npm.js +17 -14
  10. package/build/lib/cli/parser.js +152 -89
  11. package/build/lib/cli/plugin-command.js +11 -1
  12. package/build/lib/cli/utils.js +29 -3
  13. package/build/lib/config-file.js +141 -0
  14. package/build/lib/config.js +76 -61
  15. package/build/lib/driver-config.js +42 -19
  16. package/build/lib/drivers.js +8 -4
  17. package/build/lib/ext-config-io.js +165 -0
  18. package/build/lib/extension-config.js +130 -61
  19. package/build/lib/grid-register.js +22 -24
  20. package/build/lib/logger.js +3 -3
  21. package/build/lib/logsink.js +11 -13
  22. package/build/lib/main.js +197 -77
  23. package/build/lib/plugin-config.js +20 -10
  24. package/build/lib/plugins.js +4 -2
  25. package/build/lib/schema/appium-config-schema.js +252 -0
  26. package/build/lib/schema/arg-spec.js +120 -0
  27. package/build/lib/schema/cli-args.js +173 -0
  28. package/build/lib/schema/cli-transformers.js +76 -0
  29. package/build/lib/schema/index.js +36 -0
  30. package/build/lib/schema/keywords.js +62 -0
  31. package/build/lib/schema/schema.js +357 -0
  32. package/build/lib/utils.js +44 -99
  33. package/lib/appium-config.schema.json +277 -0
  34. package/lib/appium.js +201 -65
  35. package/lib/cli/argparse-actions.js +77 -0
  36. package/lib/cli/args.js +174 -375
  37. package/lib/cli/driver-command.js +4 -0
  38. package/lib/cli/extension-command.js +70 -5
  39. package/lib/cli/extension.js +25 -5
  40. package/lib/cli/npm.js +18 -12
  41. package/lib/cli/parser.js +254 -79
  42. package/lib/cli/plugin-command.js +4 -0
  43. package/lib/cli/utils.js +21 -1
  44. package/lib/config-file.js +227 -0
  45. package/lib/config.js +109 -62
  46. package/lib/driver-config.js +66 -11
  47. package/lib/drivers.js +4 -1
  48. package/lib/ext-config-io.js +287 -0
  49. package/lib/extension-config.js +225 -67
  50. package/lib/grid-register.js +27 -24
  51. package/lib/logger.js +1 -1
  52. package/lib/logsink.js +10 -7
  53. package/lib/main.js +211 -77
  54. package/lib/plugin-config.js +34 -5
  55. package/lib/plugins.js +1 -0
  56. package/lib/schema/appium-config-schema.js +286 -0
  57. package/lib/schema/arg-spec.js +218 -0
  58. package/lib/schema/cli-args.js +273 -0
  59. package/lib/schema/cli-transformers.js +123 -0
  60. package/lib/schema/index.js +2 -0
  61. package/lib/schema/keywords.js +119 -0
  62. package/lib/schema/schema.js +577 -0
  63. package/lib/utils.js +42 -88
  64. package/package.json +55 -80
  65. package/postinstall.js +71 -0
  66. package/types/appium-config.d.ts +197 -0
  67. package/types/types.d.ts +201 -0
  68. package/CHANGELOG.md +0 -3515
  69. package/build/lib/cli/parser-helpers.js +0 -82
  70. package/lib/cli/parser-helpers.js +0 -79
@@ -0,0 +1,201 @@
1
+ import {transformers} from '../lib/schema/cli-transformers';
2
+ import {SERVER_SUBCOMMAND} from '../lib/cli/parser';
3
+ import {
4
+ DRIVER_TYPE as DRIVER_SUBCOMMAND,
5
+ PLUGIN_TYPE as PLUGIN_SUBCOMMAND,
6
+ } from '../lib/ext-config-io';
7
+ import appiumConfigSchema from '../lib/schema/appium-config-schema';
8
+ import {AppiumConfiguration, ServerConfig} from './appium-config';
9
+
10
+ /**
11
+ * Converts a kebab-cased string into a camel-cased string.
12
+ */
13
+ export type KebabToCamel<S extends string> =
14
+ S extends `${infer P1}-${infer P2}${infer P3}`
15
+ ? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}`
16
+ : Lowercase<S>;
17
+
18
+ /**
19
+ * Converts an object with kebab-cased keys into camel-cased keys.
20
+ */
21
+ type ObjectToCamel<T> = {
22
+ [K in keyof T as KebabToCamel<string & K>]: T[K] extends Record<string, any>
23
+ ? KeysToCamelCase<T[K]>
24
+ : T[K];
25
+ };
26
+
27
+ /**
28
+ * Converts an object or array to have camel-cased keys.
29
+ */
30
+ export type KeysToCamelCase<T> = {
31
+ [K in keyof T as KebabToCamel<string & K>]: T[K] extends Array<any>
32
+ ? KeysToCamelCase<T[K][number]>[]
33
+ : ObjectToCamel<T[K]>;
34
+ };
35
+
36
+ /**
37
+ * The Appium configuration as it would be in a configuration file.
38
+ */
39
+ export type AppiumConfig = Partial<AppiumConfiguration>;
40
+
41
+ /**
42
+ * Certain properties have an `appiumCliDest` prop, which affects the shape of
43
+ * {@link ParsedArgs}. This type helps recognize these properties.
44
+ *
45
+ * See `../lib/schema/keywords` for definition of `appiumCliDest`.
46
+ */
47
+ interface WithDest {
48
+ appiumCliDest: string;
49
+ }
50
+
51
+ /**
52
+ * Some properties have a `default` prop, which means practically they will not
53
+ * be `undefined` upon parsing.
54
+ *
55
+ * We use this to ensure that the {@link ParsedArgs} makes guarantees
56
+ * about the presence of properties.
57
+ */
58
+ interface WithDefault {
59
+ default: any;
60
+ }
61
+
62
+ interface WithCliTransformer {
63
+ appiumCliTransformer: keyof typeof transformers;
64
+ }
65
+
66
+ interface WithTypeArray {
67
+ type: 'array';
68
+ }
69
+ interface WithTypeObject {
70
+ type: 'object';
71
+ }
72
+ type WithTransformer = WithCliTransformer | WithTypeArray | WithTypeObject;
73
+
74
+ /**
75
+ * Derive the "constant" type of the server properties from the schema.
76
+ */
77
+ type AppiumServerSchema =
78
+ typeof appiumConfigSchema['properties']['server']['properties'];
79
+
80
+ /**
81
+ * Properties of `T` with keys `appiumCliDest` prop _or_ just camel-cased.
82
+ */
83
+ type NormalizedServerConfig = {
84
+ [Prop in keyof ServerConfigMapping as AppiumServerSchema[Prop] extends WithDest
85
+ ? AppiumServerSchema[Prop]['appiumCliDest']
86
+ : KebabToCamel<Prop>]: ServerConfig[Prop];
87
+ };
88
+
89
+ /**
90
+ * "Normalized" config, which is like the flattened config (camel-cased keys),
91
+ * but not flattened.
92
+ */
93
+ export type NormalizedAppiumConfig = {
94
+ server: NormalizedServerConfig;
95
+ };
96
+
97
+ /**
98
+ * Utility type to associate {@link AppiumServerSchema} with
99
+ * {@link ServerConfig}.
100
+ */
101
+ type ServerConfigMapping = {
102
+ [Prop in keyof Required<ServerConfig>]: AppiumServerSchema[Prop];
103
+ };
104
+
105
+ /**
106
+ * This type checks if `appiumCliDest` is present in the object via
107
+ * {@link WithDest}, and uses the _value_ of that property for the key name;
108
+ * otherwise uses the camel-cased value of the key name.
109
+ */
110
+ type SetKeyForProp<Prop extends keyof ServerConfigMapping> =
111
+ AppiumServerSchema[Prop] extends WithDest
112
+ ? AppiumServerSchema[Prop]['appiumCliDest']
113
+ : KebabToCamel<Prop>;
114
+
115
+ /**
116
+ * Checks for the existence of default values, and ensures those properties will
117
+ * be defined (eliminate `| undefined` from the type).
118
+ */
119
+ type DefaultForProp<Prop extends keyof ServerConfigMapping> =
120
+ AppiumServerSchema[Prop] extends WithDefault
121
+ ? NonNullable<ServerConfig[Prop]>
122
+ : ServerConfig[Prop];
123
+
124
+ /**
125
+ * The final shape of the parsed CLI arguments.
126
+ */
127
+ type ParsedArgsFromConfig = {
128
+ [Prop in keyof ServerConfigMapping as SetKeyForProp<Prop>]: DefaultForProp<Prop>;
129
+ };
130
+
131
+ /**
132
+ * Possible subcommands for the `appium` CLI.
133
+ */
134
+ type CliSubCommands =
135
+ | typeof SERVER_SUBCOMMAND
136
+ | typeof DRIVER_SUBCOMMAND
137
+ | typeof PLUGIN_SUBCOMMAND;
138
+
139
+ /**
140
+ * Possible subcommands of {@link DRIVER_SUBCOMMAND} or
141
+ * {@link PLUGIN_SUBCOMMAND}.
142
+ */
143
+ type CliExtensionSubcommands =
144
+ | 'list'
145
+ | 'install'
146
+ | 'uninstall'
147
+ | 'update'
148
+ | 'run';
149
+
150
+ /**
151
+ * Random stuff that may appear in the parsed args which has no equivalent in a
152
+ * config file.
153
+ */
154
+ interface MoreArgs {
155
+ /**
156
+ * Path to config file, if any
157
+ */
158
+ configFile: string;
159
+
160
+ /**
161
+ * If true, show the build info and exit
162
+ */
163
+ showConfig: boolean;
164
+
165
+ /**
166
+ * If true, open a REPL
167
+ */
168
+ shell: boolean;
169
+
170
+ /**
171
+ * If true, throw on error instead of exit. Not supported via CLI, but rather
172
+ * only programmatic usage.
173
+ */
174
+ throwInsteadOfExit: boolean;
175
+
176
+ /**
177
+ * Possible subcommands
178
+ */
179
+ subcommand:
180
+ | typeof DRIVER_SUBCOMMAND
181
+ | typeof PLUGIN_SUBCOMMAND
182
+ | typeof SERVER_SUBCOMMAND;
183
+
184
+ /**
185
+ * Subcommands of `driver` subcommand
186
+ */
187
+ driverCommand: CliExtensionSubcommands;
188
+
189
+ /**
190
+ * Subcommands of `plugin` subcommand
191
+ */
192
+ pluginCommand: CliExtensionSubcommands;
193
+ }
194
+
195
+ /**
196
+ * The Appium configuration as a flattened object, parsed via CLI args _and_ any
197
+ * CLI args unsupported by the config file.
198
+ * @todo Does not make any assumptions about property names derived from
199
+ * extensions.
200
+ */
201
+ export type ParsedArgs = ParsedArgsFromConfig & Partial<MoreArgs>;