Skip to content

Commit 3c5ecbe

Browse files
authored
fix: pwa icon generation and angular vue path (#572)
* fix: pwa icon generation and angular vue path * fix: remove commented code * fix: remove commented code
1 parent 5f42c57 commit 3c5ecbe

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/platforms/android/index.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class AndroidAssetGenerator extends AssetGenerator {
233233

234234
const collected = await Promise.all(
235235
icons.map(async (icon) => {
236-
const [dest, outputInfo] = await this.generateLegacyLauncherIcon(project, asset, icon, pipe);
236+
const [dest, outputInfo] = await this.generateLegacyLauncherIcon(project, asset, icon);
237237

238238
return new OutputAsset(
239239
icon,
@@ -248,7 +248,7 @@ export class AndroidAssetGenerator extends AssetGenerator {
248248
collected.push(
249249
...(await Promise.all(
250250
icons.map(async (icon) => {
251-
const [dest, outputInfo] = await this.generateRoundLauncherIcon(project, asset, icon, pipe);
251+
const [dest, outputInfo] = await this.generateRoundLauncherIcon(project, asset, icon);
252252

253253
return new OutputAsset(
254254
icon,
@@ -270,11 +270,7 @@ export class AndroidAssetGenerator extends AssetGenerator {
270270
project: Project,
271271
asset: InputAsset,
272272
template: AndroidOutputAssetTemplate,
273-
pipe: Sharp,
274273
): Promise<[string, OutputInfo]> {
275-
const radius = 4;
276-
const svg = `<svg width="${template.width}" height="${template.height}"><rect x="0" y="0" width="${template.width}" height="${template.height}" rx="${radius}" fill="#ffffff"/></svg>`;
277-
278274
const resPath = this.getResPath(project);
279275
const parentDir = join(resPath, `mipmap-${template.density}`);
280276
if (!(await pathExists(parentDir))) {
@@ -308,7 +304,6 @@ export class AndroidAssetGenerator extends AssetGenerator {
308304
project: Project,
309305
asset: InputAsset,
310306
template: AndroidOutputAssetTemplate,
311-
pipe: Sharp,
312307
): Promise<[string, OutputInfo]> {
313308
const svg = `<svg width="${template.width}" height="${template.height}"><circle cx="${template.width / 2}" cy="${
314309
template.height / 2

src/platforms/pwa/index.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdirp, pathExists, readFile, readJSON, writeJSON } from '@ionic/utils-fs';
1+
import { mkdirp, pathExists, readFile, readJSON, rmSync, writeJSON } from '@ionic/utils-fs';
22
import fetch from 'node-fetch';
33
import parse from 'node-html-parser';
44
import { basename, extname, join, posix, relative, sep } from 'path';
@@ -118,7 +118,7 @@ export class PwaAssetGenerator extends AssetGenerator {
118118

119119
const generated: OutputAsset[] = [];
120120

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)));
122122

123123
generated.push(...splashes.flat());
124124

@@ -129,7 +129,6 @@ export class PwaAssetGenerator extends AssetGenerator {
129129
project: Project,
130130
asset: InputAsset,
131131
sizeString: string,
132-
pipe: Sharp,
133132
): Promise<OutputAsset[]> {
134133
const parts = sizeString.split('@');
135134
const sizeParts = parts[0].split('x');
@@ -291,8 +290,8 @@ export class PwaAssetGenerator extends AssetGenerator {
291290
private async getPWADirectory(projectRoot?: string): Promise<string> {
292291
if (await pathExists(join(projectRoot ?? '', 'public')) /* React */) {
293292
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');
296295
} else if (await pathExists(join(projectRoot ?? '', 'www'))) {
297296
return join(projectRoot ?? '', 'www');
298297
} else {
@@ -353,19 +352,28 @@ export class PwaAssetGenerator extends AssetGenerator {
353352
manifestJson = await readJSON(manifestPath);
354353
}
355354

356-
const icons = manifestJson['icons'] || [];
357-
355+
let icons = manifestJson['icons'] || [];
356+
const replacedIcons = [];
358357
for (const asset of pwaAssets) {
359358
const src = asset.template.name;
360359
const fname = basename(src);
361360
const relativePath = relative(pwaDir, join(pwaAssetDir, PWA_ASSET_PATH, fname));
361+
replacedIcons.push(this.makeIconManifestEntry(asset.template, relativePath));
362+
}
362363

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+
}
366372
}
367373
}
368374

375+
icons = replacedIcons;
376+
369377
// Update the manifest background color to the splash one if provided to ensure
370378
// platform automatic splash generation works
371379
if (this.options.splashBackgroundColor) {
@@ -444,9 +452,6 @@ export class PwaAssetGenerator extends AssetGenerator {
444452
}
445453
const dest = join(destDir, name);
446454

447-
// console.log(width, height);
448-
const targetLogoWidthPercent = this.options.logoSplashScale ?? 0.2;
449-
const targetWidth = Math.floor(width * targetLogoWidthPercent);
450455
const outputInfo = await pipe.resize(width, height).png().toFile(dest);
451456

452457
const template: PwaOutputAssetTemplate = {

0 commit comments

Comments
 (0)