-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Angel
authored and
Angel
committed
Oct 20, 2017
0 parents
commit d96c77b
Showing
7 changed files
with
538 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# IDEA folders | ||
.idea/ | ||
|
||
# Chromium binaries output folder | ||
/lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
BIN_OUT_PATH: path.join(__dirname, 'lib', 'chromium') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const config = require('./config'); | ||
const utils = require('./utils'); | ||
|
||
const fs = require('fs'); | ||
|
||
function getBinaryPath() { | ||
const path = utils.getOsChromiumBinPath(); | ||
|
||
console.log('Chromiu: ', path); | ||
|
||
if (fs.existsSync(path)) { | ||
return path; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
module.exports = { | ||
path: getBinaryPath() | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
'use strict'; | ||
|
||
const config = require('./config'); | ||
const utils = require('./utils'); | ||
|
||
const extractZip = require('extract-zip'); | ||
const got = require('got'); | ||
const tmp = require('tmp'); | ||
const fs = require('fs'); | ||
|
||
const CDN_URL = 'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/'; | ||
|
||
|
||
function getOsCdnUrl() { | ||
let url = CDN_URL; | ||
|
||
const platform = process.platform; | ||
|
||
if (platform === 'linux') { | ||
url += 'Linux'; | ||
if (process.arch === 'x64') { | ||
url += '_x64'; | ||
} | ||
} else if (platform === 'win32') { | ||
url += 'Win'; | ||
if (process.arch === 'x64') { | ||
url += '_x64'; | ||
} | ||
} else if (platform === 'darwin') { | ||
url += 'Mac'; | ||
} else { | ||
console.log('Unknown platform or architecture found:', process.platform, process.arch); | ||
process.exit(1); | ||
} | ||
|
||
return url; | ||
} | ||
|
||
function getLatestRevisionNumber() { | ||
return new Promise((resolve, reject) => { | ||
const url = getOsCdnUrl() + '%2FLAST_CHANGE?alt=media'; | ||
got(url) | ||
.then(response => { | ||
resolve(response.body); | ||
}) | ||
.catch(error => { | ||
console.log('An error occured while trying to retrieve latest revision number', error); | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
function createTempFile() { | ||
return new Promise((resolve, reject) => { | ||
tmp.file((error, path, fd) => { | ||
if (error) { | ||
console.log('An error occured while trying to create temporary file', error); | ||
reject(error); | ||
} else { | ||
resolve(path); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function downloadChromiumRevision(revision) { | ||
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'; | ||
got.stream(url) | ||
.on('error', (error, body, response) => { | ||
console.log('An error occurred while trying to download Chromium archive', error); | ||
reject(error); | ||
}) | ||
.pipe(fs.createWriteStream(path)) | ||
.on('error', error => { | ||
console.log('An error occurred while trying to save Chromium archive to disk', error); | ||
reject(error); | ||
}) | ||
.on('finish', () => { | ||
resolve(path); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function unzipArchive(archivePath, outputFolder) { | ||
console.log('Started extracting archive', archivePath); | ||
return new Promise((resolve, reject) => { | ||
extractZip(archivePath, { dir: outputFolder }, error => { | ||
if (error) { | ||
console.log('An error occurred while trying to extract archive', error); | ||
reject(error); | ||
} else { | ||
console.log('Archive was successfully extracted'); | ||
resolve(true); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
getLatestRevisionNumber() | ||
.then(downloadChromiumRevision) | ||
.then(path => unzipArchive(path, config.BIN_OUT_PATH)) | ||
.catch(error => console.error('An error occurred while trying to setup Chromium. Resolve all issues and restart the process', error)); |
Oops, something went wrong.