@@ -7,6 +7,9 @@ export const createManifest = async (context, config, queue, options) => {
7
7
const manifestDest = path . join ( config . outputDir , options . manifestPath ) ;
8
8
const iconsDir = path . join ( config . outputDir , options . staticAssetsDir ) ;
9
9
const iconName = options . icon . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
10
+ const maskableIconName = typeof options . maskableIcon === 'string'
11
+ ? options . maskableIcon . split ( '/' ) . slice ( - 1 ) [ 0 ]
12
+ : null
10
13
11
14
// Generate all size images from options.icon
12
15
const sizes = [ 512 , 384 , 192 , 180 , 152 , 144 , 128 , 120 , 96 , 72 , 48 , 16 ] ;
@@ -15,16 +18,37 @@ export const createManifest = async (context, config, queue, options) => {
15
18
const icons = [ ] ;
16
19
await Promise . all ( sizes . map ( ( size ) => {
17
20
const sizes = `${ size } x${ size } ` ;
18
- const imagePath = path . join ( iconsDir , rename ( iconName , { suffix : `-${ sizes } ` } ) )
19
- const src = path . relative ( config . outputDir , imagePath ) ;
20
- const type = 'image/' + iconName . split ( '.' ) . slice ( - 1 ) [ 0 ] ;
21
- icons . push ( {
22
- src,
23
- type,
24
- sizes,
25
- purpose : options . maskableIcon ? 'maskable any' : 'any' ,
26
- } ) ;
27
- return sharp ( options . icon ) . resize ( size , size ) . toFile ( imagePath ) ;
21
+
22
+ // for { icon }
23
+ let imagePath = path . join ( iconsDir , rename ( iconName , { suffix : `-${ sizes } ` } ) )
24
+ let src = path . relative ( config . outputDir , imagePath ) ;
25
+ let type = 'image/' + iconName . split ( '.' ) . slice ( - 1 ) [ 0 ] ;
26
+ let purpose = 'any'
27
+
28
+ // maskableIcon can now be boolean or an icon path.
29
+ // if it is true, or is the same icon file as standard icon, set 'maskable any'
30
+ if ( options . maskableIcon === true || options . maskableIcon === options . icon ) {
31
+ purpose = 'maskable any'
32
+ }
33
+
34
+ // add and process { icon }
35
+ icons . push ( { src, type, sizes, purpose } ) ;
36
+ const results = [ sharp ( options . icon ) . resize ( size , size ) . toFile ( imagePath ) ]
37
+
38
+ // if maskableIcon is a string, then we need to process it as a separate maskable icon
39
+ if ( options . maskableIcon && typeof options . maskableIcon === 'string' ) {
40
+ imagePath = path . join ( iconsDir , rename ( maskableIconName , { suffix : `-maskable-${ sizes } ` } ) )
41
+ src = path . relative ( config . outputDir , imagePath ) ;
42
+ type = 'image/' + iconName . split ( '.' ) . slice ( - 1 ) [ 0 ] ;
43
+ purpose = 'maskable'
44
+
45
+ // add and process { maskableIcon }
46
+ icons . push ( { src, type, sizes, purpose } ) ;
47
+ results . push ( sharp ( options . maskableIconName ) . resize ( size , size ) . toFile ( imagePath ) )
48
+ }
49
+
50
+ // always return a single promise
51
+ return Promise . all ( results )
28
52
} ) ) ;
29
53
30
54
await fs . outputFile ( manifestDest , JSON . stringify ( {
0 commit comments