forked from dtolstyi/node-chromium
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.js
73 lines (61 loc) · 2.34 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const path = require('path');
const config = require('./config');
module.exports = {
getOsChromiumBinPath() {
const platform = process.platform;
let chromiumFolderNamePostfix = platform;
if (platform === 'darwin') {
chromiumFolderNamePostfix = 'mac';
} else if (platform === 'win32') {
chromiumFolderNamePostfix = 'win';
}
const chromiumFolderName = `chrome-${chromiumFolderNamePostfix}`;
let binPath = path.join(config.BIN_OUT_PATH, chromiumFolderName);
if (platform === 'linux') {
binPath = path.join(binPath, 'chrome');
} else if (platform === 'win32') {
binPath = path.join(binPath, 'chrome.exe');
} else if (platform === 'darwin') {
binPath = path.join(binPath, 'Chromium.app/Contents/MacOS/Chromium');
} else {
console.error('Unsupported platform or architecture found:', process.platform, process.arch);
throw new Error('Unsupported platform');
}
return binPath;
},
getOsCdnUrls(params) {
const platform = params.platform;
const architecture = params.architecture;
const revision = params.revision;
let urlOsName;
if (platform === 'linux') {
urlOsName = 'Linux';
if (architecture === 'x64') {
urlOsName += '_x64';
}
} else if (platform === 'win32') {
urlOsName = 'Win';
if (architecture === 'x64') {
urlOsName += '_x64';
}
} else if (platform === 'darwin') {
urlOsName = 'Mac';
} else {
console.log('Unknown platform or architecture found:', platform, architecture);
throw new Error('Unsupported platform');
}
const urlOsPostfixes = [];
if (platform === 'linux') {
urlOsPostfixes.push(platform);
} else if (platform === 'win32') {
urlOsPostfixes.push(platform, 'win');
} else {
urlOsPostfixes.push('mac');
}
const urls = urlOsPostfixes.map(urlOsPostfix => {
return `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/${urlOsName}%2F${revision}%2Fchrome-${urlOsPostfix}.zip?alt=media`;
});
return urls;
}
};