@@ -79,34 +79,34 @@ function downloadImage(imageUrl, imagesPath, imageSrc) {
7979  } ) ;           
8080} 
8181
82- // normalize icon  list and download to res  folder 
83- function  getManifestIcons ( manifest )  { 
84-      var  iconList  =  [ ] ; 
85-      if  ( manifest . icons  &&  manifest . icons  instanceof  Array )  { 
86-          manifest . icons . forEach ( function  ( icon )  { 
87-              var  imageUrl  =  url . resolve ( manifest . start_url ,   icon . src ) ; 
88-              icon . src  =  url . parse ( imageUrl ) . pathname ; 
89-              var  sizes  =  icon . sizes . toLowerCase ( ) . split ( ' ' ) ; 
90-              sizes . forEach ( function  ( iconSize )  { 
91-                  var  dimensions  =  iconSize . split ( 'x' ) ; 
92-                  var  element  =  { 
93-                    "src" : icon . src , 
94-                    "width" : dimensions [ 0 ] , 
95-                    "height" : dimensions [ 1 ] , 
96-                    "density" : icon . density , 
97-                    "type" : icon . type 
98-                  } ; 
99- 
100-                  iconList . push ( element ) ; 
101-              } ) ; 
82+ // normalize image  list and download images  to project  folder 
83+ function  processImageList ( images ,   baseUrl )  { 
84+   var  imageList  =  [ ] ; 
85+   if  ( images  &&  images  instanceof  Array )  { 
86+     images . forEach ( function  ( image )  { 
87+       var  imageUrl  =  url . resolve ( baseUrl ,   image . src ) ; 
88+       image . src  =  url . parse ( imageUrl ) . pathname ; 
89+       var  sizes  =  image . sizes . toLowerCase ( ) . split ( ' ' ) ; 
90+       sizes . forEach ( function  ( imageSize )  { 
91+         var  dimensions  =  imageSize . split ( 'x' ) ; 
92+         var  element  =  { 
93+           "src" : image . src , 
94+           "width" : dimensions [ 0 ] , 
95+           "height" : dimensions [ 1 ] , 
96+           "density" : image . density , 
97+           "type" : image . type 
98+         } ; 
99+ 
100+         imageList . push ( element ) ; 
101+       } ) ; 
102102
103-              var  iconsPath  =  path . dirname ( path . join ( projectRoot ,  icon . src ) ) ; 
103+       var  imagePath  =  path . dirname ( path . join ( projectRoot ,  image . src ) ) ; 
104104
105-              downloadImage ( imageUrl ,  iconsPath ,   icon . src ) ; 
106-          } ) ; 
107-      } 
105+       downloadImage ( imageUrl ,  imagePath ,   image . src ) ; 
106+     } ) ; 
107+   } 
108108
109-      return  iconList ; 
109+   return  imageList ; 
110110} 
111111
112112// Configure Cordova configuration parser 
@@ -230,7 +230,7 @@ function isValidFormat(icon, validFormats) {
230230  return  false ; 
231231} 
232232
233- function  processIconsBySize ( platform ,  manifestIcons ,  splashScreenSizes ,  iconSizes ,  validFormats )  { 
233+ function  processImagesBySize ( platform ,  manifestImages ,  splashScreenSizes ,  iconSizes ,  validFormats )  { 
234234    // get platform section and create it if it does not exist 
235235    var  root  =  config . doc . find ( 'platform[@name=\''  +  platform  +  '\']' ) ; 
236236    if  ( ! root )  { 
@@ -240,7 +240,7 @@ function processIconsBySize(platform, manifestIcons, splashScreenSizes, iconSize
240240
241241    var  platformIcons  =  root . findall ( 'icon' ) ; 
242242    var  platformScreens  =  root . findall ( 'splash' ) ; 
243-     manifestIcons . forEach ( function  ( element )  { 
243+     manifestImages . forEach ( function  ( element )  { 
244244        if  ( ! isValidFormat ( element ,  validFormats ) )  { 
245245          return ; 
246246        } 
@@ -286,7 +286,7 @@ function processIconsBySize(platform, manifestIcons, splashScreenSizes, iconSize
286286    } ) ; 
287287} 
288288
289- function  processIconsByDensity ( platform ,  manifestIcons ,  screenSizeToDensityMap ,  iconSizeToDensityMap ,  dppxToDensityMap ,  validFormats )  { 
289+ function  processImagesByDensity ( platform ,  manifestImages ,  screenSizeToDensityMap ,  iconSizeToDensityMap ,  dppxToDensityMap ,  validFormats )  { 
290290    // get platform section and create it if it does not exist 
291291    var  root  =  config . doc . find ( 'platform[@name=\''  +  platform  +  '\']' ) ; 
292292    if  ( ! root )  { 
@@ -296,7 +296,7 @@ function processIconsByDensity(platform, manifestIcons, screenSizeToDensityMap,
296296
297297    var  platformIcons  =  root . findall ( 'icon' ) ; 
298298    var  platformScreens  =  root . findall ( 'splash' ) ; 
299-     manifestIcons . forEach ( function  ( element )  { 
299+     manifestImages . forEach ( function  ( element )  { 
300300        if  ( ! isValidFormat ( element ,  validFormats ) )  { 
301301            return ; 
302302        } 
@@ -455,7 +455,7 @@ function processDefaultIconsBySize(platform, screenSizes, iconSizes) {
455455    } ) ; 
456456} 
457457
458- function  processiOSIcons ( manifestIcons )  { 
458+ function  processiOSIcons ( manifestIcons ,   manifestSplashScreens )  { 
459459    var  iconSizes  =  [ 
460460        "40x40" , 
461461        "80x80" , 
@@ -487,11 +487,12 @@ function processiOSIcons(manifestIcons) {
487487        "1242x2208" 
488488    ] ; 
489489
490-     processIconsBySize ( 'ios' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
490+     processImagesBySize ( 'ios' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
491+     processImagesBySize ( 'ios' ,  manifestSplashScreens ,  splashScreenSizes ,  [ ] ) ; 
491492    processDefaultIconsBySize ( 'ios' ,  splashScreenSizes ,  iconSizes ) ; 
492493} 
493494
494- function  processAndroidIcons ( manifestIcons ,  outputConfiguration ,   previousIndent )  { 
495+ function  processAndroidIcons ( manifestIcons ,  manifestSplashScreens )  { 
495496    var  iconSizeToDensityMap  =  { 
496497        36 : 'ldpi' , 
497498        48 : 'mdpi' , 
@@ -540,11 +541,12 @@ function processAndroidIcons(manifestIcons, outputConfiguration, previousIndent)
540541      'image/png' 
541542    ] ; 
542543
543-     processIconsByDensity ( 'android' ,  manifestIcons ,  screenSizeToDensityMap ,  iconSizeToDensityMap ,  dppxToDensityMap ,  validFormats ) ;    
544+     processImagesByDensity ( 'android' ,  manifestIcons ,  screenSizeToDensityMap ,  iconSizeToDensityMap ,  dppxToDensityMap ,  validFormats ) ;    
545+     processImagesByDensity ( 'android' ,  manifestSplashScreens ,  screenSizeToDensityMap ,  [ ] ,  dppxToDensityMap ,  validFormats ) ;    
544546    processDefaultIconsByDensity ( 'android' ,  screenDensities ,  iconDensities ) ; 
545547} 
546548
547- function  processWindowsIcons ( manifestIcons )  { 
549+ function  processWindowsIcons ( manifestIcons ,   manifestSplashScreens )  { 
548550    var  iconSizes  =  [ 
549551        "30x30" , 
550552        "44x44" , 
@@ -566,11 +568,12 @@ function processWindowsIcons(manifestIcons) {
566568        "1152x1920" 
567569    ] ; 
568570
569-     processIconsBySize ( 'windows' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
571+     processImagesBySize ( 'windows' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
572+     processImagesBySize ( 'windows' ,  manifestSplashScreens ,  splashScreenSizes ,  [ ] ) ; 
570573    processDefaultIconsBySize ( 'windows' ,  splashScreenSizes ,  iconSizes ) ; 
571574} ; 
572575
573- function  processWindowsPhoneIcons ( manifestIcons )  { 
576+ function  processWindowsPhoneIcons ( manifestIcons ,   manifestSplashScreens )  { 
574577    var  iconSizes  =  [ 
575578        "62x62" , 
576579        "173x173" 
@@ -580,7 +583,8 @@ function processWindowsPhoneIcons(manifestIcons) {
580583        "480x800" 
581584    ] ; 
582585
583-     processIconsBySize ( 'wp8' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
586+     processImagesBySize ( 'wp8' ,  manifestIcons ,  splashScreenSizes ,  iconSizes ) ; 
587+     processImagesBySize ( 'wp8' ,  manifestSplashScreens ,  splashScreenSizes ,  [ ] ) ; 
584588    processDefaultIconsBySize ( 'wp8' ,  splashScreenSizes ,  iconSizes ) ; 
585589} ; 
586590
@@ -665,16 +669,19 @@ module.exports = function (context) {
665669        // configure access rules 
666670        processAccessRules ( manifest ) ; 
667671
668-         // Obtain and download the icons specified in the manidest 
669-         var  manifestIcons  =  getManifestIcons ( manifest ) ; 
672+         // Obtain and download the icons and splash screens specified in the manifest. 
673+         // Currently, splash screens specified in the splash_screens section of the manifest  
674+         // take precedence over similarly sized splash screens in the icons section. 
675+         var  manifestIcons  =  processImageList ( manifest . icons ,  manifest . start_url ) ; 
676+         var  manifestSplashScreens  =  processImageList ( manifest . splash_screens ,  manifest . start_url ) ; 
670677
671678        Q . allSettled ( pendingTasks ) . then ( function  ( )  { 
672679
673680          // Configure the icons once all icon files are downloaded 
674-           processiOSIcons ( manifestIcons ) ; 
675-           processAndroidIcons ( manifestIcons ) ; 
676-           processWindowsIcons ( manifestIcons ) ; 
677-           processWindowsPhoneIcons ( manifestIcons ) ; 
681+           processiOSIcons ( manifestIcons ,   manifestSplashScreens ) ; 
682+           processAndroidIcons ( manifestIcons ,   manifestSplashScreens ) ; 
683+           processWindowsIcons ( manifestIcons ,   manifestSplashScreens ) ; 
684+           processWindowsPhoneIcons ( manifestIcons ,   manifestSplashScreens ) ; 
678685
679686          // save the updated configuration 
680687          config . write ( ) ; 
0 commit comments