@ohos-ports/webdriver-manager 0.0.0-stage → 12.1.9-beta.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.
Files changed (123) hide show
  1. package/.circleci/config.yml +24 -0
  2. package/CHANGELOG.md +670 -0
  3. package/CONTRIBUTING.md +61 -0
  4. package/LICENSE +21 -0
  5. package/README.md +75 -2
  6. package/bin/webdriver-manager +56 -0
  7. package/built/config.json +18 -0
  8. package/built/lib/binaries/android_sdk.d.ts +26 -0
  9. package/built/lib/binaries/android_sdk.js +103 -0
  10. package/built/lib/binaries/android_sdk.js.map +1 -0
  11. package/built/lib/binaries/appium.d.ts +18 -0
  12. package/built/lib/binaries/appium.js +42 -0
  13. package/built/lib/binaries/appium.js.map +1 -0
  14. package/built/lib/binaries/binary.d.ts +66 -0
  15. package/built/lib/binaries/binary.js +76 -0
  16. package/built/lib/binaries/binary.js.map +1 -0
  17. package/built/lib/binaries/chrome_driver.d.ts +12 -0
  18. package/built/lib/binaries/chrome_driver.js +38 -0
  19. package/built/lib/binaries/chrome_driver.js.map +1 -0
  20. package/built/lib/binaries/chrome_xml.d.ts +36 -0
  21. package/built/lib/binaries/chrome_xml.js +156 -0
  22. package/built/lib/binaries/chrome_xml.js.map +1 -0
  23. package/built/lib/binaries/config_source.d.ts +38 -0
  24. package/built/lib/binaries/config_source.js +209 -0
  25. package/built/lib/binaries/config_source.js.map +1 -0
  26. package/built/lib/binaries/gecko_driver.d.ts +13 -0
  27. package/built/lib/binaries/gecko_driver.js +50 -0
  28. package/built/lib/binaries/gecko_driver.js.map +1 -0
  29. package/built/lib/binaries/gecko_driver_github.d.ts +14 -0
  30. package/built/lib/binaries/gecko_driver_github.js +93 -0
  31. package/built/lib/binaries/gecko_driver_github.js.map +1 -0
  32. package/built/lib/binaries/iedriver.d.ts +13 -0
  33. package/built/lib/binaries/iedriver.js +38 -0
  34. package/built/lib/binaries/iedriver.js.map +1 -0
  35. package/built/lib/binaries/iedriver_xml.d.ts +9 -0
  36. package/built/lib/binaries/iedriver_xml.js +69 -0
  37. package/built/lib/binaries/iedriver_xml.js.map +1 -0
  38. package/built/lib/binaries/index.d.ts +7 -0
  39. package/built/lib/binaries/index.js +13 -0
  40. package/built/lib/binaries/index.js.map +1 -0
  41. package/built/lib/binaries/standalone.d.ts +13 -0
  42. package/built/lib/binaries/standalone.js +41 -0
  43. package/built/lib/binaries/standalone.js.map +1 -0
  44. package/built/lib/binaries/standalone_xml.d.ts +9 -0
  45. package/built/lib/binaries/standalone_xml.js +89 -0
  46. package/built/lib/binaries/standalone_xml.js.map +1 -0
  47. package/built/lib/cli/cli.d.ts +57 -0
  48. package/built/lib/cli/cli.js +136 -0
  49. package/built/lib/cli/cli.js.map +1 -0
  50. package/built/lib/cli/index.d.ts +4 -0
  51. package/built/lib/cli/index.js +10 -0
  52. package/built/lib/cli/index.js.map +1 -0
  53. package/built/lib/cli/logger.d.ts +95 -0
  54. package/built/lib/cli/logger.js +264 -0
  55. package/built/lib/cli/logger.js.map +1 -0
  56. package/built/lib/cli/options.d.ts +22 -0
  57. package/built/lib/cli/options.js +67 -0
  58. package/built/lib/cli/options.js.map +1 -0
  59. package/built/lib/cli/programs.d.ts +93 -0
  60. package/built/lib/cli/programs.js +226 -0
  61. package/built/lib/cli/programs.js.map +1 -0
  62. package/built/lib/cli_instance.d.ts +2 -0
  63. package/built/lib/cli_instance.js +18 -0
  64. package/built/lib/cli_instance.js.map +1 -0
  65. package/built/lib/cmds/clean.d.ts +2 -0
  66. package/built/lib/cmds/clean.js +39 -0
  67. package/built/lib/cmds/clean.js.map +1 -0
  68. package/built/lib/cmds/index.d.ts +1 -0
  69. package/built/lib/cmds/index.js +7 -0
  70. package/built/lib/cmds/index.js.map +1 -0
  71. package/built/lib/cmds/initialize.d.ts +3 -0
  72. package/built/lib/cmds/initialize.js +244 -0
  73. package/built/lib/cmds/initialize.js.map +1 -0
  74. package/built/lib/cmds/opts.d.ts +38 -0
  75. package/built/lib/cmds/opts.js +91 -0
  76. package/built/lib/cmds/opts.js.map +1 -0
  77. package/built/lib/cmds/shutdown.d.ts +2 -0
  78. package/built/lib/cmds/shutdown.js +46 -0
  79. package/built/lib/cmds/shutdown.js.map +1 -0
  80. package/built/lib/cmds/start.d.ts +2 -0
  81. package/built/lib/cmds/start.js +458 -0
  82. package/built/lib/cmds/start.js.map +1 -0
  83. package/built/lib/cmds/status.d.ts +2 -0
  84. package/built/lib/cmds/status.js +120 -0
  85. package/built/lib/cmds/status.js.map +1 -0
  86. package/built/lib/cmds/update.d.ts +3 -0
  87. package/built/lib/cmds/update.js +300 -0
  88. package/built/lib/cmds/update.js.map +1 -0
  89. package/built/lib/cmds/version.d.ts +2 -0
  90. package/built/lib/cmds/version.js +17 -0
  91. package/built/lib/cmds/version.js.map +1 -0
  92. package/built/lib/config.d.ts +58 -0
  93. package/built/lib/config.js +97 -0
  94. package/built/lib/config.js.map +1 -0
  95. package/built/lib/files/downloaded_binary.d.ts +14 -0
  96. package/built/lib/files/downloaded_binary.js +32 -0
  97. package/built/lib/files/downloaded_binary.js.map +1 -0
  98. package/built/lib/files/downloader.d.ts +20 -0
  99. package/built/lib/files/downloader.js +103 -0
  100. package/built/lib/files/downloader.js.map +1 -0
  101. package/built/lib/files/file_manager.d.ts +72 -0
  102. package/built/lib/files/file_manager.js +239 -0
  103. package/built/lib/files/file_manager.js.map +1 -0
  104. package/built/lib/files/index.d.ts +3 -0
  105. package/built/lib/files/index.js +9 -0
  106. package/built/lib/files/index.js.map +1 -0
  107. package/built/lib/http_utils.d.ts +27 -0
  108. package/built/lib/http_utils.js +118 -0
  109. package/built/lib/http_utils.js.map +1 -0
  110. package/built/lib/utils.d.ts +6 -0
  111. package/built/lib/utils.js +115 -0
  112. package/built/lib/utils.js.map +1 -0
  113. package/built/lib/webdriver.d.ts +0 -0
  114. package/built/lib/webdriver.js +22 -0
  115. package/built/lib/webdriver.js.map +1 -0
  116. package/built/package.json +85 -0
  117. package/config.json +18 -0
  118. package/docs/README.md +6 -0
  119. package/docs/mobile.md +79 -0
  120. package/docs/protractor.md +41 -0
  121. package/docs/versions.md +87 -0
  122. package/gulpfile.js +44 -0
  123. package/package.json +83 -4
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ // Will use chalk if chalk is available to add color to console logging
6
+ let chalk;
7
+ let printRed;
8
+ let printYellow;
9
+ let printGray;
10
+ try {
11
+ chalk = require('chalk');
12
+ printRed = chalk.red;
13
+ printYellow = chalk.yellow;
14
+ printGray = chalk.gray;
15
+ }
16
+ catch (e) {
17
+ printRed = printYellow = printGray = (msg) => {
18
+ return msg;
19
+ };
20
+ }
21
+ var LogLevel;
22
+ (function (LogLevel) {
23
+ LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
24
+ LogLevel[LogLevel["WARN"] = 1] = "WARN";
25
+ LogLevel[LogLevel["INFO"] = 2] = "INFO";
26
+ LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
27
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
28
+ var WriteTo;
29
+ (function (WriteTo) {
30
+ WriteTo[WriteTo["CONSOLE"] = 0] = "CONSOLE";
31
+ WriteTo[WriteTo["FILE"] = 1] = "FILE";
32
+ WriteTo[WriteTo["BOTH"] = 2] = "BOTH";
33
+ WriteTo[WriteTo["NONE"] = 3] = "NONE";
34
+ })(WriteTo = exports.WriteTo || (exports.WriteTo = {}));
35
+ let logFile = 'webdriver.log'; // the default log file name
36
+ /**
37
+ * Logger class adds timestamp output, log levels, and identifiers to help
38
+ * when debugging. Also could write to console, file, both, or none.
39
+ */
40
+ class Logger {
41
+ /**
42
+ * Creates a logger instance with an ID for the logger.
43
+ * @constructor
44
+ */
45
+ constructor(id) {
46
+ this.id = id;
47
+ }
48
+ /**
49
+ * Set up the write location. If writing to a file, get the file descriptor.
50
+ * @param writeTo The enum for where to write the logs.
51
+ * @param opt_logFile An optional parameter to override the log file location.
52
+ */
53
+ static setWrite(writeTo, opt_logFile) {
54
+ if (opt_logFile) {
55
+ logFile = opt_logFile;
56
+ }
57
+ Logger.writeTo = writeTo;
58
+ if (Logger.writeTo == WriteTo.FILE || Logger.writeTo == WriteTo.BOTH) {
59
+ Logger.fd = fs.openSync(path.resolve(logFile), 'a');
60
+ Logger.firstWrite = false;
61
+ }
62
+ }
63
+ /**
64
+ * Log INFO
65
+ * @param ...msgs multiple arguments to be logged.
66
+ */
67
+ info(...msgs) {
68
+ this.log_(LogLevel.INFO, msgs);
69
+ }
70
+ /**
71
+ * Log DEBUG
72
+ * @param ...msgs multiple arguments to be logged.
73
+ */
74
+ debug(...msgs) {
75
+ this.log_(LogLevel.DEBUG, msgs);
76
+ }
77
+ /**
78
+ * Log WARN
79
+ * @param ...msgs multiple arguments to be logged.
80
+ */
81
+ warn(...msgs) {
82
+ this.log_(LogLevel.WARN, msgs);
83
+ }
84
+ /**
85
+ * Log ERROR
86
+ * @param ...msgs multiple arguments to be logged.
87
+ */
88
+ error(...msgs) {
89
+ this.log_(LogLevel.ERROR, msgs);
90
+ }
91
+ /**
92
+ * For the log level set, check to see if the messages should be logged.
93
+ * @param logLevel The log level of the message.
94
+ * @param msgs The messages to be logged
95
+ */
96
+ log_(logLevel, msgs) {
97
+ switch (Logger.logLevel) {
98
+ case LogLevel.ERROR:
99
+ if (logLevel <= LogLevel.ERROR) {
100
+ this.print_(logLevel, msgs);
101
+ }
102
+ break;
103
+ case LogLevel.WARN:
104
+ if (logLevel <= LogLevel.WARN) {
105
+ this.print_(logLevel, msgs);
106
+ }
107
+ break;
108
+ case LogLevel.INFO:
109
+ if (logLevel <= LogLevel.INFO) {
110
+ this.print_(logLevel, msgs);
111
+ }
112
+ break;
113
+ case LogLevel.DEBUG:
114
+ if (logLevel <= LogLevel.DEBUG) {
115
+ this.print_(logLevel, msgs);
116
+ }
117
+ break;
118
+ default:
119
+ throw new Error('Log level undefined');
120
+ }
121
+ }
122
+ /**
123
+ * Format with timestamp, log level, identifier, and message and log to
124
+ * specified medium (console, file, both, none).
125
+ * @param logLevel The log level of the message.
126
+ * @param msgs The messages to be logged.
127
+ */
128
+ print_(logLevel, msgs) {
129
+ let consoleLog = '';
130
+ let fileLog = '';
131
+ if (Logger.showTimestamp) {
132
+ consoleLog += Logger.timestamp_(WriteTo.CONSOLE);
133
+ fileLog += Logger.timestamp_(WriteTo.FILE);
134
+ }
135
+ consoleLog += Logger.level_(logLevel, this.id, WriteTo.CONSOLE);
136
+ fileLog += Logger.level_(logLevel, this.id, WriteTo.FILE);
137
+ if (Logger.showId) {
138
+ consoleLog += Logger.id_(logLevel, this.id, WriteTo.CONSOLE);
139
+ fileLog += Logger.id_(logLevel, this.id, WriteTo.FILE);
140
+ }
141
+ consoleLog += ' -';
142
+ fileLog += ' - ';
143
+ switch (Logger.writeTo) {
144
+ case WriteTo.CONSOLE:
145
+ msgs.unshift(consoleLog);
146
+ console.log.apply(console, msgs);
147
+ break;
148
+ case WriteTo.FILE:
149
+ // for the first line written to the file, add a space
150
+ if (!Logger.firstWrite) {
151
+ fs.writeSync(Logger.fd, '\n');
152
+ Logger.firstWrite = true;
153
+ }
154
+ fileLog += ' ' + Logger.msgToFile_(msgs);
155
+ fs.writeSync(Logger.fd, fileLog + '\n');
156
+ break;
157
+ case WriteTo.BOTH:
158
+ // for the first line written to the file, add a space
159
+ if (!Logger.firstWrite) {
160
+ fs.writeSync(Logger.fd, '\n');
161
+ Logger.firstWrite = true;
162
+ }
163
+ fileLog += ' ' + Logger.msgToFile_(msgs);
164
+ fs.writeSync(Logger.fd, fileLog + '\n');
165
+ msgs.unshift(consoleLog);
166
+ console.log.apply(console, msgs);
167
+ break;
168
+ case WriteTo.NONE:
169
+ break;
170
+ }
171
+ }
172
+ /**
173
+ * Get a timestamp formatted with [hh:mm:ss]
174
+ * @param writeTo The enum for where to write the logs.
175
+ * @return The string of the formatted timestamp
176
+ */
177
+ static timestamp_(writeTo) {
178
+ let d = new Date();
179
+ let ts = '[';
180
+ let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
181
+ let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
182
+ let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
183
+ if (writeTo == WriteTo.CONSOLE) {
184
+ ts += printGray(hours + ':' + minutes + ':' + seconds) + ']';
185
+ }
186
+ else {
187
+ ts += hours + ':' + minutes + ':' + seconds + ']';
188
+ }
189
+ ts += ' ';
190
+ return ts;
191
+ }
192
+ /**
193
+ * Get the identifier of the logger as '/<id>'
194
+ * @param logLevel The log level of the message.
195
+ * @param writeTo The enum for where to write the logs.
196
+ * @return The string of the formatted id
197
+ */
198
+ static id_(logLevel, id, writeTo) {
199
+ let level = LogLevel[logLevel].toString();
200
+ if (writeTo === WriteTo.FILE) {
201
+ return '/' + id;
202
+ }
203
+ else if (logLevel === LogLevel.ERROR) {
204
+ return printRed('/' + id);
205
+ }
206
+ else if (logLevel === LogLevel.WARN) {
207
+ return printYellow('/' + id);
208
+ }
209
+ else {
210
+ return '/' + id;
211
+ }
212
+ }
213
+ /**
214
+ * Get the log level formatted with the first letter. For info, it is I.
215
+ * @param logLevel The log level of the message.
216
+ * @param writeTo The enum for where to write the logs.
217
+ * @return The string of the formatted log level
218
+ */
219
+ static level_(logLevel, id, writeTo) {
220
+ let level = LogLevel[logLevel].toString();
221
+ if (writeTo === WriteTo.FILE) {
222
+ return level[0];
223
+ }
224
+ else if (logLevel === LogLevel.ERROR) {
225
+ return printRed(level[0]);
226
+ }
227
+ else if (logLevel === LogLevel.WARN) {
228
+ return printYellow(level[0]);
229
+ }
230
+ else {
231
+ return level[0];
232
+ }
233
+ }
234
+ /**
235
+ * Convert the list of messages to a single string message.
236
+ * @param msgs The list of messages.
237
+ * @return The string of the formatted messages
238
+ */
239
+ static msgToFile_(msgs) {
240
+ let log = '';
241
+ for (let pos = 0; pos < msgs.length; pos++) {
242
+ let msg = msgs[pos];
243
+ let ret;
244
+ if (typeof msg === 'object') {
245
+ ret = JSON.stringify(msg);
246
+ }
247
+ else {
248
+ ret = msg;
249
+ }
250
+ if (pos !== msgs.length - 1) {
251
+ ret += ' ';
252
+ }
253
+ log += ret;
254
+ }
255
+ return log;
256
+ }
257
+ }
258
+ Logger.logLevel = LogLevel.INFO;
259
+ Logger.showTimestamp = true;
260
+ Logger.showId = true;
261
+ Logger.writeTo = WriteTo.CONSOLE;
262
+ Logger.firstWrite = false;
263
+ exports.Logger = Logger;
264
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../lib/cli/logger.ts"],"names":[],"mappings":";;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,uEAAuE;AACvE,IAAI,KAAU,CAAC;AACf,IAAI,QAAkB,CAAC;AACvB,IAAI,WAAqB,CAAC;AAC1B,IAAI,SAAmB,CAAC;AAExB,IAAI,CAAC;IACH,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC;IACrB,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC;IAC3B,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;AACzB,CAAC;AAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACX,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,CAAC,GAAQ;QAC5C,MAAM,CAAC,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AAED,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,yCAAK,CAAA;IACL,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;AACP,CAAC,EALW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAKnB;AAED,IAAY,OAKX;AALD,WAAY,OAAO;IACjB,2CAAO,CAAA;IACP,qCAAI,CAAA;IACJ,qCAAI,CAAA;IACJ,qCAAI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,GAAG,CAAC;QACb,CAAC;QACD,MAAM,CAAC,GAAG,CAAC;IACb,CAAC;;AAjOM,eAAQ,GAAa,QAAQ,CAAC,IAAI,CAAC;AACnC,oBAAa,GAAY,IAAI,CAAC;AAC9B,aAAM,GAAY,IAAI,CAAC;AACvB,cAAO,GAAY,OAAO,CAAC,OAAO,CAAC;AAEnC,iBAAU,GAAY,KAAK,CAAC;AANrC,wBAmOC"}
@@ -0,0 +1,22 @@
1
+ export interface MinimistArgs {
2
+ [opt: string]: string[];
3
+ }
4
+ export interface Args {
5
+ [opt: string]: number | string | boolean;
6
+ }
7
+ export interface Options {
8
+ [opt: string]: Option;
9
+ }
10
+ export declare class Option {
11
+ opt: string;
12
+ description: string;
13
+ type: string;
14
+ defaultValue: number | string | boolean;
15
+ value: number | string | boolean;
16
+ constructor(opt: string, description: string, type: string, defaultValue?: number | string | boolean);
17
+ getValue_(): number | string | boolean;
18
+ getNumber(): number;
19
+ getString(): string;
20
+ getBoolean(): boolean;
21
+ }
22
+ export declare function unparseOptions(options: Options): string[];
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Option {
4
+ constructor(opt, description, type, defaultValue) {
5
+ this.opt = opt;
6
+ this.description = description;
7
+ this.type = type;
8
+ if (defaultValue != null) {
9
+ this.defaultValue = defaultValue;
10
+ }
11
+ }
12
+ getValue_() {
13
+ if (typeof this.value !== 'undefined') {
14
+ return this.value;
15
+ }
16
+ else {
17
+ return this.defaultValue;
18
+ }
19
+ }
20
+ getNumber() {
21
+ let value = this.getValue_();
22
+ if (value != null && (typeof value === 'number' || typeof value === 'string')) {
23
+ return +value;
24
+ }
25
+ else {
26
+ return null;
27
+ }
28
+ }
29
+ getString() {
30
+ let value = this.getValue_();
31
+ if (value != null) {
32
+ return '' + this.getValue_();
33
+ }
34
+ else {
35
+ return '';
36
+ }
37
+ }
38
+ getBoolean() {
39
+ let value = this.getValue_();
40
+ if (value != null) {
41
+ if (typeof value === 'string') {
42
+ return !(value === '0' || value === 'false');
43
+ }
44
+ else if (typeof value === 'number') {
45
+ return value !== 0;
46
+ }
47
+ else {
48
+ return value;
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+ }
54
+ exports.Option = Option;
55
+ function unparseOptions(options) {
56
+ var args = [];
57
+ for (let name in options) {
58
+ let value = options[name].getValue_();
59
+ if (value !== options[name].defaultValue) {
60
+ args.push('--' + name, '' + value);
61
+ }
62
+ }
63
+ return args;
64
+ }
65
+ exports.unparseOptions = unparseOptions;
66
+ ;
67
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../lib/cli/options.ts"],"names":[],"mappings":";;AAMA;IAOE,YACI,GAAW,EAAE,WAAmB,EAAE,IAAY,EAAE,YAAoC;QACtF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,EAAE,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACnC,CAAC;IACH,CAAC;IAED,SAAS;QACP,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAAC,IAAI,CAAC,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,SAAS;QACP,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC7B,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC9E,MAAM,CAAC,CAAC,KAAK,CAA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AAI,CAAC,IAAI,GAAG,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC;AACd,CAAC;AATD,wCASC;AAAA,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { MinimistArgs, Option, Options } from './options';
2
+ /**
3
+ * Dictionary that maps the command and the program.
4
+ */
5
+ export interface Programs {
6
+ [cmd: string]: Program;
7
+ }
8
+ /**
9
+ * A program has a command, a description, options, and a run method
10
+ */
11
+ export declare class Program {
12
+ static MIN_SPACING: number;
13
+ cmd: string;
14
+ cmdDescription: string;
15
+ options: Options;
16
+ runMethod: Function;
17
+ helpDescription: string;
18
+ version: string;
19
+ /**
20
+ * Register a command and the description.
21
+ * @param cmd The command.
22
+ * @param cmdDescription The description of the command.
23
+ * @returns The program for method chaining.
24
+ */
25
+ command(cmd: string, cmdDescription: string): Program;
26
+ /**
27
+ * Register a new option.
28
+ * @param opt The option.
29
+ * @param description The description of the option.
30
+ * @param type The type of value expected: boolean, number, or string
31
+ * @param defaultValue The option's default value.
32
+ * @returns The program for method chaining.
33
+ */
34
+ option(opt: string, description: string, type: string, opt_defaultValue?: number | string | boolean): Program;
35
+ /**
36
+ * Adds an option to the program.
37
+ * @param option The option.
38
+ * @returns The program for method chaining.
39
+ */
40
+ addOption(option: Option): Program;
41
+ /**
42
+ * Registers a method that will be used to run the program.
43
+ * @param runMethod The method that will be used to run the program.
44
+ * @returns The program for method chaining.
45
+ */
46
+ action(runMethod: Function): Program;
47
+ /**
48
+ * Adds the value to the options and passes the updated options to the run
49
+ * method.
50
+ * @param args The arguments that will be parsed to run the method.
51
+ */
52
+ run(json: JSON): Promise<void>;
53
+ private getValue_(key, json);
54
+ /**
55
+ * Prints the command with the description. The description will have spaces
56
+ * between the cmd so that the starting position is "posDescription". If the
57
+ * gap between the cmd and the description is less than MIN_SPACING or
58
+ * posDescription is undefined, the spacing will be MIN_SPACING.
59
+ *
60
+ * @param opt_postDescription Starting position of the description.
61
+ */
62
+ printCmd(opt_posDescription?: number): void;
63
+ /**
64
+ * Prints the options with the option descriptions and default values.
65
+ * The posDescription and posDefault is the starting position for the option
66
+ * description. If extOptions are provided, check to see if we have already
67
+ * printed those options. Also, once we print the option, add them to the extOptions.
68
+ *
69
+ * @param posDescription Position to start logging the description.
70
+ * @param posDefault Position to start logging the default value.
71
+ * @param opt_extOptions A collection of options that will be updated.
72
+ */
73
+ printOptions(posDescription: number, posDefault: number, opt_extOptions?: Options): void;
74
+ /**
75
+ * Assuming that the this program can run by itself, to print out the program's
76
+ * help. Also assuming that the commands are called cmd-run and cmd-help.
77
+ */
78
+ printHelp(): void;
79
+ posDescription(): number;
80
+ posDefault(): number;
81
+ lengthOf_(param: string): number;
82
+ /**
83
+ * Create a collection of options used by this program.
84
+ * @returns The options used in the programs.
85
+ */
86
+ getOptions_(allOptions: Options): Options;
87
+ /**
88
+ * Get the options used by the program and create the minimist options
89
+ * to ensure that minimist parses the values properly.
90
+ * @returns The options for minimist.
91
+ */
92
+ getMinimistOptions(): MinimistArgs;
93
+ }
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const options_1 = require("./options");
4
+ /**
5
+ * A program has a command, a description, options, and a run method
6
+ */
7
+ class Program {
8
+ constructor() {
9
+ this.options = {};
10
+ }
11
+ /**
12
+ * Register a command and the description.
13
+ * @param cmd The command.
14
+ * @param cmdDescription The description of the command.
15
+ * @returns The program for method chaining.
16
+ */
17
+ command(cmd, cmdDescription) {
18
+ this.cmd = cmd;
19
+ this.cmdDescription = cmdDescription;
20
+ return this;
21
+ }
22
+ /**
23
+ * Register a new option.
24
+ * @param opt The option.
25
+ * @param description The description of the option.
26
+ * @param type The type of value expected: boolean, number, or string
27
+ * @param defaultValue The option's default value.
28
+ * @returns The program for method chaining.
29
+ */
30
+ option(opt, description, type, opt_defaultValue) {
31
+ this.options[opt] = new options_1.Option(opt, description, type, opt_defaultValue);
32
+ return this;
33
+ }
34
+ /**
35
+ * Adds an option to the program.
36
+ * @param option The option.
37
+ * @returns The program for method chaining.
38
+ */
39
+ addOption(option) {
40
+ this.options[option.opt] = option;
41
+ return this;
42
+ }
43
+ /**
44
+ * Registers a method that will be used to run the program.
45
+ * @param runMethod The method that will be used to run the program.
46
+ * @returns The program for method chaining.
47
+ */
48
+ action(runMethod) {
49
+ this.runMethod = runMethod;
50
+ return this;
51
+ }
52
+ /**
53
+ * Adds the value to the options and passes the updated options to the run
54
+ * method.
55
+ * @param args The arguments that will be parsed to run the method.
56
+ */
57
+ run(json) {
58
+ for (let opt in this.options) {
59
+ this.options[opt].value = this.getValue_(opt, json);
60
+ }
61
+ return Promise.resolve(this.runMethod(this.options));
62
+ }
63
+ getValue_(key, json) {
64
+ let keyList = key.split('.');
65
+ let tempJson = json;
66
+ while (keyList.length > 0) {
67
+ let keyItem = keyList[0];
68
+ if (tempJson[keyItem] != null) {
69
+ tempJson = tempJson[keyItem];
70
+ keyList = keyList.slice(1);
71
+ }
72
+ else {
73
+ return undefined;
74
+ }
75
+ }
76
+ return tempJson;
77
+ }
78
+ /**
79
+ * Prints the command with the description. The description will have spaces
80
+ * between the cmd so that the starting position is "posDescription". If the
81
+ * gap between the cmd and the description is less than MIN_SPACING or
82
+ * posDescription is undefined, the spacing will be MIN_SPACING.
83
+ *
84
+ * @param opt_postDescription Starting position of the description.
85
+ */
86
+ printCmd(opt_posDescription) {
87
+ let log = ' ' + this.cmd;
88
+ let spacing = Program.MIN_SPACING;
89
+ if (opt_posDescription) {
90
+ let diff = opt_posDescription - log.length;
91
+ if (diff < Program.MIN_SPACING) {
92
+ spacing = Program.MIN_SPACING;
93
+ }
94
+ else {
95
+ spacing = diff;
96
+ }
97
+ }
98
+ log += Array(spacing).join(' ') + this.cmdDescription;
99
+ console.log(log);
100
+ }
101
+ /**
102
+ * Prints the options with the option descriptions and default values.
103
+ * The posDescription and posDefault is the starting position for the option
104
+ * description. If extOptions are provided, check to see if we have already
105
+ * printed those options. Also, once we print the option, add them to the extOptions.
106
+ *
107
+ * @param posDescription Position to start logging the description.
108
+ * @param posDefault Position to start logging the default value.
109
+ * @param opt_extOptions A collection of options that will be updated.
110
+ */
111
+ printOptions(posDescription, posDefault, opt_extOptions) {
112
+ for (let opt in this.options) {
113
+ // we have already logged it
114
+ if (opt_extOptions && opt_extOptions[opt]) {
115
+ continue;
116
+ }
117
+ let option = this.options[opt];
118
+ let log = ' --' + option.opt;
119
+ let spacing = Program.MIN_SPACING;
120
+ // description
121
+ let diff = posDescription - log.length;
122
+ if (diff < Program.MIN_SPACING) {
123
+ spacing = Program.MIN_SPACING;
124
+ }
125
+ else {
126
+ spacing = diff;
127
+ }
128
+ log += Array(spacing).join(' ') + option.description;
129
+ // default value
130
+ if (option.defaultValue) {
131
+ spacing = Program.MIN_SPACING;
132
+ let diff = posDefault - log.length - 1;
133
+ if (diff <= Program.MIN_SPACING) {
134
+ spacing = Program.MIN_SPACING;
135
+ }
136
+ else {
137
+ spacing = diff;
138
+ }
139
+ log += Array(spacing).join(' ');
140
+ log += '[default: ' + option.defaultValue + ']';
141
+ }
142
+ console.log(log);
143
+ if (opt_extOptions) {
144
+ opt_extOptions[option.opt] = option;
145
+ }
146
+ }
147
+ }
148
+ /**
149
+ * Assuming that the this program can run by itself, to print out the program's
150
+ * help. Also assuming that the commands are called cmd-run and cmd-help.
151
+ */
152
+ printHelp() {
153
+ console.log('\n' +
154
+ 'Usage: ' + this.cmd + ' [options]\n' +
155
+ ' ' + this.cmd + ' help\n' +
156
+ 'Description: ' + this.cmdDescription + '\n');
157
+ console.log('Options:');
158
+ this.printOptions(this.posDescription(), this.posDefault());
159
+ }
160
+ posDescription() {
161
+ return this.lengthOf_('opt') + 2 * Program.MIN_SPACING;
162
+ }
163
+ posDefault() {
164
+ return this.posDescription() + this.lengthOf_('description') + Program.MIN_SPACING;
165
+ }
166
+ lengthOf_(param) {
167
+ let maxLength = -1;
168
+ for (let opt in this.options) {
169
+ let option = this.options[opt];
170
+ if (param === 'description') {
171
+ maxLength = Math.max(maxLength, option.description.length);
172
+ }
173
+ else if (param === 'opt') {
174
+ maxLength = Math.max(maxLength, option.opt.length);
175
+ }
176
+ }
177
+ return maxLength;
178
+ }
179
+ /**
180
+ * Create a collection of options used by this program.
181
+ * @returns The options used in the programs.
182
+ */
183
+ getOptions_(allOptions) {
184
+ for (let opt in this.options) {
185
+ allOptions[opt] = this.options[opt];
186
+ }
187
+ return allOptions;
188
+ }
189
+ /**
190
+ * Get the options used by the program and create the minimist options
191
+ * to ensure that minimist parses the values properly.
192
+ * @returns The options for minimist.
193
+ */
194
+ getMinimistOptions() {
195
+ let allOptions = {};
196
+ allOptions = this.getOptions_(allOptions);
197
+ let minimistOptions = {};
198
+ let minimistBoolean = [];
199
+ let minimistString = [];
200
+ let minimistNumber = [];
201
+ let minimistDefault = {};
202
+ for (let opt in allOptions) {
203
+ let option = allOptions[opt];
204
+ if (option.type === 'boolean') {
205
+ minimistBoolean.push(option.opt);
206
+ }
207
+ else if (option.type === 'string') {
208
+ minimistString.push(option.opt);
209
+ }
210
+ else if (option.type === 'number') {
211
+ minimistNumber.push(option.opt);
212
+ }
213
+ if (typeof option.defaultValue !== 'undefined') {
214
+ minimistDefault[option.opt] = option.defaultValue;
215
+ }
216
+ }
217
+ minimistOptions['boolean'] = minimistBoolean;
218
+ minimistOptions['string'] = minimistString;
219
+ minimistOptions['number'] = minimistNumber;
220
+ minimistOptions['default'] = minimistDefault;
221
+ return minimistOptions;
222
+ }
223
+ }
224
+ Program.MIN_SPACING = 4;
225
+ exports.Program = Program;
226
+ //# sourceMappingURL=programs.js.map