|
1 |
| -import { readFile, writeFile } from '@ionic/utils-fs'; |
| 1 | +import { readFile, rmSync, writeFile } from '@ionic/utils-fs'; |
2 | 2 | import { join } from 'path';
|
3 | 3 | import sharp from 'sharp';
|
4 | 4 |
|
@@ -48,15 +48,6 @@ export class IosAssetGenerator extends AssetGenerator {
|
48 | 48 | return this.generateFromLogo(asset, project);
|
49 | 49 | case AssetKind.Icon:
|
50 | 50 | return this.generateIcons(asset, project);
|
51 |
| - case AssetKind.NotificationIcon: |
52 |
| - return this.generateNotificationIcons(asset, project); |
53 |
| - // eslint-disable-next-line no-duplicate-case |
54 |
| - case AssetKind.Icon: |
55 |
| - return []; |
56 |
| - case AssetKind.SettingsIcon: |
57 |
| - return this.generateSettingsIcons(asset, project); |
58 |
| - case AssetKind.SpotlightIcon: |
59 |
| - return this.generateSpotlightIcons(asset, project); |
60 | 51 | case AssetKind.Splash:
|
61 | 52 | case AssetKind.SplashDark:
|
62 | 53 | return this.generateSplashes(asset, project);
|
@@ -221,39 +212,13 @@ export class IosAssetGenerator extends AssetGenerator {
|
221 | 212 |
|
222 | 213 | // Generate ALL the icons when only given a logo
|
223 | 214 | private async generateIconsForLogo(asset: InputAsset, project: Project): Promise<OutputAsset[]> {
|
224 |
| - const icons = Object.values(IosAssetTemplates).filter((a) => |
225 |
| - [AssetKind.Icon, AssetKind.NotificationIcon, AssetKind.SettingsIcon, AssetKind.SpotlightIcon].find( |
226 |
| - (i) => i === a.kind, |
227 |
| - ), |
228 |
| - ); |
| 215 | + const icons = Object.values(IosAssetTemplates).filter((a) => [AssetKind.Icon].find((i) => i === a.kind)); |
229 | 216 |
|
230 | 217 | return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]);
|
231 | 218 | }
|
232 | 219 |
|
233 | 220 | private async generateIcons(asset: InputAsset, project: Project): Promise<OutputAsset[]> {
|
234 |
| - const icons = Object.values(IosAssetTemplates).filter((a) => |
235 |
| - [AssetKind.Icon, AssetKind.NotificationIcon, AssetKind.SettingsIcon, AssetKind.SpotlightIcon].find( |
236 |
| - (i) => i === a.kind, |
237 |
| - ), |
238 |
| - ); |
239 |
| - |
240 |
| - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); |
241 |
| - } |
242 |
| - |
243 |
| - private async generateNotificationIcons(asset: InputAsset, project: Project): Promise<OutputAsset[]> { |
244 |
| - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.NotificationIcon); |
245 |
| - |
246 |
| - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); |
247 |
| - } |
248 |
| - |
249 |
| - private async generateSettingsIcons(asset: InputAsset, project: Project): Promise<OutputAsset[]> { |
250 |
| - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.SettingsIcon); |
251 |
| - |
252 |
| - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); |
253 |
| - } |
254 |
| - |
255 |
| - private async generateSpotlightIcons(asset: InputAsset, project: Project): Promise<OutputAsset[]> { |
256 |
| - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.SpotlightIcon); |
| 221 | + const icons = Object.values(IosAssetTemplates).filter((a) => [AssetKind.Icon].find((i) => i === a.kind)); |
257 | 222 |
|
258 | 223 | return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]);
|
259 | 224 | }
|
@@ -308,36 +273,29 @@ export class IosAssetGenerator extends AssetGenerator {
|
308 | 273 | }
|
309 | 274 |
|
310 | 275 | private async updateIconsContentsJson(generated: OutputAsset[], project: Project) {
|
311 |
| - const contentsJsonPath = join(project.config.ios!.path!, IOS_APP_ICON_SET_PATH, 'Contents.json'); |
| 276 | + const assetsPath = join(project.config.ios!.path!, IOS_APP_ICON_SET_PATH); |
| 277 | + const contentsJsonPath = join(assetsPath, 'Contents.json'); |
312 | 278 | const json = await readFile(contentsJsonPath, { encoding: 'utf-8' });
|
313 | 279 |
|
314 | 280 | const parsed = JSON.parse(json);
|
315 | 281 |
|
316 |
| - const withoutMissing = parsed.images.filter((i: any) => !!i.filename); |
317 |
| - |
| 282 | + const withoutMissing = []; |
318 | 283 | for (const g of generated) {
|
319 |
| - const width = g.template.width / (g.template.scale ?? 1); |
320 |
| - const height = g.template.height / (g.template.scale ?? 1); |
321 |
| - const scale = g.template.scale ?? 1; |
| 284 | + const width = g.template.width; |
| 285 | + const height = g.template.height; |
322 | 286 |
|
323 |
| - const existing = withoutMissing.find( |
324 |
| - (f: any) => |
325 |
| - f.scale === `${scale}x` && |
326 |
| - f.size === `${width}x${height}` && |
327 |
| - f.idiom === (g.template as IosOutputAssetTemplate).idiom && |
328 |
| - typeof f.appearances === 'undefined', |
329 |
| - ); |
| 287 | + parsed.images.map((i: any) => { |
| 288 | + if (i.filename !== (g.template as IosOutputAssetTemplate).name) { |
| 289 | + rmSync(join(assetsPath, i.filename)); |
| 290 | + } |
| 291 | + }); |
330 | 292 |
|
331 |
| - if (existing) { |
332 |
| - existing.filename = (g.template as IosOutputAssetTemplate).name; |
333 |
| - } else { |
334 |
| - withoutMissing.push({ |
335 |
| - idiom: (g.template as IosOutputAssetTemplate).idiom, |
336 |
| - size: `${width}x${height}`, |
337 |
| - scale: `${scale}x`, |
338 |
| - filename: (g.template as IosOutputAssetTemplate).name, |
339 |
| - }); |
340 |
| - } |
| 293 | + withoutMissing.push({ |
| 294 | + idiom: (g.template as IosOutputAssetTemplate).idiom, |
| 295 | + size: `${width}x${height}`, |
| 296 | + filename: (g.template as IosOutputAssetTemplate).name, |
| 297 | + platform: Platform.Ios, |
| 298 | + }); |
341 | 299 | }
|
342 | 300 |
|
343 | 301 | parsed.images = withoutMissing;
|
|
0 commit comments