Skip to content

Commit 79ad2c3

Browse files
committed
chore: switch away to download
Signed-off-by: Jakub Mucha <[email protected]>
1 parent 190ffb2 commit 79ad2c3

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

helpers.js

+7-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const axios = require('axios');
2-
const zip = require('cross-zip');
32
const fs = require('fs').promises;
43
const path = require('path');
4+
const download = require('download');
55
const packageJson = require('./package.json');
6-
const { pipeline } = require('stream/promises');
76

87
let networkName = 'mainnet';
98
let networkId = 1;
@@ -92,25 +91,9 @@ module.exports = {
9291
},
9392
download: async (url, destination) => {
9493
try {
95-
const writer = await pipeline(fs.createWriteStream(destination));
96-
const result = await axios({
97-
url,
98-
method: 'GET',
99-
responseType: 'stream',
100-
});
101-
await new Promise(resolve =>
102-
result.data.pipe(writer).on('finish', resolve),
103-
);
104-
} catch (e) {
105-
throw new Error(
106-
`[download] Unable to download metamask release from: ${url} to: ${destination}`,
107-
e,
108-
);
109-
}
110-
},
111-
extract: async (file, destination) => {
112-
try {
113-
await zip.unzip(file, destination);
94+
// todo: check if zip file exists, if yes then remove it before
95+
// todo: if directory exists, dont overwrite
96+
await download(url, destination, { extract: true });
11497
} catch (e) {
11598
throw new Error(
11699
`[download] Unable to download metamask release from: ${url} to: ${destination} with following error:\n${e}`,
@@ -120,13 +103,9 @@ module.exports = {
120103
prepareMetamask: async version => {
121104
const release = await module.exports.getMetamaskReleases(version);
122105
const downloadsDirectory = path.resolve(__dirname, 'downloads');
123-
if (!fs.existsSync(downloadsDirectory)) {
124-
fs.mkdirSync(downloadsDirectory);
125-
}
126-
const downloadDestination = path.join(downloadsDirectory, release.filename);
127-
await module.exports.download(release.downloadUrl, downloadDestination);
128-
const metamaskDirectory = path.join(downloadsDirectory, 'metamask');
129-
await module.exports.extract(downloadDestination, metamaskDirectory);
106+
await module.exports.dirExists(downloadsDirectory);
107+
const metamaskDirectory = path.join(downloadsDirectory, release.tagName);
108+
await module.exports.download(release.downloadUrl, metamaskDirectory);
130109
return metamaskDirectory;
131110
},
132111
};

0 commit comments

Comments
 (0)