@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,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const request = require("@ohos-ports/request");
6
+ const url = require("url");
7
+ const cli_1 = require("../cli");
8
+ const http_utils_1 = require("../http_utils");
9
+ let logger = new cli_1.Logger('downloader');
10
+ /**
11
+ * The file downloader.
12
+ */
13
+ class Downloader {
14
+ /**
15
+ * Http get the file. Check the content length of the file before writing the file.
16
+ * If the content length does not match, remove it and download the file.
17
+ *
18
+ * @param binary The binary of interest.
19
+ * @param fileName The file name.
20
+ * @param outputDir The directory where files are downloaded and stored.
21
+ * @param contentLength The content length of the existing file.
22
+ * @param opt_proxy The proxy for downloading files.
23
+ * @param opt_callback Callback method to be executed after the file is downloaded.
24
+ * @returns Promise<boolean> Resolves true = downloaded. Resolves false = not downloaded.
25
+ * Rejected with an error.
26
+ */
27
+ static getFile(binary, fileUrl, fileName, outputDir, contentLength, callback) {
28
+ let filePath = path.resolve(outputDir, fileName);
29
+ let file;
30
+ let options = http_utils_1.HttpUtils.initOptions(fileUrl);
31
+ let req = null;
32
+ let resContentLength;
33
+ return new Promise((resolve, reject) => {
34
+ req = request(options);
35
+ req.on('response', response => {
36
+ if (response.statusCode === 200) {
37
+ resContentLength = +response.headers['content-length'];
38
+ if (contentLength === resContentLength) {
39
+ // if the size is the same, do not download and stop here
40
+ response.destroy();
41
+ resolve(false);
42
+ }
43
+ else {
44
+ let curl = outputDir + '/' + fileName + ' ' + options.url;
45
+ if (http_utils_1.HttpUtils.requestOpts.proxy) {
46
+ let pathUrl = url.parse(options.url.toString()).path;
47
+ let host = url.parse(options.url.toString()).host;
48
+ let newFileUrl = url.resolve(http_utils_1.HttpUtils.requestOpts.proxy, pathUrl);
49
+ curl = outputDir + '/' + fileName + ' \'' + newFileUrl +
50
+ '\' -H \'host:' + host + '\'';
51
+ }
52
+ if (http_utils_1.HttpUtils.requestOpts.ignoreSSL) {
53
+ curl = 'k ' + curl;
54
+ }
55
+ logger.info('curl -o' + curl);
56
+ // only pipe if the headers are different length
57
+ file = fs.createWriteStream(filePath);
58
+ req.pipe(file);
59
+ file.on('close', () => {
60
+ fs.stat(filePath, (error, stats) => {
61
+ if (error) {
62
+ error.msg = 'Error: Got error ' + error + ' from ' + fileUrl;
63
+ return reject(error);
64
+ }
65
+ if (stats.size != resContentLength) {
66
+ error.msg = 'Error: corrupt download for ' + fileName +
67
+ '. Please re-run webdriver-manager update';
68
+ fs.unlinkSync(filePath);
69
+ reject(error);
70
+ }
71
+ if (callback) {
72
+ callback(binary, outputDir, fileName);
73
+ }
74
+ resolve(true);
75
+ });
76
+ });
77
+ }
78
+ }
79
+ else {
80
+ let error = new Error();
81
+ error.msg =
82
+ 'Expected response code 200, received: ' + response.statusCode;
83
+ reject(error);
84
+ }
85
+ });
86
+ req.on('error', error => {
87
+ if (error.code === 'ETIMEDOUT') {
88
+ error.msg = 'Connection timeout downloading: ' + fileUrl +
89
+ '. Default timeout is 4 minutes.';
90
+ }
91
+ else if (error.connect) {
92
+ error.msg = 'Could not connect to the server to download: ' + fileUrl;
93
+ }
94
+ reject(error);
95
+ });
96
+ })
97
+ .catch(error => {
98
+ logger.error(error.msg || error.message);
99
+ });
100
+ }
101
+ }
102
+ exports.Downloader = Downloader;
103
+ //# sourceMappingURL=downloader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"downloader.js","sourceRoot":"","sources":["../../../lib/files/downloader.ts"],"names":[],"mappings":";;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,mCAAmC;AACnC,2BAA2B;AAG3B,gCAA8B;AAE9B,8CAAwC;AAExC,IAAI,MAAM,GAAG,IAAI,YAAM,CAAC,YAAY,CAAC,CAAC;AAEtC;;GAEG;AACH;IACE;;;;;;;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CAAC;gCACxC,CAAC;gCACD,OAAO,CAAC,IAAI,CAAC,CAAC;4BAChB,CAAC,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC;gBAEH,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACN,IAAI,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;oBACvB,KAAa,CAAC,GAAG;wBACd,wCAAwC,GAAG,QAAQ,CAAC,UAAU,CAAC;oBACnE,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK;gBACnB,EAAE,CAAC,CAAE,KAAa,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC;oBACvC,KAAa,CAAC,GAAG,GAAG,kCAAkC,GAAG,OAAO;wBAC7D,iCAAiC,CAAC;gBACxC,CAAC;gBAAC,IAAI,CAAC,EAAE,CAAC,CAAE,KAAa,CAAC,OAAO,CAAC,CAAC,CAAC;oBACjC,KAAa,CAAC,GAAG,GAAG,+CAA+C,GAAG,OAAO,CAAC;gBACjF,CAAC;gBACD,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACJ,KAAK,CAAC,KAAK;YACV,MAAM,CAAC,KAAK,CAAE,KAAa,CAAC,GAAG,IAAK,KAAa,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACT,CAAC;CACF;AA5FD,gCA4FC"}
@@ -0,0 +1,72 @@
1
+ import { Binary, BinaryMap } from '../binaries';
2
+ import { DownloadedBinary } from './downloaded_binary';
3
+ /**
4
+ * The File Manager class is where the webdriver manager will compile a list of
5
+ * binaries that could be downloaded and get a list of previously downloaded
6
+ * file versions.
7
+ */
8
+ export declare class FileManager {
9
+ /**
10
+ * Create a directory if it does not exist.
11
+ * @param outputDir The directory to create.
12
+ */
13
+ static makeOutputDirectory(outputDir: string): void;
14
+ /**
15
+ * For the operating system, check against the list of operating systems that the
16
+ * binary is available for.
17
+ * @param osType The operating system.
18
+ * @param binary The class type to have access to the static properties.
19
+ * @returns If the binary is available for the operating system.
20
+ */
21
+ static checkOS_(osType: string, binary: typeof Binary): boolean;
22
+ /**
23
+ * For the operating system, create a list that includes the binaries
24
+ * for selenium standalone, chrome, and internet explorer.
25
+ * @param osType The operating system.
26
+ * @param alternateCDN URL of the alternative CDN to be used instead of the default ones.
27
+ * @returns A binary map that are available for the operating system.
28
+ */
29
+ static compileBinaries_(osType: string, alternateCDN?: string): BinaryMap<Binary>;
30
+ /**
31
+ * Look up the operating system and compile a list of binaries that are available
32
+ * for the system.
33
+ * @param alternateCDN URL of the alternative CDN to be used instead of the default ones.
34
+ * @returns A binary map that is available for the operating system.
35
+ */
36
+ static setupBinaries(alternateCDN?: string): BinaryMap<Binary>;
37
+ /**
38
+ * Get the list of existing files from the output directory
39
+ * @param outputDir The directory where binaries are saved
40
+ * @returns A list of existing files.
41
+ */
42
+ static getExistingFiles(outputDir: string): string[];
43
+ /**
44
+ * For the binary, operating system, and system architecture, look through
45
+ * the existing files and the downloaded binary
46
+ * @param binary The binary of interest
47
+ * @param osType The operating system.
48
+ * @param existingFiles A list of existing files.
49
+ * @returns The downloaded binary with all the versions found.
50
+ */
51
+ static downloadedVersions_<T extends Binary>(binary: T, osType: string, arch: string, existingFiles: string[]): DownloadedBinary;
52
+ /**
53
+ * Finds all the downloaded binary versions stored in the output directory.
54
+ * @param outputDir The directory where files are downloaded and stored.
55
+ * @returns An dictionary map of all the downloaded binaries found in the output folder.
56
+ */
57
+ static downloadedBinaries(outputDir: string): BinaryMap<DownloadedBinary>;
58
+ /**
59
+ * Try to download the binary version.
60
+ * @param binary The binary of interest.
61
+ * @param outputDir The directory where files are downloaded and stored.
62
+ * @returns Promise resolved to true for files downloaded, resolved to false for files not
63
+ * downloaded because they exist, rejected if there is an error.
64
+ */
65
+ static downloadFile<T extends Binary>(binary: T, outputDir: string, callback?: Function): Promise<boolean>;
66
+ /**
67
+ * Removes the existing files found in the output directory that match the
68
+ * binary prefix names.
69
+ * @param outputDir The directory where files are downloaded and stored.
70
+ */
71
+ static removeExistingFiles(outputDir: string): void;
72
+ }
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const binaries_1 = require("../binaries");
6
+ const cli_1 = require("../cli");
7
+ const config_1 = require("../config");
8
+ const downloaded_binary_1 = require("./downloaded_binary");
9
+ const downloader_1 = require("./downloader");
10
+ let logger = new cli_1.Logger('file_manager');
11
+ /**
12
+ * The File Manager class is where the webdriver manager will compile a list of
13
+ * binaries that could be downloaded and get a list of previously downloaded
14
+ * file versions.
15
+ */
16
+ class FileManager {
17
+ /**
18
+ * Create a directory if it does not exist.
19
+ * @param outputDir The directory to create.
20
+ */
21
+ static makeOutputDirectory(outputDir) {
22
+ try {
23
+ fs.statSync(outputDir);
24
+ }
25
+ catch (e) {
26
+ logger.info('creating folder ' + outputDir);
27
+ fs.mkdirSync(outputDir);
28
+ }
29
+ }
30
+ /**
31
+ * For the operating system, check against the list of operating systems that the
32
+ * binary is available for.
33
+ * @param osType The operating system.
34
+ * @param binary The class type to have access to the static properties.
35
+ * @returns If the binary is available for the operating system.
36
+ */
37
+ static checkOS_(osType, binary) {
38
+ for (let os in binary.os) {
39
+ if (binaries_1.OS[os] == osType) {
40
+ return true;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ /**
46
+ * For the operating system, create a list that includes the binaries
47
+ * for selenium standalone, chrome, and internet explorer.
48
+ * @param osType The operating system.
49
+ * @param alternateCDN URL of the alternative CDN to be used instead of the default ones.
50
+ * @returns A binary map that are available for the operating system.
51
+ */
52
+ static compileBinaries_(osType, alternateCDN) {
53
+ let binaries = {};
54
+ if (FileManager.checkOS_(osType, binaries_1.Standalone)) {
55
+ binaries[binaries_1.Standalone.id] = new binaries_1.Standalone(alternateCDN);
56
+ }
57
+ if (FileManager.checkOS_(osType, binaries_1.ChromeDriver)) {
58
+ binaries[binaries_1.ChromeDriver.id] = new binaries_1.ChromeDriver(alternateCDN);
59
+ }
60
+ if (FileManager.checkOS_(osType, binaries_1.GeckoDriver)) {
61
+ binaries[binaries_1.GeckoDriver.id] = new binaries_1.GeckoDriver(alternateCDN);
62
+ }
63
+ if (FileManager.checkOS_(osType, binaries_1.IEDriver)) {
64
+ binaries[binaries_1.IEDriver.id] = new binaries_1.IEDriver(alternateCDN);
65
+ }
66
+ if (FileManager.checkOS_(osType, binaries_1.AndroidSDK)) {
67
+ binaries[binaries_1.AndroidSDK.id] = new binaries_1.AndroidSDK(alternateCDN);
68
+ }
69
+ if (FileManager.checkOS_(osType, binaries_1.Appium)) {
70
+ binaries[binaries_1.Appium.id] = new binaries_1.Appium(alternateCDN);
71
+ }
72
+ return binaries;
73
+ }
74
+ /**
75
+ * Look up the operating system and compile a list of binaries that are available
76
+ * for the system.
77
+ * @param alternateCDN URL of the alternative CDN to be used instead of the default ones.
78
+ * @returns A binary map that is available for the operating system.
79
+ */
80
+ static setupBinaries(alternateCDN) {
81
+ return FileManager.compileBinaries_(config_1.Config.osType(), alternateCDN);
82
+ }
83
+ /**
84
+ * Get the list of existing files from the output directory
85
+ * @param outputDir The directory where binaries are saved
86
+ * @returns A list of existing files.
87
+ */
88
+ static getExistingFiles(outputDir) {
89
+ try {
90
+ return fs.readdirSync(outputDir);
91
+ }
92
+ catch (e) {
93
+ return [];
94
+ }
95
+ }
96
+ /**
97
+ * For the binary, operating system, and system architecture, look through
98
+ * the existing files and the downloaded binary
99
+ * @param binary The binary of interest
100
+ * @param osType The operating system.
101
+ * @param existingFiles A list of existing files.
102
+ * @returns The downloaded binary with all the versions found.
103
+ */
104
+ static downloadedVersions_(binary, osType, arch, existingFiles) {
105
+ let versions = [];
106
+ for (let existPos in existingFiles) {
107
+ let existFile = existingFiles[existPos];
108
+ // use only files that have a prefix and suffix that we care about
109
+ if (existFile.indexOf(binary.prefix()) === 0) {
110
+ let editExistFile = existFile.replace(binary.prefix(), '');
111
+ // if the suffix matches the executable suffix, add it
112
+ if (binary.suffix() === binary.executableSuffix()) {
113
+ versions.push(editExistFile.replace(binary.suffix(), ''));
114
+ }
115
+ else if (!existFile.endsWith('.zip') && !existFile.endsWith('.tar.gz') &&
116
+ existFile.indexOf(binary.suffix()) === -1) {
117
+ editExistFile = editExistFile.replace(binary.executableSuffix(), '');
118
+ editExistFile = editExistFile.indexOf('_') === 0 ?
119
+ editExistFile.substring(1, editExistFile.length) :
120
+ editExistFile;
121
+ versions.push(editExistFile);
122
+ }
123
+ }
124
+ }
125
+ if (versions.length === 0) {
126
+ return null;
127
+ }
128
+ let downloadedBinary = new downloaded_binary_1.DownloadedBinary(binary);
129
+ downloadedBinary.versions = versions;
130
+ return downloadedBinary;
131
+ }
132
+ /**
133
+ * Finds all the downloaded binary versions stored in the output directory.
134
+ * @param outputDir The directory where files are downloaded and stored.
135
+ * @returns An dictionary map of all the downloaded binaries found in the output folder.
136
+ */
137
+ static downloadedBinaries(outputDir) {
138
+ let ostype = config_1.Config.osType();
139
+ let arch = config_1.Config.osArch();
140
+ let binaries = FileManager.setupBinaries();
141
+ let existingFiles = FileManager.getExistingFiles(outputDir);
142
+ let downloaded = {};
143
+ for (let bin in binaries) {
144
+ let binary = FileManager.downloadedVersions_(binaries[bin], ostype, arch, existingFiles);
145
+ if (binary != null) {
146
+ downloaded[binary.id()] = binary;
147
+ }
148
+ }
149
+ return downloaded;
150
+ }
151
+ /**
152
+ * Try to download the binary version.
153
+ * @param binary The binary of interest.
154
+ * @param outputDir The directory where files are downloaded and stored.
155
+ * @returns Promise resolved to true for files downloaded, resolved to false for files not
156
+ * downloaded because they exist, rejected if there is an error.
157
+ */
158
+ static downloadFile(binary, outputDir, callback) {
159
+ return new Promise((resolve, reject) => {
160
+ let outDir = config_1.Config.getSeleniumDir();
161
+ let downloaded = FileManager.downloadedBinaries(outputDir);
162
+ let contentLength = 0;
163
+ // Pass options down to binary to make request to get the latest version to download.
164
+ binary.getUrl(binary.version()).then(fileUrl => {
165
+ binary.versionCustom = fileUrl.version;
166
+ let filePath = path.resolve(outputDir, binary.filename());
167
+ let fileName = binary.filename();
168
+ // If we have downloaded the file before, check the content length
169
+ if (downloaded[binary.id()]) {
170
+ let downloadedBinary = downloaded[binary.id()];
171
+ let versions = downloadedBinary.versions;
172
+ let version = binary.versionCustom;
173
+ for (let index in versions) {
174
+ let v = versions[index];
175
+ if (v === version) {
176
+ contentLength = fs.statSync(filePath).size;
177
+ downloader_1.Downloader.getFile(binary, fileUrl.url, fileName, outputDir, contentLength, callback)
178
+ .then(downloaded => {
179
+ resolve(downloaded);
180
+ });
181
+ }
182
+ }
183
+ }
184
+ // We have not downloaded it before, or the version does not exist. Use the default content
185
+ // length of zero and download the file.
186
+ downloader_1.Downloader.getFile(binary, fileUrl.url, fileName, outputDir, contentLength, callback)
187
+ .then(downloaded => {
188
+ resolve(downloaded);
189
+ });
190
+ });
191
+ });
192
+ }
193
+ /**
194
+ * Removes the existing files found in the output directory that match the
195
+ * binary prefix names.
196
+ * @param outputDir The directory where files are downloaded and stored.
197
+ */
198
+ static removeExistingFiles(outputDir) {
199
+ try {
200
+ fs.statSync(outputDir);
201
+ }
202
+ catch (e) {
203
+ logger.warn('path does not exist ' + outputDir);
204
+ return;
205
+ }
206
+ let existingFiles = FileManager.getExistingFiles(outputDir);
207
+ if (existingFiles.length === 0) {
208
+ logger.warn('no files found in path ' + outputDir);
209
+ return;
210
+ }
211
+ let binaries = FileManager.setupBinaries();
212
+ existingFiles.forEach((file) => {
213
+ for (let binPos in binaries) {
214
+ let bin = binaries[binPos];
215
+ if (file.indexOf(bin.prefix()) !== -1) {
216
+ bin.remove(path.resolve(outputDir, file));
217
+ logger.info('removed ' + file);
218
+ }
219
+ }
220
+ });
221
+ let metaFiles = [
222
+ 'chrome-response.xml', 'gecko-response.json', 'iedriver-response.xml',
223
+ 'standalone-response.xml', 'update-config.json'
224
+ ];
225
+ for (let metaFile of metaFiles) {
226
+ try {
227
+ let metaFilePath = path.resolve(outputDir, metaFile);
228
+ if (fs.statSync(metaFilePath)) {
229
+ fs.unlinkSync(metaFilePath);
230
+ logger.info('removed ' + metaFile);
231
+ }
232
+ }
233
+ catch (e) {
234
+ }
235
+ }
236
+ }
237
+ }
238
+ exports.FileManager = FileManager;
239
+ //# sourceMappingURL=file_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file_manager.js","sourceRoot":"","sources":["../../../lib/files/file_manager.ts"],"names":[],"mappings":";;AAAA,yBAAyB;AACzB,6BAA6B;AAG7B,0CAAuH;AACvH,gCAA8B;AAC9B,sCAAiC;AAEjC,2DAAqD;AACrD,6CAAwC;AAExC,IAAI,MAAM,GAAG,IAAI,YAAM,CAAC,cAAc,CAAC,CAAC;AAExC;;;;GAIG;AACH;IACE;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,SAAiB;QAC1C,IAAI,CAAC;YACH,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC;QAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;YAC5C,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAc,EAAE,MAAqB;QACnD,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YACzB,EAAE,CAAC,CAAC,aAAE,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC;gBACrB,MAAM,CAAC,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,MAAM,CAAC,KAAK,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAc,EAAE,YAAqB;QA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;QAC3C,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI;YACzB,GAAG,CAAC,CAAC,IAAI,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC;gBAC5B,IAAI,GAAG,GAAW,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACnC,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACtC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;oBAC1C,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;gBACjC,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,GAAG;YACd,qBAAqB,EAAE,qBAAqB,EAAE,uBAAuB;YACrE,yBAAyB,EAAE,oBAAoB;SAChD,CAAC;QACF,GAAG,CAAC,CAAC,IAAI,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC;YAC/B,IAAI,CAAC;gBACH,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBACrD,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;oBAC9B,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;YAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9OD,kCA8OC"}
@@ -0,0 +1,3 @@
1
+ export * from './downloaded_binary';
2
+ export * from './downloader';
3
+ export * from './file_manager';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ __export(require("./downloaded_binary"));
7
+ __export(require("./downloader"));
8
+ __export(require("./file_manager"));
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/files/index.ts"],"names":[],"mappings":";;;;;AAAA,yCAAoC;AACpC,kCAA6B;AAC7B,oCAA+B"}
@@ -0,0 +1,27 @@
1
+ /// <reference types="request" />
2
+ import { OptionsWithUrl } from 'request';
3
+ export interface RequestOptionsValue {
4
+ proxy?: string;
5
+ ignoreSSL?: boolean;
6
+ }
7
+ export declare class HttpUtils {
8
+ static requestOpts: RequestOptionsValue;
9
+ static assignOptions(options: RequestOptionsValue): void;
10
+ static initOptions(url: string, timeout?: number): OptionsWithUrl;
11
+ static optionsSSL(options: OptionsWithUrl, opt_ignoreSSL: boolean): OptionsWithUrl;
12
+ static optionsProxy(options: OptionsWithUrl, requestUrl: string, opt_proxy: string): OptionsWithUrl;
13
+ static optionsHeader(options: OptionsWithUrl, key: string, value: string): OptionsWithUrl;
14
+ /**
15
+ * Resolves proxy based on values set
16
+ * @param fileUrl The url to download the file.
17
+ * @param opt_proxy The proxy to connect to to download files.
18
+ * @return Either undefined or the proxy.
19
+ */
20
+ static resolveProxy(fileUrl: string, opt_proxy?: string): string;
21
+ }
22
+ /**
23
+ * Request the body from the url.
24
+ * @param requestUrl The request url.
25
+ * @returns A promise string of the response body.
26
+ */
27
+ export declare function requestBody(requestUrl: string): Promise<string>;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const request = require("@ohos-ports/request");
4
+ const url = require("url");
5
+ const logger_1 = require("./cli/logger");
6
+ const config_1 = require("./config");
7
+ let logger = new logger_1.Logger('http_utils');
8
+ class HttpUtils {
9
+ static assignOptions(options) {
10
+ Object.assign(HttpUtils.requestOpts, options);
11
+ }
12
+ static initOptions(url, timeout) {
13
+ let options = {
14
+ url: url,
15
+ // default Linux can be anywhere from 20-120 seconds
16
+ // increasing this arbitrarily to 4 minutes
17
+ timeout: 240000
18
+ };
19
+ HttpUtils.optionsSSL(options, HttpUtils.requestOpts.ignoreSSL);
20
+ HttpUtils.optionsProxy(options, url, HttpUtils.requestOpts.proxy);
21
+ return options;
22
+ }
23
+ static optionsSSL(options, opt_ignoreSSL) {
24
+ if (opt_ignoreSSL) {
25
+ logger.info('ignoring SSL certificate');
26
+ options.strictSSL = !opt_ignoreSSL;
27
+ options.rejectUnauthorized = !opt_ignoreSSL;
28
+ }
29
+ return options;
30
+ }
31
+ static optionsProxy(options, requestUrl, opt_proxy) {
32
+ if (opt_proxy) {
33
+ options.proxy = HttpUtils.resolveProxy(requestUrl, opt_proxy);
34
+ if (url.parse(requestUrl).protocol === 'https:') {
35
+ options.url = requestUrl.replace('https:', 'http:');
36
+ }
37
+ }
38
+ return options;
39
+ }
40
+ static optionsHeader(options, key, value) {
41
+ if (options.headers == null) {
42
+ options.headers = {};
43
+ }
44
+ options.headers[key] = value;
45
+ return options;
46
+ }
47
+ /**
48
+ * Resolves proxy based on values set
49
+ * @param fileUrl The url to download the file.
50
+ * @param opt_proxy The proxy to connect to to download files.
51
+ * @return Either undefined or the proxy.
52
+ */
53
+ static resolveProxy(fileUrl, opt_proxy) {
54
+ let protocol = url.parse(fileUrl).protocol;
55
+ let hostname = url.parse(fileUrl).hostname;
56
+ if (opt_proxy) {
57
+ return opt_proxy;
58
+ }
59
+ else {
60
+ // If the NO_PROXY environment variable exists and matches the host name,
61
+ // to ignore the resolve proxy.
62
+ // the checks to see if it exists and equal to empty string is to help with testing
63
+ let noProxy = config_1.Config.noProxy();
64
+ if (noProxy) {
65
+ // array of hostnames/domain names listed in the NO_PROXY environment variable
66
+ let noProxyTokens = noProxy.split(',');
67
+ // check if the fileUrl hostname part does not end with one of the
68
+ // NO_PROXY environment variable's hostnames/domain names
69
+ for (let noProxyToken of noProxyTokens) {
70
+ if (hostname.indexOf(noProxyToken) !== -1) {
71
+ return undefined;
72
+ }
73
+ }
74
+ }
75
+ // If the HTTPS_PROXY and HTTP_PROXY environment variable is set, use that as the proxy
76
+ if (protocol === 'https:') {
77
+ return config_1.Config.httpsProxy() || config_1.Config.httpProxy();
78
+ }
79
+ else if (protocol === 'http:') {
80
+ return config_1.Config.httpProxy();
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+ }
86
+ HttpUtils.requestOpts = {};
87
+ exports.HttpUtils = HttpUtils;
88
+ /**
89
+ * Request the body from the url.
90
+ * @param requestUrl The request url.
91
+ * @returns A promise string of the response body.
92
+ */
93
+ function requestBody(requestUrl) {
94
+ const options = HttpUtils.initOptions(requestUrl);
95
+ options.followRedirect = true;
96
+ return new Promise((resolve, reject) => {
97
+ const req = request(options);
98
+ req.on('response', response => {
99
+ if (response.statusCode === 200) {
100
+ let output = '';
101
+ response.on('data', (data) => {
102
+ output += data;
103
+ });
104
+ response.on('end', () => {
105
+ resolve(output);
106
+ });
107
+ }
108
+ else {
109
+ reject(new Error('response status code is not 200'));
110
+ }
111
+ });
112
+ req.on('error', error => {
113
+ reject(error);
114
+ });
115
+ });
116
+ }
117
+ exports.requestBody = requestBody;
118
+ //# sourceMappingURL=http_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http_utils.js","sourceRoot":"","sources":["../../lib/http_utils.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAEnC,2BAA2B;AAE3B,yCAAoC;AACpC,qCAAgC;AAEhC,IAAI,MAAM,GAAG,IAAI,eAAM,CAAC,YAAY,CAAC,CAAC;AAOtC;IAEE,MAAM,CAAC,aAAa,CAAC,OAA4B;QAC/C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAW,EAAE,OAAgB;QAC9C,IAAI,OAAO,GAAmB;YAC5B,GAAG,EAAE,GAAG;YAC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AC;QACH,CAAC;QACD,MAAM,CAAC,SAAS,CAAC;IACnB,CAAC;;AAnFM,qBAAW,GAAwB,EAAE,CAAC;AAD/C,8BAqFC;AAED;;;;GAIG;AACH,qBAA4B,UAAkB;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAClD,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAC9B,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;QACjC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7B,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,QAAQ;YACzB,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC;gBAChC,IAAI,MAAM,GAAG,EAAE,CAAC;gBAChB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI;oBACvB,MAAM,IAAI,IAAI,CAAC;gBACjB,CAAC,CAAC,CAAC;gBACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;oBACjB,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,IAAI,CAAC,CAAC;gBACN,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC,CAAC;YACvD,CAAC;QACH,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK;YACnB,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAtBD,kCAsBC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import * as child_process from 'child_process';
3
+ export declare let spawn: (cmd: string, args: string[], stdio?: any, opts?: child_process.SpawnOptions) => child_process.ChildProcess;
4
+ export declare let spawnSync: (cmd: string, args: string[], stdio?: any, opts?: child_process.SpawnSyncOptions) => child_process.SpawnSyncReturns<any>;
5
+ export declare function request(method: string, port: string, path: string, timeout?: number, data?: any): Promise<string>;
6
+ export declare function adb(sdkPath: string, port: number, command: string, timeout: number, args?: string[]): Promise<string>;