Skip to content

Commit e0a663b

Browse files
committed
replace download with alternate package
1 parent 387f5af commit e0a663b

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
"axios": "^1.1.2",
4747
"boxen": "5.1.2",
4848
"cli-progress": "^3.11.2",
49+
"decompress": "^4.2.1",
4950
"dotenv": "^16.0.3",
5051
"download": "^8.0.0",
5152
"inquirer": "^8.2.4",
5253
"minimist": "^1.2.6",
54+
"node-downloader-helper": "^2.1.6",
5355
"untildify": "^4.0.0",
5456
"which": "^2.0.2"
5557
}

src/commands/android/utils/common.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import colors from 'ansi-colors';
22
import axios, {AxiosResponse} from 'axios';
33
import cliProgress from 'cli-progress';
4-
import download from 'download';
4+
import decompress from 'decompress';
5+
import {DownloaderHelper} from 'node-downloader-helper';
56
import fs from 'fs';
67
import os from 'os';
78
import path from 'path';
@@ -92,28 +93,39 @@ export const getBinaryLocation = (sdkRoot: string, platform: Platform, binaryNam
9293
return '';
9394
};
9495

95-
export const downloadWithProgressBar = async (url: string, dest: string, extract = false) => {
96+
export const downloadWithProgressBar = async (url: string, dest: string, extract=false) => {
97+
const absoluteFolderPath = path.resolve(dest);
98+
99+
if (!fs.existsSync(absoluteFolderPath)) {
100+
fs.mkdirSync(absoluteFolderPath, { recursive: true });
101+
}
102+
96103
const progressBar = new cliProgress.Bar({
97104
format: ' [{bar}] {percentage}% | ETA: {eta}s'
98105
}, cliProgress.Presets.shades_classic);
99106

100-
try {
101-
const stream = download(url, dest, {
102-
extract
103-
});
104-
progressBar.start(100, 0);
105-
106-
await stream.on('downloadProgress', function(progress) {
107-
progressBar.update(progress.percent*100);
108-
});
109-
progressBar.stop();
110-
111-
return true;
112-
} catch {
107+
const downloader = new DownloaderHelper(url, dest, {override: {skip: true}});
108+
109+
downloader.on('start', () => progressBar.start(100, 0));
110+
downloader.on('progress', (stats) => {
111+
progressBar.update(stats.progress);
112+
});
113+
downloader.on('end', (downloadInfo) => {
114+
console.log(downloadInfo);
115+
if (extract) {
116+
decompress(downloadInfo.filePath, dest).then(() => {
117+
fs.unlink(downloadInfo.filePath, (err) => {
118+
if (err) {
119+
console.log(`Please delete the zip file at: ${downloadInfo.filePath}.`);
120+
}
121+
})
122+
});
123+
}
113124
progressBar.stop();
125+
});
126+
downloader.on('error', () => progressBar.stop());
114127

115-
return false;
116-
}
128+
return await downloader.start();
117129
};
118130

119131
export const getLatestVersion = async (browser: 'firefox' | 'chrome'): Promise<string> => {

0 commit comments

Comments
 (0)