Skip to content

Commit 592db53

Browse files
committed
revert other revert, removed all-unpacker with node-unar, corrections, remove unneeded code, retry now part of node-wget-fetch
1 parent 2e72bf5 commit 592db53

File tree

3 files changed

+172
-225
lines changed

3 files changed

+172
-225
lines changed

installer.mjs

Lines changed: 21 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
sep,
1313
} from 'path';
1414
import spawn from 'cross-spawn';
15-
import unCompress from 'all-unpacker';
16-
import fetching from 'node-wget-fetch';
15+
import { unpack } from 'node-unar';
16+
import { wget, isString } from 'node-wget-fetch';
1717

1818
const __filename = fileURLToPath(
1919
import.meta.url);
@@ -92,53 +92,35 @@ function retrieve(path = {
9292
dest: ''
9393
}) {
9494
console.log('Downloading ' + path.url);
95-
return new Promise((resolve, reject) => {
96-
fetching.wget(path.url, path.dest)
97-
.then((info) => resolve(info))
98-
.catch((err) => reject('Error downloading file: ' + err));
99-
});
95+
return wget(path.url, path.dest, { retry: { retries: 5 } })
96+
.then((info) => {
97+
return info;
98+
})
99+
.catch((err) => {
100+
throw ('Error downloading file: ' + err);
101+
});
100102
}
101103

102104
function platformUnpacker(platformData = windowsPlatform) {
103-
return new retryPromise({
104-
retries: 5
105-
}, (resolve, retry) => {
106-
return retrieve({
105+
return new Promise((resolve, reject) => {
106+
retrieve({
107107
url: platformData.url + platformData.filename,
108108
dest: platformData.source
109109
}).then(() => {
110110
console.log('Extracting: ' + platformData.filename);
111-
if (fetching.isString(platformData.platform)) {
111+
if (isString(platformData.platform)) {
112112
unpack(platformData.source, platformData.destination)
113-
.then(() => {
113+
.then((results) => {
114+
console.log('Archive of type: ' + results.type)
115+
console.log('Successfully extracted to: ' + results.directory)
114116
return resolve(platformData.platform);
115117
})
116-
.catch((err) => retry(err));
118+
.catch((err) => reject(err));
117119
}
118-
}).catch((err) => retry(err));
120+
}).catch((err) => reject(err));
119121
}).catch((err) => console.error(err));
120122
}
121123

122-
function unpack(source, destination, toCopy) {
123-
return new Promise((resolve, reject) => {
124-
return unCompress.unpack(
125-
source, {
126-
files: (toCopy == null ? '' : toCopy),
127-
targetDir: destination,
128-
forceOverwrite: true,
129-
noDirectory: true,
130-
quiet: true,
131-
},
132-
(err, files, text) => {
133-
if (err)
134-
return reject(err);
135-
console.log(text);
136-
return resolve(files);
137-
}
138-
);
139-
});
140-
}
141-
142124
function extraUnpack(cmd = '', source = '', destination = '', toCopy = []) {
143125
let args = ['e', source, '-o' + destination];
144126
let extraArgs = args.concat(toCopy).concat(['-r', '-aos']);
@@ -170,97 +152,19 @@ function makeExecutable(binary = [], binaryFolder = '') {
170152
});
171153
}
172154

173-
/**
174-
* Returns a promise that conditionally tries to resolve multiple times, as specified by the retry
175-
* policy.
176-
* @param {retryPolicy} [options] - Either An object that specifies the retry policy.
177-
* @param {retryExecutor} executor - A function that is called for each attempt to resolve the promise.
178-
* @returns {Promise}
179-
*
180-
* @see https://github.com/wouter-vdb/retrying-promise
181-
*/
182-
function retryPromise(options, executor) {
183-
if (executor == undefined) {
184-
executor = options;
185-
options = {};
186-
}
187-
188-
var opts = prepOpts(options);
189-
var attempts = 1;
190-
191-
return new Promise((resolve, reject) => {
192-
let retrying = false;
193-
194-
function retry(err) {
195-
if (retrying) return;
196-
retrying = true;
197-
if (attempts < opts.retries) {
198-
setTimeout(() => {
199-
attempts++;
200-
retrying = false;
201-
executor(resolve, retry, reject, attempts);
202-
}, createTimeout(attempts, opts));
203-
} else {
204-
//console.log(attempts, opts.retries);
205-
reject(err);
206-
}
207-
}
208-
209-
executor(resolve, retry, reject, attempts);
210-
});
211-
}
212-
213-
/*
214-
* Preps the options object, initializing default values and checking constraints.
215-
* @param {Object} options - The options as provided to `retryingPromise`.
216-
*/
217-
function prepOpts(options) {
218-
var opts = {
219-
retries: 10,
220-
factor: 2,
221-
minTimeout: 1000,
222-
maxTimeout: Infinity,
223-
randomize: false
224-
};
225-
for (var key in options) {
226-
opts[key] = options[key];
227-
}
228-
229-
if (opts.minTimeout > opts.maxTimeout) {
230-
throw new Error('minTimeout is greater than maxTimeout');
231-
}
232-
233-
return opts;
234-
}
235-
236-
/**
237-
* Get a timeout value in milliseconds.
238-
* @param {number} attempt - The attempt count.
239-
* @param {Object} opts - The options.
240-
* @returns {number} The timeout value in milliseconds.
241-
*/
242-
function createTimeout(attempt, opts) {
243-
var random = opts.randomize ? Math.random() + 1 : 1;
244-
245-
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
246-
timeout = Math.min(timeout, opts.maxTimeout);
247-
248-
return timeout;
249-
}
250-
251155
let extractionPromises = [];
252156
let platforms = [linuxPlatform, appleMacPlatform, windowsOtherPlatform];
253157
if (process.platform == 'win32')
254158
platforms = [linuxPlatform, appleMacPlatform, windowsPlatform, windowsOtherPlatform];
255159

256160
platforms.forEach((dataFor) => {
257161
fs.mkdir(dataFor.destination, (err) => {
258-
if (err) {}
162+
if (err) { }
259163
});
260164
const extracted = retrieve({
261-
url: _7zAppUrl + dataFor.extraName,
262-
dest: dataFor.extraSourceFile
263-
})
165+
url: _7zAppUrl + dataFor.extraName,
166+
dest: dataFor.extraSourceFile
167+
})
264168
.then(() => {
265169
return platformUnpacker(dataFor)
266170
.then(() => {

package-lock.json

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

0 commit comments

Comments
 (0)