Skip to content

Commit cd8fc2d

Browse files
authored
chrome(chromium): add Windows support for chromium (#402)
1 parent e2c7d2b commit cd8fc2d

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/provider/chromium.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
4747
* Step 1: Download the json file that contains all the releases by OS. Each
4848
* OS will have a list of release versions. The requested body will also be
4949
* written to the out directory.
50-
*
50+
*
5151
* The requested url is https://omahaproxy.appspot.com/all.json. Some other
5252
* urls include a timestamped csv https://omahaproxy.appspot.com/history.
5353
* @return Promise of the all-json file.
@@ -60,7 +60,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
6060
this.makeDirectory(fileName);
6161
const httpOptions = { fileName, ignoreSSL: this.ignoreSSL,
6262
proxy: this.proxy };
63-
63+
6464
if (isExpired(fileName)) {
6565
const allJsonUrl = 'https://omahaproxy.appspot.com/all.json';
6666
let contents = await requestBody(allJsonUrl, httpOptions);
@@ -79,7 +79,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
7979
* Step 2: From the all-json object, make a request that matches the major
8080
* version requested. The requested body will also be written to file in the
8181
* out directory.
82-
*
82+
*
8383
* An example of a requsted url is
8484
* https://omahaproxy.appspot.com/deps.json?version=72.0.3626.81
8585
* @param allJson The all-json object.
@@ -109,11 +109,11 @@ export class Chromium extends ProviderClass implements ProviderInterface {
109109
}
110110

111111
let workingFullVersion = '';
112-
let workingSemanticVersion = '0.0.0';
113-
for (let item of all) {
112+
const workingSemanticVersion = '0.0.0';
113+
for (const item of all) {
114114
if (item['os'] === os) {
115115
const versions = item['versions'];
116-
for (let version of versions) {
116+
for (const version of versions) {
117117
const fullVersion = version['current_version'];
118118
const major = fullVersion.split('.')[0];
119119
const minor = fullVersion.split('.')[1];
@@ -145,11 +145,11 @@ export class Chromium extends ProviderClass implements ProviderInterface {
145145
* This is the "chromium_base_position" and make a request to the storage
146146
* bucket. If the returned value is {"kind": "storage#objects"}, then
147147
* decrement the revision number.
148-
*
148+
*
149149
* An example is the chromium_base_position revision number (612437).
150150
* https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o?delimiter=/&prefix=Linux_x64/612437/
151151
* returns {"kind": "storage#objects"}.
152-
*
152+
*
153153
* We keep decrementing the number until we reach 612434 where there is a list
154154
* of items.
155155
* @param downloadJson The download-version-json object.
@@ -181,7 +181,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
181181
}
182182
revisionUrl += os + '/';
183183
let chromiumBasePosition: number = downloadJson['chromium_base_position'];
184-
184+
185185
const httpOptions = { fileName, ignoreSSL: this.ignoreSSL,
186186
proxy: this.proxy };
187187
while(chromiumBasePosition > 0) {
@@ -203,23 +203,23 @@ export class Chromium extends ProviderClass implements ProviderInterface {
203203
* Step 4: Get the download url for the chromium zip. Unzipping the zip file
204204
* directory. The folders and binaries uncompressed are different for each OS.
205205
* The following is examples of each OS:
206-
*
206+
*
207207
* downloads/
208208
* |- chrome-linux/chrome
209209
* |- chrome-mac/Chromium.app
210210
* |- chrome-win/chrome.exe
211-
*
211+
*
212212
* @param storageObject The download-storage-json object
213213
* @param majorVersion The major version, this must be a whole number.
214214
*/
215215
async downloadUrl(storageObject: JsonObject, majorVersion: string
216216
): Promise<void> {
217-
const fileName = path.resolve(this.outDir,
217+
const fileName = path.resolve(this.outDir,
218218
this.compressedBinaryFileName.replace('.zip', `-${majorVersion}.zip`));
219219
if (isExpired(fileName)) {
220220
const httpOptions = { fileName, ignoreSSL: this.ignoreSSL,
221221
proxy: this.proxy };
222-
for (let item of storageObject['items'] as JsonObject[]) {
222+
for (const item of storageObject['items'] as JsonObject[]) {
223223
const name: string = item['name'];
224224
if (name.indexOf('chrome') >= 0) {
225225
const downloadUrl = item['mediaLink'];
@@ -253,41 +253,41 @@ export class Chromium extends ProviderClass implements ProviderInterface {
253253
downloadVersionJson, majorVersion);
254254
await this.downloadUrl(storageObject, majorVersion);
255255

256-
let binaryFolder = (): string => {
256+
const binaryFolder = (): string => {
257257
if (this.osType === 'Linux') {
258258
return path.resolve(this.outDir, 'chrome-linux');
259259
} else if (this.osType === 'Darwin') {
260260
return path.resolve(this.outDir,
261261
'chrome-mac/Chromium.app/Contents/MacOS');
262262
} else if (this.osType === 'Windows_NT') {
263-
return 'fix me';
263+
return path.resolve(this.outDir, 'chrome-win');
264264
}
265265
throw new Error('os does not exist');
266-
}
266+
};
267267

268-
let binaryRegex = (): RegExp => {
268+
const binaryRegex = (): RegExp => {
269269
if (this.osType === 'Linux') {
270270
return /chrome$/g;
271271
} else if (this.osType === 'Darwin') {
272272
return /Chromium/g;
273273
} else if (this.osType === 'Windows_NT') {
274-
return /fix-me/g;
274+
return /chrome\.exe/g;
275275
}
276276
throw new Error('os does not exist');
277277
};
278278

279-
let binaryFile = (): string => {
279+
const binaryFile = (): string => {
280280
if (this.osType === 'Linux') {
281281
return path.resolve(this.outDir, 'chrome-linux/chrome');
282282
} else if (this.osType === 'Darwin') {
283283
return path.resolve(this.outDir,
284284
'chrome-mac/Chromium.app/Contents/MacOS/Chromium');
285285
} else if (this.osType === 'Windows_NT') {
286-
return 'fix me';
286+
return 'chrome-win/chrome.exe';
287287
}
288288
throw new Error('os does not exist');
289-
}
290-
289+
};
290+
291291
generateConfigFile(binaryFolder(),
292292
path.resolve(this.outDir, this.configFileName),
293293
binaryRegex(), binaryFile());
@@ -310,7 +310,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
310310
const regex = /chromium\-version\-(\d+)\.json/g;
311311
const exec = regex.exec(existFile);
312312
if (exec) {
313-
return exec[1];
313+
return exec[1];
314314
}
315315
}
316316
}
@@ -329,7 +329,7 @@ export class Chromium extends ProviderClass implements ProviderInterface {
329329
} else if (this.osType === 'Windows_NT') {
330330
chromiumPath = 'chrome-win/';
331331
}
332-
332+
333333
rimraf.sync(path.resolve(this.outDir, chromiumPath));
334334
const files = removeFiles(this.outDir, [/chromium.*/g]);
335335
try {

0 commit comments

Comments
 (0)