1
- import { mkdirp , pathExists , readFile , readJSON , writeJSON } from '@ionic/utils-fs' ;
1
+ import { mkdirp , pathExists , readFile , readJSON , rmSync , writeJSON } from '@ionic/utils-fs' ;
2
2
import fetch from 'node-fetch' ;
3
3
import parse from 'node-html-parser' ;
4
4
import { basename , extname , join , posix , relative , sep } from 'path' ;
@@ -118,7 +118,7 @@ export class PwaAssetGenerator extends AssetGenerator {
118
118
119
119
const generated : OutputAsset [ ] = [ ] ;
120
120
121
- const splashes = await Promise . all ( assetSizes . map ( ( a ) => this . _generateSplashFromLogo ( project , asset , a , pipe ) ) ) ;
121
+ const splashes = await Promise . all ( assetSizes . map ( ( a ) => this . _generateSplashFromLogo ( project , asset , a ) ) ) ;
122
122
123
123
generated . push ( ...splashes . flat ( ) ) ;
124
124
@@ -129,7 +129,6 @@ export class PwaAssetGenerator extends AssetGenerator {
129
129
project : Project ,
130
130
asset : InputAsset ,
131
131
sizeString : string ,
132
- pipe : Sharp ,
133
132
) : Promise < OutputAsset [ ] > {
134
133
const parts = sizeString . split ( '@' ) ;
135
134
const sizeParts = parts [ 0 ] . split ( 'x' ) ;
@@ -291,8 +290,8 @@ export class PwaAssetGenerator extends AssetGenerator {
291
290
private async getPWADirectory ( projectRoot ?: string ) : Promise < string > {
292
291
if ( await pathExists ( join ( projectRoot ?? '' , 'public' ) ) /* React */ ) {
293
292
return join ( projectRoot ?? '' , 'public' ) ;
294
- } else if ( await pathExists ( join ( projectRoot ?? '' , 'src/assets ' ) ) /* Angular and Vue */ ) {
295
- return join ( projectRoot ?? '' , 'src/assets ' ) ;
293
+ } else if ( await pathExists ( join ( projectRoot ?? '' , 'src' ) ) /* Angular and Vue */ ) {
294
+ return join ( projectRoot ?? '' , 'src' ) ;
296
295
} else if ( await pathExists ( join ( projectRoot ?? '' , 'www' ) ) ) {
297
296
return join ( projectRoot ?? '' , 'www' ) ;
298
297
} else {
@@ -353,19 +352,28 @@ export class PwaAssetGenerator extends AssetGenerator {
353
352
manifestJson = await readJSON ( manifestPath ) ;
354
353
}
355
354
356
- const icons = manifestJson [ 'icons' ] || [ ] ;
357
-
355
+ let icons = manifestJson [ 'icons' ] || [ ] ;
356
+ const replacedIcons = [ ] ;
358
357
for ( const asset of pwaAssets ) {
359
358
const src = asset . template . name ;
360
359
const fname = basename ( src ) ;
361
360
const relativePath = relative ( pwaDir , join ( pwaAssetDir , PWA_ASSET_PATH , fname ) ) ;
361
+ replacedIcons . push ( this . makeIconManifestEntry ( asset . template , relativePath ) ) ;
362
+ }
362
363
363
- const existing = ! ! icons . find ( ( i : any ) => i . src === relativePath ) ;
364
- if ( ! existing ) {
365
- icons . push ( this . makeIconManifestEntry ( asset . template , relativePath ) ) ;
364
+ // Delete icons that were replaced
365
+ for ( const icon of icons ) {
366
+ if ( await pathExists ( join ( pwaDir , icon . src ) ) ) {
367
+ const exists = ! ! pwaAssets . find ( ( i : any ) => i . sizes === icon . sizes ) ;
368
+ if ( ! exists ) {
369
+ rmSync ( join ( pwaDir , icon . src ) ) ;
370
+ warn ( `DELETE ${ icon . src } ` ) ;
371
+ }
366
372
}
367
373
}
368
374
375
+ icons = replacedIcons ;
376
+
369
377
// Update the manifest background color to the splash one if provided to ensure
370
378
// platform automatic splash generation works
371
379
if ( this . options . splashBackgroundColor ) {
@@ -444,9 +452,6 @@ export class PwaAssetGenerator extends AssetGenerator {
444
452
}
445
453
const dest = join ( destDir , name ) ;
446
454
447
- // console.log(width, height);
448
- const targetLogoWidthPercent = this . options . logoSplashScale ?? 0.2 ;
449
- const targetWidth = Math . floor ( width * targetLogoWidthPercent ) ;
450
455
const outputInfo = await pipe . resize ( width , height ) . png ( ) . toFile ( dest ) ;
451
456
452
457
const template : PwaOutputAssetTemplate = {
0 commit comments