appium 2.0.0-beta.3 → 2.0.0-beta.30

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 (139) hide show
  1. package/README.md +10 -11
  2. package/build/lib/appium.d.ts +215 -0
  3. package/build/lib/appium.d.ts.map +1 -0
  4. package/build/lib/appium.js +238 -132
  5. package/build/lib/cli/args.d.ts +20 -0
  6. package/build/lib/cli/args.d.ts.map +1 -0
  7. package/build/lib/cli/args.js +96 -282
  8. package/build/lib/cli/driver-command.d.ts +36 -0
  9. package/build/lib/cli/driver-command.d.ts.map +1 -0
  10. package/build/lib/cli/driver-command.js +19 -12
  11. package/build/lib/cli/extension-command.d.ts +345 -0
  12. package/build/lib/cli/extension-command.d.ts.map +1 -0
  13. package/build/lib/cli/extension-command.js +171 -96
  14. package/build/lib/cli/extension.d.ts +14 -0
  15. package/build/lib/cli/extension.d.ts.map +1 -0
  16. package/build/lib/cli/extension.js +31 -16
  17. package/build/lib/cli/parser.d.ts +79 -0
  18. package/build/lib/cli/parser.d.ts.map +1 -0
  19. package/build/lib/cli/parser.js +152 -95
  20. package/build/lib/cli/plugin-command.d.ts +39 -0
  21. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  22. package/build/lib/cli/plugin-command.js +18 -13
  23. package/build/lib/cli/utils.d.ts +29 -0
  24. package/build/lib/cli/utils.d.ts.map +1 -0
  25. package/build/lib/cli/utils.js +27 -3
  26. package/build/lib/config-file.d.ts +100 -0
  27. package/build/lib/config-file.d.ts.map +1 -0
  28. package/build/lib/config-file.js +136 -0
  29. package/build/lib/config.d.ts +40 -0
  30. package/build/lib/config.d.ts.map +1 -0
  31. package/build/lib/config.js +92 -67
  32. package/build/lib/constants.d.ts +48 -0
  33. package/build/lib/constants.d.ts.map +1 -0
  34. package/build/lib/constants.js +60 -0
  35. package/build/lib/extension/driver-config.d.ts +84 -0
  36. package/build/lib/extension/driver-config.d.ts.map +1 -0
  37. package/build/lib/extension/driver-config.js +190 -0
  38. package/build/lib/extension/extension-config.d.ts +170 -0
  39. package/build/lib/extension/extension-config.d.ts.map +1 -0
  40. package/build/lib/extension/extension-config.js +297 -0
  41. package/build/lib/extension/index.d.ts +39 -0
  42. package/build/lib/extension/index.d.ts.map +1 -0
  43. package/build/lib/extension/index.js +77 -0
  44. package/build/lib/extension/manifest.d.ts +174 -0
  45. package/build/lib/extension/manifest.d.ts.map +1 -0
  46. package/build/lib/extension/manifest.js +246 -0
  47. package/build/lib/extension/package-changed.d.ts +11 -0
  48. package/build/lib/extension/package-changed.d.ts.map +1 -0
  49. package/build/lib/extension/package-changed.js +68 -0
  50. package/build/lib/extension/plugin-config.d.ts +62 -0
  51. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  52. package/build/lib/extension/plugin-config.js +87 -0
  53. package/build/lib/grid-register.d.ts +10 -0
  54. package/build/lib/grid-register.d.ts.map +1 -0
  55. package/build/lib/grid-register.js +21 -25
  56. package/build/lib/logger.d.ts +3 -0
  57. package/build/lib/logger.d.ts.map +1 -0
  58. package/build/lib/logger.js +4 -6
  59. package/build/lib/logsink.d.ts +4 -0
  60. package/build/lib/logsink.d.ts.map +1 -0
  61. package/build/lib/logsink.js +12 -16
  62. package/build/lib/main.d.ts +51 -0
  63. package/build/lib/main.d.ts.map +1 -0
  64. package/build/lib/main.js +174 -82
  65. package/build/lib/schema/arg-spec.d.ts +143 -0
  66. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  67. package/build/lib/schema/arg-spec.js +119 -0
  68. package/build/lib/schema/cli-args.d.ts +19 -0
  69. package/build/lib/schema/cli-args.d.ts.map +1 -0
  70. package/build/lib/schema/cli-args.js +180 -0
  71. package/build/lib/schema/cli-transformers.d.ts +5 -0
  72. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  73. package/build/lib/schema/cli-transformers.js +74 -0
  74. package/build/lib/schema/index.d.ts +3 -0
  75. package/build/lib/schema/index.d.ts.map +1 -0
  76. package/build/lib/schema/index.js +34 -0
  77. package/build/lib/schema/keywords.d.ts +24 -0
  78. package/build/lib/schema/keywords.d.ts.map +1 -0
  79. package/build/lib/schema/keywords.js +70 -0
  80. package/build/lib/schema/schema.d.ts +259 -0
  81. package/build/lib/schema/schema.d.ts.map +1 -0
  82. package/build/lib/schema/schema.js +452 -0
  83. package/build/lib/utils.d.ts +66 -0
  84. package/build/lib/utils.d.ts.map +1 -0
  85. package/build/lib/utils.js +35 -139
  86. package/build/tsconfig.tsbuildinfo +1 -0
  87. package/index.js +11 -0
  88. package/lib/appium-config.schema.json +278 -0
  89. package/lib/appium.js +398 -155
  90. package/lib/cli/args.js +174 -377
  91. package/lib/cli/driver-command.js +22 -7
  92. package/lib/cli/extension-command.js +372 -177
  93. package/lib/cli/extension.js +32 -10
  94. package/lib/cli/parser.js +252 -83
  95. package/lib/cli/plugin-command.js +19 -6
  96. package/lib/cli/utils.js +22 -2
  97. package/lib/config-file.js +223 -0
  98. package/lib/config.js +169 -69
  99. package/lib/constants.js +78 -0
  100. package/lib/extension/driver-config.js +249 -0
  101. package/lib/extension/extension-config.js +458 -0
  102. package/lib/extension/index.js +102 -0
  103. package/lib/extension/manifest.js +486 -0
  104. package/lib/extension/package-changed.js +63 -0
  105. package/lib/extension/plugin-config.js +113 -0
  106. package/lib/grid-register.js +25 -22
  107. package/lib/logger.js +1 -1
  108. package/lib/logsink.js +14 -7
  109. package/lib/main.js +233 -83
  110. package/lib/schema/arg-spec.js +232 -0
  111. package/lib/schema/cli-args.js +261 -0
  112. package/lib/schema/cli-transformers.js +122 -0
  113. package/lib/schema/index.js +2 -0
  114. package/lib/schema/keywords.js +134 -0
  115. package/lib/schema/schema.js +734 -0
  116. package/lib/utils.js +85 -129
  117. package/package.json +62 -85
  118. package/scripts/postinstall.js +71 -0
  119. package/types/appium-manifest.d.ts +61 -0
  120. package/types/cli.d.ts +134 -0
  121. package/types/extension.d.ts +56 -0
  122. package/types/external-manifest.d.ts +58 -0
  123. package/types/index.d.ts +7 -0
  124. package/CHANGELOG.md +0 -3515
  125. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  126. package/build/lib/cli/npm.js +0 -206
  127. package/build/lib/cli/parser-helpers.js +0 -82
  128. package/build/lib/driver-config.js +0 -77
  129. package/build/lib/drivers.js +0 -96
  130. package/build/lib/extension-config.js +0 -251
  131. package/build/lib/plugin-config.js +0 -59
  132. package/build/lib/plugins.js +0 -14
  133. package/lib/cli/npm.js +0 -183
  134. package/lib/cli/parser-helpers.js +0 -79
  135. package/lib/driver-config.js +0 -46
  136. package/lib/drivers.js +0 -81
  137. package/lib/extension-config.js +0 -208
  138. package/lib/plugin-config.js +0 -34
  139. package/lib/plugins.js +0 -10
@@ -2,36 +2,53 @@
2
2
 
3
3
  import DriverCommand from './driver-command';
4
4
  import PluginCommand from './plugin-command';
5
- import DriverConfig from '../driver-config';
6
- import PluginConfig from '../plugin-config';
7
- import { DRIVER_TYPE } from '../extension-config';
5
+ import { DRIVER_TYPE, PLUGIN_TYPE } from '../constants';
8
6
  import { errAndQuit, log, JSON_SPACES } from './utils';
9
7
 
8
+ const commandClasses = Object.freeze(/** @type {const} */({
9
+ [DRIVER_TYPE]: DriverCommand,
10
+ [PLUGIN_TYPE]: PluginCommand
11
+ }));
12
+
10
13
  /**
11
14
  * Run a subcommand of the 'appium driver' type. Each subcommand has its own set of arguments which
12
15
  * can be represented as a JS object.
13
16
  *
14
17
  * @param {Object} args - JS object where the key is the parameter name (as defined in
15
18
  * driver-parser.js)
19
+ * @template {import('../extension/manifest').ExtensionType} ExtType
20
+ * @param {import('../extension/extension-config').ExtensionConfig<ExtType>} configObject - Extension config object
16
21
  */
17
- async function runExtensionCommand (args, type) {
22
+ async function runExtensionCommand (args, configObject) {
18
23
  // TODO driver config file should be locked while any of these commands are
19
24
  // running to prevent weird situations
20
25
  let jsonResult = null;
21
- const {json, appiumHome} = args;
26
+ const {extensionType: type} = configObject;
27
+ const extCmd = args[`${type}Command`];
28
+ if (!extCmd) {
29
+ throw new TypeError(`Cannot call ${type} command without a subcommand like 'install'`);
30
+ }
31
+ let {json, suppressOutput} = args;
32
+ if (suppressOutput) {
33
+ json = true;
34
+ }
22
35
  const logFn = (msg) => log(json, msg);
23
- const ConfigClass = type === DRIVER_TYPE ? DriverConfig : PluginConfig;
24
- const CommandClass = type === DRIVER_TYPE ? DriverCommand : PluginCommand;
25
- const config = new ConfigClass(appiumHome, logFn);
36
+ let config = configObject;
37
+ config.log = logFn;
38
+ const CommandClass = /** @type {ExtCommand<ExtType>} */(commandClasses[type]);
26
39
  const cmd = new CommandClass({config, json});
27
40
  try {
28
- await config.read();
29
41
  jsonResult = await cmd.execute(args);
30
42
  } catch (err) {
43
+ // in the suppress output case, we are calling this function internally and should
44
+ // just throw instead of printing an error and ending the process
45
+ if (suppressOutput) {
46
+ throw err;
47
+ }
31
48
  errAndQuit(json, err);
32
49
  }
33
50
 
34
- if (json) {
51
+ if (json && !suppressOutput) {
35
52
  console.log(JSON.stringify(jsonResult, null, JSON_SPACES));
36
53
  }
37
54
 
@@ -41,3 +58,8 @@ async function runExtensionCommand (args, type) {
41
58
  export {
42
59
  runExtensionCommand,
43
60
  };
61
+
62
+ /**
63
+ * @template {import('../../types').ExtensionType} ExtType
64
+ * @typedef {ExtType extends import('../../types').DriverType ? import('@appium/types').Class<DriverCommand> : ExtType extends import('../../types').PluginType ? import('@appium/types').Class<PluginCommand> : never} ExtCommand
65
+ */
package/lib/cli/parser.js CHANGED
@@ -1,98 +1,267 @@
1
- import path from 'path';
2
- import _ from 'lodash';
1
+
2
+ import { fs } from '@appium/support';
3
3
  import { ArgumentParser } from 'argparse';
4
- import { sharedArgs, serverArgs, extensionArgs } from './args';
5
- import { DRIVER_TYPE, PLUGIN_TYPE } from '../extension-config';
6
- import { rootDir } from '../utils';
7
-
8
- function getParser (debug = false) {
9
- const parser = new ArgumentParser({
10
- version: require(path.resolve(rootDir, 'package.json')).version,
11
- addHelp: true,
12
- description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
13
- prog: process.argv[1] ? path.basename(process.argv[1]) : 'appium',
14
- debug
15
- });
16
- const subParsers = parser.addSubparsers({dest: 'subcommand', debug});
17
-
18
- // add the 'server' subcommand, and store the raw arguments on the parser
19
- // object as a way for other parts of the code to work with the arguments
20
- // conceptually rather than just through argparse
21
- const serverArgs = addServerToParser(sharedArgs, subParsers, debug);
22
- parser.rawArgs = serverArgs;
23
-
24
- // add the 'driver' and 'plugin' subcommands
25
- addExtensionsToParser(sharedArgs, subParsers, debug);
26
-
27
- // modify the parseArgs function to insert the 'server' subcommand if the
28
- // user hasn't specified a subcommand or the global help command
29
- parser._parseArgs = parser.parseArgs;
30
- parser.parseArgs = function (args, namespace) {
31
- if (_.isUndefined(args)) {
32
- args = [...process.argv.slice(2)];
33
- }
34
- if (!_.includes([DRIVER_TYPE, PLUGIN_TYPE, 'server', '-h'], args[0])) {
35
- args.splice(0, 0, 'server');
4
+ import _ from 'lodash';
5
+ import path from 'path';
6
+ import { DRIVER_TYPE, PLUGIN_TYPE, SERVER_SUBCOMMAND } from '../constants';
7
+ import { finalizeSchema, getArgSpec, hasArgSpec } from '../schema';
8
+ import { rootDir } from '../config';
9
+ import {
10
+ getExtensionArgs,
11
+ getServerArgs
12
+ } from './args';
13
+
14
+ /**
15
+ * If the parsed args do not contain any of these values, then we
16
+ * will automatially inject the `server` subcommand.
17
+ */
18
+ const NON_SERVER_ARGS = Object.freeze(
19
+ new Set([
20
+ DRIVER_TYPE,
21
+ PLUGIN_TYPE,
22
+ SERVER_SUBCOMMAND,
23
+ '-h',
24
+ '--help',
25
+ '-v',
26
+ '--version'
27
+ ])
28
+ );
29
+
30
+ const version = fs.readPackageJsonFrom(rootDir).version;
31
+
32
+ /**
33
+ * A wrapper around `argparse`
34
+ *
35
+ * - Handles instantiation, configuration, and monkeypatching of an
36
+ * `ArgumentParser` instance for Appium server and its extensions
37
+ * - Handles error conditions, messages, and exit behavior
38
+ */
39
+ class ArgParser {
40
+ /**
41
+ * @param {boolean} [debug] - If true, throw instead of exit on error.
42
+ */
43
+ constructor (debug = false) {
44
+ const prog = process.argv[1] ? path.basename(process.argv[1]) : 'appium';
45
+ const parser = new ArgumentParser({
46
+ add_help: true,
47
+ description:
48
+ 'A webdriver-compatible server that facilitates automation of web, mobile, and other types of apps across various platforms.',
49
+ prog,
50
+ });
51
+
52
+ ArgParser._patchExit(parser);
53
+
54
+ /**
55
+ * Program name (typically `appium`)
56
+ * @type {string}
57
+ */
58
+ this.prog = prog;
59
+
60
+ /**
61
+ * If `true`, throw an error on parse failure instead of printing help
62
+ * @type {boolean}
63
+ */
64
+ this.debug = debug;
65
+
66
+ /**
67
+ * Wrapped `ArgumentParser` instance
68
+ * @type {ArgumentParser}
69
+ */
70
+ this.parser = parser;
71
+
72
+ parser.add_argument('-v', '--version', {
73
+ action: 'version',
74
+ version,
75
+ });
76
+
77
+ const subParsers = parser.add_subparsers({dest: 'subcommand'});
78
+
79
+ // add the 'server' subcommand, and store the raw arguments on the parser
80
+ // object as a way for other parts of the code to work with the arguments
81
+ // conceptually rather than just through argparse
82
+ const serverArgs = ArgParser._addServerToParser(subParsers);
83
+
84
+ this.rawArgs = serverArgs;
85
+
86
+ // add the 'driver' and 'plugin' subcommands
87
+ ArgParser._addExtensionCommandsToParser(subParsers);
88
+
89
+ // backwards compatibility / drop-in wrapper
90
+ /**
91
+ * @type {ArgParser['parseArgs']}
92
+ */
93
+ this.parse_args = this.parseArgs;
94
+ }
95
+
96
+ /**
97
+ * Parse arguments from the command line.
98
+ *
99
+ * If no subcommand is passed in, this method will inject the `server` subcommand.
100
+ *
101
+ * `ArgParser.prototype.parse_args` is an alias of this method.
102
+ * @param {string[]} [args] - Array of arguments, ostensibly from `process.argv`. Gathers args from `process.argv` if not provided.
103
+ * @returns {import('../../types/cli').ParsedArgs} - The parsed arguments
104
+ */
105
+ parseArgs (args = process.argv.slice(2)) {
106
+ if (!NON_SERVER_ARGS.has(args[0])) {
107
+ args.unshift(SERVER_SUBCOMMAND);
36
108
  }
37
- return this._parseArgs(args, namespace);
38
- }.bind(parser);
39
- return parser;
40
- }
41
109
 
42
- function addServerToParser (sharedArgs, subParsers, debug) {
43
- const serverParser = subParsers.addParser('server', {
44
- addHelp: true,
45
- help: 'Run an Appium server',
46
- debug
47
- });
110
+ try {
111
+ const parsed = this.parser.parse_args(args);
112
+ return ArgParser._transformParsedArgs(parsed);
113
+ } catch (err) {
114
+ if (this.debug) {
115
+ throw err;
116
+ }
117
+ // this isn't tested via unit tests (we use `debug: true`) so may escape coverage.
48
118
 
49
- for (const [flags, opts] of [...sharedArgs, ...serverArgs]) {
50
- // addArgument mutates arguments so make copies
51
- serverParser.addArgument([...flags], {...opts});
119
+ /* istanbul ignore next */
120
+ {
121
+ // eslint-disable-next-line no-console
122
+ console.error(); // need an extra space since argparse prints usage.
123
+ // eslint-disable-next-line no-console
124
+ console.error(err.message);
125
+ process.exit(1);
126
+ }
127
+ }
52
128
  }
53
129
 
54
- return serverArgs;
55
- }
130
+ /**
131
+ * Given an object full of arguments as returned by `argparser.parse_args`,
132
+ * expand the ones for extensions into a nested object structure and rename
133
+ * keys to match the intended destination.
134
+ *
135
+ * E.g., `{'driver-foo-bar': baz}` becomes `{driver: {foo: {bar: 'baz'}}}`
136
+ * @param {object} args
137
+ * @returns {object}
138
+ */
139
+ static _transformParsedArgs (args) {
140
+ return _.reduce(
141
+ args,
142
+ (unpacked, value, key) => {
143
+ if (!_.isUndefined(value) && hasArgSpec(key)) {
144
+ const {dest} = /** @type {import('../schema/arg-spec').ArgSpec} */(getArgSpec(key));
145
+ _.set(unpacked, dest, value);
146
+ } else {
147
+ // this could be anything that _isn't_ a server arg
148
+ unpacked[key] = value;
149
+ }
150
+ return unpacked;
151
+ },
152
+ {},
153
+ );
154
+ }
56
155
 
57
- function getDefaultServerArgs () {
58
- let defaults = {};
59
- for (let [, arg] of serverArgs) {
60
- defaults[arg.dest] = arg.defaultValue;
156
+ /**
157
+ * Patches the `exit()` method of the parser to throw an error, so we can handle it manually.
158
+ * @param {ArgumentParser} parser
159
+ */
160
+ static _patchExit (parser) {
161
+ parser.exit = (code, msg) => {
162
+ if (code) {
163
+ throw new Error(msg);
164
+ }
165
+ process.exit();
166
+ };
61
167
  }
62
- return defaults;
63
- }
64
168
 
65
- function addExtensionsToParser (sharedArgs, subParsers, debug) {
66
- for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
67
- const extParser = subParsers.addParser(type, {
68
- addHelp: true,
69
- help: `Access the ${type} management CLI commands`,
70
- debug
71
- });
72
- const extSubParsers = extParser.addSubparsers({
73
- dest: `${type}Command`,
74
- debug
169
+ /**
170
+ *
171
+ * @param {import('argparse').SubParser} subParser
172
+ * @returns {import('./args').ArgumentDefinitions}
173
+ */
174
+ static _addServerToParser (subParser) {
175
+ const serverParser = subParser.add_parser('server', {
176
+ add_help: true,
177
+ help: 'Run an Appium server',
75
178
  });
76
- const parserSpecs = [
77
- {command: 'list', args: extensionArgs[type].list,
78
- help: `List available and installed ${type}s`},
79
- {command: 'install', args: extensionArgs[type].install,
80
- help: `Install a ${type}`},
81
- {command: 'uninstall', args: extensionArgs[type].uninstall,
82
- help: `Uninstall a ${type}`},
83
- {command: 'update', args: extensionArgs[type].update,
84
- help: `Update installed ${type}s to the latest version`},
85
- ];
86
-
87
- for (const {command, args, help} of parserSpecs) {
88
- const parser = extSubParsers.addParser(command, {help, debug});
89
- for (const [flags, opts] of [...sharedArgs, ...args]) {
90
- // addArgument mutates params so make sure to send in copies instead
91
- parser.addArgument([...flags], {...opts});
179
+
180
+ ArgParser._patchExit(serverParser);
181
+
182
+ const serverArgs = getServerArgs();
183
+ for (const [flagsOrNames, opts] of serverArgs) {
184
+ // TS doesn't like the spread operator here.
185
+ // @ts-ignore
186
+ serverParser.add_argument(...flagsOrNames, {...opts});
187
+ }
188
+
189
+ return serverArgs;
190
+ }
191
+
192
+ /**
193
+ * Adds extension sub-sub-commands to `driver`/`plugin` subcommands
194
+ * @param {import('argparse').SubParser} subParsers
195
+ */
196
+ static _addExtensionCommandsToParser (subParsers) {
197
+ for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
198
+ const extParser = subParsers.add_parser(type, {
199
+ add_help: true,
200
+ help: `Access the ${type} management CLI commands`,
201
+ });
202
+
203
+ ArgParser._patchExit(extParser);
204
+
205
+ const extSubParsers = extParser.add_subparsers({
206
+ dest: `${type}Command`,
207
+ });
208
+ const extensionArgs = getExtensionArgs();
209
+ const parserSpecs = [
210
+ {
211
+ command: 'list',
212
+ args: extensionArgs[type].list,
213
+ help: `List available and installed ${type}s`,
214
+ },
215
+ {
216
+ command: 'install',
217
+ args: extensionArgs[type].install,
218
+ help: `Install a ${type}`,
219
+ },
220
+ {
221
+ command: 'uninstall',
222
+ args: extensionArgs[type].uninstall,
223
+ help: `Uninstall a ${type}`,
224
+ },
225
+ {
226
+ command: 'update',
227
+ args: extensionArgs[type].update,
228
+ help: `Update installed ${type}s to the latest version`,
229
+ },
230
+ {
231
+ command: 'run',
232
+ args: extensionArgs[type].run,
233
+ help:
234
+ `Run a script (defined inside the ${type}'s package.json under the ` +
235
+ `“scripts” field inside the “appium” field) from an installed ${type}`,
236
+ },
237
+ ];
238
+
239
+ for (const {command, args, help} of parserSpecs) {
240
+ const parser = extSubParsers.add_parser(command, {help});
241
+
242
+ ArgParser._patchExit(parser);
243
+
244
+ for (const [flagsOrNames, opts] of args) {
245
+ // add_argument mutates params so make sure to send in copies instead
246
+ // @ts-ignore
247
+ parser.add_argument(...flagsOrNames, {...opts});
248
+ }
92
249
  }
93
250
  }
94
251
  }
95
252
  }
96
253
 
97
- export default getParser;
98
- export { getParser, getDefaultServerArgs };
254
+ /**
255
+ * Creates a {@link ArgParser} instance; finalizes the config schema.
256
+ *
257
+ * @constructs ArgParser
258
+ * @param {boolean} [debug] - If `true`, throw instead of exit upon parsing error
259
+ * @returns {ArgParser}
260
+ */
261
+ function getParser (debug) {
262
+ finalizeSchema();
263
+
264
+ return new ArgParser(debug);
265
+ }
266
+
267
+ export { getParser, ArgParser };
@@ -1,27 +1,34 @@
1
1
  import _ from 'lodash';
2
2
  import ExtensionCommand from './extension-command';
3
- import { PLUGIN_TYPE } from '../extension-config';
4
- import { KNOWN_PLUGINS } from '../plugins';
3
+ import { KNOWN_PLUGINS } from '../constants';
5
4
 
6
5
  const REQ_PLUGIN_FIELDS = ['pluginName', 'mainClass'];
7
6
 
8
7
  export default class PluginCommand extends ExtensionCommand {
9
8
 
9
+ /**
10
+ *
11
+ * @param {PluginCommandOptions} opts
12
+ */
10
13
  constructor ({config, json}) {
11
- super({config, json, type: PLUGIN_TYPE});
14
+ super({config, json});
12
15
  this.knownExtensions = KNOWN_PLUGINS;
13
16
  }
14
17
 
15
18
  async install ({plugin, installType, packageName}) {
16
- return await super.install({ext: plugin, installType, packageName});
19
+ return await super._install({ext: plugin, installType, packageName});
17
20
  }
18
21
 
19
22
  async uninstall ({plugin}) {
20
- return await super.uninstall({ext: plugin});
23
+ return await super._uninstall({ext: plugin});
21
24
  }
22
25
 
23
26
  async update ({plugin, unsafe}) {
24
- return await super.update({ext: plugin, unsafe});
27
+ return await super._update({ext: plugin, unsafe});
28
+ }
29
+
30
+ async run ({plugin, scriptName}) {
31
+ return await super._run({ext: plugin, scriptName});
25
32
  }
26
33
 
27
34
  getPostInstallText ({extName, extData}) {
@@ -41,3 +48,9 @@ export default class PluginCommand extends ExtensionCommand {
41
48
  }
42
49
 
43
50
  }
51
+
52
+ /**
53
+ * @typedef PluginCommandOptions
54
+ * @property {import('../extension/extension-config').ExtensionConfig<import('../extension/manifest').PluginType>} config
55
+ * @property {boolean} json
56
+ */
package/lib/cli/utils.js CHANGED
@@ -7,7 +7,7 @@ const JSON_SPACES = 4;
7
7
  /***
8
8
  * Log an error to the console and exit the process.
9
9
  * @param {boolean} json - whether we should log json or text
10
- * @param {string} msg - error message
10
+ * @param {any} msg - error message, object, Error instance, etc.
11
11
  */
12
12
  function errAndQuit (json, msg) {
13
13
  if (json) {
@@ -52,9 +52,29 @@ async function spinWith (json, msg, fn) {
52
52
  }
53
53
  }
54
54
 
55
+ class RingBuffer {
56
+ constructor (size = 50) {
57
+ this.size = size;
58
+ this.buffer = [];
59
+ }
60
+ getBuff () {
61
+ return this.buffer;
62
+ }
63
+ dequeue () {
64
+ this.buffer.shift();
65
+ }
66
+ enqueue (item) {
67
+ if (this.buffer.length >= this.size) {
68
+ this.dequeue();
69
+ }
70
+ this.buffer.push(item);
71
+ }
72
+ }
73
+
55
74
  export {
56
75
  errAndQuit,
57
76
  log,
58
77
  spinWith,
59
- JSON_SPACES
78
+ JSON_SPACES,
79
+ RingBuffer
60
80
  };