@@ -12,8 +12,8 @@ import {
12
12
sep ,
13
13
} from 'path' ;
14
14
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' ;
17
17
18
18
const __filename = fileURLToPath (
19
19
import . meta. url ) ;
@@ -92,53 +92,35 @@ function retrieve(path = {
92
92
dest : ''
93
93
} ) {
94
94
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
+ } ) ;
100
102
}
101
103
102
104
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 ( {
107
107
url : platformData . url + platformData . filename ,
108
108
dest : platformData . source
109
109
} ) . then ( ( ) => {
110
110
console . log ( 'Extracting: ' + platformData . filename ) ;
111
- if ( fetching . isString ( platformData . platform ) ) {
111
+ if ( isString ( platformData . platform ) ) {
112
112
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 )
114
116
return resolve ( platformData . platform ) ;
115
117
} )
116
- . catch ( ( err ) => retry ( err ) ) ;
118
+ . catch ( ( err ) => reject ( err ) ) ;
117
119
}
118
- } ) . catch ( ( err ) => retry ( err ) ) ;
120
+ } ) . catch ( ( err ) => reject ( err ) ) ;
119
121
} ) . catch ( ( err ) => console . error ( err ) ) ;
120
122
}
121
123
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
-
142
124
function extraUnpack ( cmd = '' , source = '' , destination = '' , toCopy = [ ] ) {
143
125
let args = [ 'e' , source , '-o' + destination ] ;
144
126
let extraArgs = args . concat ( toCopy ) . concat ( [ '-r' , '-aos' ] ) ;
@@ -170,97 +152,19 @@ function makeExecutable(binary = [], binaryFolder = '') {
170
152
} ) ;
171
153
}
172
154
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
-
251
155
let extractionPromises = [ ] ;
252
156
let platforms = [ linuxPlatform , appleMacPlatform , windowsOtherPlatform ] ;
253
157
if ( process . platform == 'win32' )
254
158
platforms = [ linuxPlatform , appleMacPlatform , windowsPlatform , windowsOtherPlatform ] ;
255
159
256
160
platforms . forEach ( ( dataFor ) => {
257
161
fs . mkdir ( dataFor . destination , ( err ) => {
258
- if ( err ) { }
162
+ if ( err ) { }
259
163
} ) ;
260
164
const extracted = retrieve ( {
261
- url : _7zAppUrl + dataFor . extraName ,
262
- dest : dataFor . extraSourceFile
263
- } )
165
+ url : _7zAppUrl + dataFor . extraName ,
166
+ dest : dataFor . extraSourceFile
167
+ } )
264
168
. then ( ( ) => {
265
169
return platformUnpacker ( dataFor )
266
170
. then ( ( ) => {
0 commit comments