22
33const common = require ( './common' )
44const debug = require ( 'debug' ) ( 'electron-packager' )
5- const download = require ( 'electron-download' )
65const extract = require ( 'extract-zip' )
76const fs = require ( 'fs-extra' )
87const getPackageInfo = require ( 'get-package-info' )
@@ -12,43 +11,14 @@ const os = require('os')
1211const path = require ( 'path' )
1312const resolve = require ( 'resolve' )
1413const series = require ( 'run-series' )
15-
16- var supportedArchs = common . archs . reduce ( function ( result , arch ) {
17- result [ arch ] = 1
18- return result
19- } , { } )
20-
21- var supportedPlatforms = {
22- // Maps to module ID for each platform (lazy-required if used)
23- darwin : './mac' ,
24- linux : './linux' ,
25- mas : './mac' , // map to darwin
26- win32 : './win32'
27- }
14+ const targets = require ( './targets' )
2815
2916function debugHostInfo ( ) {
3017 debug ( `Electron Packager ${ metadata . version } ` )
3118 debug ( `Node ${ process . version } ` )
3219 debug ( `Host Operating system: ${ process . platform } (${ process . arch } )` )
3320}
3421
35- function validateList ( list , supported , name ) {
36- // Validates list of architectures or platforms.
37- // Returns a normalized array if successful, or an error message string otherwise.
38-
39- if ( ! list ) return `Must specify ${ name } `
40- if ( list === 'all' ) return Object . keys ( supported )
41-
42- if ( ! Array . isArray ( list ) ) list = list . split ( ',' )
43- for ( var i = list . length ; i -- ; ) {
44- if ( ! supported [ list [ i ] ] ) {
45- return `Unsupported ${ name } ${ list [ i ] } ; must be one of: ${ Object . keys ( supported ) . join ( ', ' ) } `
46- }
47- }
48-
49- return list
50- }
51-
5222function getMetadata ( opts , dir , cb ) {
5323 var props = [ ]
5424 if ( ! opts . name ) props . push ( [ 'productName' , 'name' ] )
@@ -121,30 +91,20 @@ function createSeries (opts, archs, platforms) {
12191 } )
12292 }
12393
124- var combinations = [ ]
125- archs . forEach ( function ( arch ) {
126- platforms . forEach ( function ( platform ) {
127- // Electron does not have 32-bit releases for Mac OS X, so skip that combination
128- if ( common . isPlatformMac ( platform ) && arch === 'ia32' ) return
129- combinations . push ( common . createDownloadOpts ( opts , platform , arch ) )
130- } )
131- } )
132-
13394 var tasks = [ ]
13495 var useTempDir = opts . tmpdir !== false
13596 if ( useTempDir ) {
13697 tasks . push ( function ( cb ) {
13798 fs . remove ( tempBase , cb )
13899 } )
139100 }
140- return tasks . concat ( combinations . map ( function ( combination ) {
101+ return tasks . concat ( common . createDownloadCombos ( opts , platforms , archs ) . map ( combination => {
141102 var arch = combination . arch
142103 var platform = combination . platform
143104 var version = combination . version
144105
145- return function ( callback ) {
146- debug ( `Downloading Electron with options ${ JSON . stringify ( combination ) } ` )
147- download ( combination , function ( err , zipPath ) {
106+ return ( callback ) => {
107+ common . downloadElectronZip ( combination , ( err , zipPath ) => {
148108 if ( err ) return callback ( err )
149109
150110 function createApp ( comboOpts ) {
@@ -176,7 +136,7 @@ function createSeries (opts, archs, platforms) {
176136 }
177137 }
178138 ] , function ( ) {
179- require ( supportedPlatforms [ platform ] ) . createApp ( comboOpts , buildDir , callback )
139+ require ( targets . supportedPlatforms [ platform ] ) . createApp ( comboOpts , buildDir , callback )
180140 } )
181141 }
182142
@@ -229,10 +189,10 @@ module.exports = function packager (opts, cb) {
229189 debugHostInfo ( )
230190 if ( debug . enabled ) debug ( `Packager Options: ${ JSON . stringify ( opts ) } ` )
231191
232- var archs = validateList ( opts . all ? 'all' : opts . arch || process . arch , supportedArchs , 'arch' )
233- var platforms = validateList ( opts . all ? 'all' : opts . platform || process . platform , supportedPlatforms , 'platform' )
234- if ( ! Array . isArray ( archs ) ) return cb ( new Error ( archs ) )
235- if ( ! Array . isArray ( platforms ) ) return cb ( new Error ( platforms ) )
192+ let archs = targets . validateListFromOptions ( opts , targets . supportedArchs , 'arch' )
193+ let platforms = targets . validateListFromOptions ( opts , targets . supportedPlatforms , 'platform' )
194+ if ( ! Array . isArray ( archs ) ) return cb ( archs )
195+ if ( ! Array . isArray ( platforms ) ) return cb ( platforms )
236196
237197 debug ( `Target Platforms: ${ platforms . join ( ', ' ) } ` )
238198 debug ( `Target Architectures: ${ archs . join ( ', ' ) } ` )
0 commit comments