1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const Downloader = require('./utils/ChromiumDownloader');
|
18 | const revision = require('./package').puppeteer.chromium_revision;
|
19 | const ProgressBar = require('progress');
|
20 |
|
21 |
|
22 | if (Downloader.revisionInfo(Downloader.currentPlatform(), revision))
|
23 | return;
|
24 |
|
25 | let allRevisions = Downloader.downloadedRevisions();
|
26 | Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress)
|
27 |
|
28 | .then(() => Promise.all(allRevisions.map(({platform, revision}) => Downloader.removeRevision(platform, revision))))
|
29 | .catch(error => console.error('Download failed: ' + error.message));
|
30 |
|
31 | let progressBar = null;
|
32 | function onProgress(bytesTotal, delta) {
|
33 | if (!progressBar) {
|
34 | progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(bytesTotal)} [:bar] :percent :etas `, {
|
35 | complete: '=',
|
36 | incomplete: ' ',
|
37 | width: 20,
|
38 | total: bytesTotal,
|
39 | });
|
40 | }
|
41 | progressBar.tick(delta);
|
42 | }
|
43 |
|
44 | function toMegabytes(bytes) {
|
45 | let mb = bytes / 1024 / 1024;
|
46 | return (Math.round(mb * 10) / 10) + ' Mb';
|
47 | }
|
48 |
|