Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,32 @@ const got = require('got');
const tmp = require('tmp');

const config = require('./config');
const utils = require('./utils');

const CDN_URL = 'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/';
const CDN_URL = 'https://download-chromium.appspot.com/dl/OS_TYPE?type=snapshots';

function getOsCdnUrl() {
let url = CDN_URL;
let osType = '';

const platform = process.platform;

if (platform === 'linux') {
url += 'Linux';
osType += 'Linux';
if (process.arch === 'x64') {
url += '_x64';
osType += '_x64';
}
} else if (platform === 'win32') {
url += 'Win';
osType += 'Win';
if (process.arch === 'x64') {
url += '_x64';
osType += '_x64';
}
} else if (platform === 'darwin') {
url += 'Mac';
osType += 'Mac';
} else {
console.log('Unknown platform or architecture found:', process.platform, process.arch);
throw new Error('Unsupported platform');
}

return url;
}

function getLatestRevisionNumber() {
return new Promise((resolve, reject) => {
const url = getOsCdnUrl() + '%2FLAST_CHANGE?alt=media';
got(url)
.then(response => {
resolve(response.body);
})
.catch(err => {
console.log('An error occured while trying to retrieve latest revision number', err);
reject(err);
});
});
return CDN_URL.replace(/OS_TYPE/, osType);
}

function createTempFile() {
Expand All @@ -62,12 +47,12 @@ function createTempFile() {
});
}

function downloadChromiumRevision(revision) {
function downloadChromium() {
return new Promise((resolve, reject) => {
createTempFile()
.then(path => {
console.log('Downloading Chromium archive from Google CDN');
const url = getOsCdnUrl() + `%2F${revision}%2F` + utils.getOsChromiumFolderName() + '.zip?alt=media';
const url = getOsCdnUrl();
got.stream(url)
.on('error', error => {
console.log('An error occurred while trying to download Chromium archive', error);
Expand Down Expand Up @@ -100,8 +85,7 @@ function unzipArchive(archivePath, outputFolder) {
});
}

module.exports = getLatestRevisionNumber()
.then(downloadChromiumRevision)
module.exports = downloadChromium()
.then(path => unzipArchive(path, config.BIN_OUT_PATH))
.catch(err => console.error('An error occurred while trying to setup Chromium. Resolve all issues and restart the process', err));