@@ -133,14 +133,18 @@ export function createSfx(
133
133
reject : ( err : string ) => void ,
134
134
progress : ( data : any ) => any
135
135
) {
136
- let directory =
137
- destination != '' && fs . existsSync ( destination )
138
- ? destination
139
- : getPath ( 'when' ) ;
136
+ let directory = undefined ;
137
+ if ( destination && fs . existsSync ( destination ) )
138
+ directory = destination ;
139
+ else {
140
+ const whenPath = getPath ( 'when' ) ;
141
+ if ( ! whenPath ) return reject ( 'Path not found!' ) ;
142
+ directory = whenPath ;
143
+ }
144
+
140
145
let SfxDirectory = join ( directory , 'SfxPackages' ) ;
141
146
fs . ensureDirSync ( SfxDirectory ) ;
142
- let override =
143
- isWindows ( ) && ( platform == 'linux' || platform == 'darwin' ) ;
147
+ const override = isWindows ( ) && [ 'linux' , 'darwin' ] . includes ( platform ) ;
144
148
let binaryDirectory = Binary ( override ) ;
145
149
let configFile = join ( binaryDirectory . path , 'config.txt' ) ;
146
150
//let configFile = join(SfxDirectory, 'config.txt');
@@ -166,24 +170,29 @@ export function createSfx(
166
170
if ( text ) config . write ( 'ExecuteParameters=' + text + '\n' ) ;
167
171
config . write ( ';!@InstallEnd@!' + '\n' ) ;
168
172
config . close ( ) ;
169
- delete options . title ;
170
- delete options . prompt ;
171
- delete options . beginPrompt ;
172
- delete options . progress ;
173
- delete options . run ;
174
- delete options . runProgram ;
175
- delete options . directory ;
176
- delete options . execute ;
177
- delete options . executeFile ;
178
- delete options . parameters ;
179
- delete options . executeParameters ;
180
- let sfxModule =
181
- type == 'gui' ? '7zwin32.sfx' : '7zCon' + platform + '.sfx' ;
182
- let sfx = name . includes ( extension ) ? name : name + extension ;
183
- let list = Array . isArray ( files )
184
- ? [ configFile ] . concat ( files )
185
- : configFile + ' ' + files ;
186
- sfx = join ( SfxDirectory , sfx ) ;
173
+ [
174
+ 'title' ,
175
+ 'prompt' ,
176
+ 'beginPrompt' ,
177
+ 'progress' ,
178
+ 'run' ,
179
+ 'runProgram' ,
180
+ 'directory' ,
181
+ 'execute' ,
182
+ 'executeFile' ,
183
+ 'parameters' ,
184
+ 'executeParameters'
185
+ ] . forEach ( ( name ) => delete options [ name ] ) ;
186
+ const sfxModule = type === 'gui'
187
+ ? '7zwin32.sfx'
188
+ : `7zCon${ platform } .sfx` ;
189
+ const sfxFilename = name . includes ( extension )
190
+ ? name
191
+ : name + extension ;
192
+ const sfx = join ( SfxDirectory , sfxFilename ) ;
193
+ let list = Array . isArray ( files )
194
+ ? [ configFile , ...files ]
195
+ : `${ configFile } ${ files } ` ;
187
196
let params = Object . assign ( options , {
188
197
sfx : sfxModule ,
189
198
} ) ;
@@ -198,12 +207,10 @@ export function createSfx(
198
207
if ( fs . existsSync ( sfx ) ) {
199
208
return resolve ( sfx ) ;
200
209
/* c8 ignore next 4 */
201
- } else {
202
- console . error ( data ) ;
203
- return reject (
204
- 'Failed! The Sfx application could not be created!'
205
- ) ;
206
- }
210
+ }
211
+
212
+ console . error ( data ) ;
213
+ return reject ( 'Failed! The Sfx application could not be created!' ) ;
207
214
} ) ;
208
215
} )
209
216
. catch ( ( err : string ) => {
0 commit comments