From 395273083bda26153be40ad590deaedc9e4be0e0 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 2 Oct 2023 16:36:34 +0200 Subject: [PATCH] fix: only generate single 1024x1024 iOS icon --- package-lock.json | 4 +- src/definitions.ts | 6 - src/platforms/ios/assets.ts | 5 +- src/platforms/ios/index.ts | 80 +++---------- src/project.ts | 3 - test/asset.test.ts | 12 -- .../AppIcon.appiconset/Contents.json | 108 +---------------- .../AppIcon.appiconset/Contents.json | 110 +----------------- test/platforms/ios.asset.test.ts | 47 +------- 9 files changed, 31 insertions(+), 344 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e1a228..d6ebb27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@capacitor/assets", - "version": "2.0.4", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@capacitor/assets", - "version": "2.0.4", + "version": "3.0.0", "license": "MIT", "dependencies": { "@capacitor/cli": "^5.3.0", diff --git a/src/definitions.ts b/src/definitions.ts index 9344b99..42160dd 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -12,9 +12,6 @@ export interface Assets { iosIcon?: InputAsset | null; iosSplash?: InputAsset | null; iosSplashDark?: InputAsset | null; - iosNotificationIcon?: InputAsset | null; - iosSettingsIcon?: InputAsset | null; - iosSpotlightIcon?: InputAsset | null; androidIcon?: InputAsset | null; androidIconForeground?: InputAsset | null; @@ -37,8 +34,6 @@ export const enum AssetKind { IconForeground = 'icon-foreground', IconBackground = 'icon-background', NotificationIcon = 'notification-icon', - SettingsIcon = 'settings-icon', - SpotlightIcon = 'spotlight-icon', Splash = 'splash', SplashDark = 'splash-dark', } @@ -129,7 +124,6 @@ export interface IosOutputAssetTemplate extends OutputAssetTemplate { // https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/ImageSetType.html#//apple_ref/doc/uid/TP40015170-CH25-SW2 export const enum IosIdiom { Universal = 'universal', - iOSMarketing = 'ios-marketing', iPhone = 'iphone', iPad = 'ipad', Watch = 'watch', diff --git a/src/platforms/ios/assets.ts b/src/platforms/ios/assets.ts index 0568dd4..ad37e6b 100644 --- a/src/platforms/ios/assets.ts +++ b/src/platforms/ios/assets.ts @@ -4,17 +4,16 @@ import { AssetKind, Format, IosIdiom, Orientation, Platform, Theme } from '../.. /** * 1024px Icon * - * - App Store + * - iOS 1024 icon */ export const IOS_1024_ICON: IosOutputAssetTemplate = { platform: Platform.Ios, - idiom: IosIdiom.iOSMarketing, + idiom: IosIdiom.Universal, kind: AssetKind.Icon, name: 'AppIcon-512@2x.png', format: Format.Png, width: 1024, height: 1024, - scale: 1, }; export const IOS_1X_UNIVERSAL_ANYANY_SPLASH: IosOutputAssetTemplateSplash = { diff --git a/src/platforms/ios/index.ts b/src/platforms/ios/index.ts index 551e816..7006f51 100644 --- a/src/platforms/ios/index.ts +++ b/src/platforms/ios/index.ts @@ -1,4 +1,4 @@ -import { readFile, writeFile } from '@ionic/utils-fs'; +import { readFile, rmSync, writeFile } from '@ionic/utils-fs'; import { join } from 'path'; import sharp from 'sharp'; @@ -48,15 +48,6 @@ export class IosAssetGenerator extends AssetGenerator { return this.generateFromLogo(asset, project); case AssetKind.Icon: return this.generateIcons(asset, project); - case AssetKind.NotificationIcon: - return this.generateNotificationIcons(asset, project); - // eslint-disable-next-line no-duplicate-case - case AssetKind.Icon: - return []; - case AssetKind.SettingsIcon: - return this.generateSettingsIcons(asset, project); - case AssetKind.SpotlightIcon: - return this.generateSpotlightIcons(asset, project); case AssetKind.Splash: case AssetKind.SplashDark: return this.generateSplashes(asset, project); @@ -221,39 +212,13 @@ export class IosAssetGenerator extends AssetGenerator { // Generate ALL the icons when only given a logo private async generateIconsForLogo(asset: InputAsset, project: Project): Promise { - const icons = Object.values(IosAssetTemplates).filter((a) => - [AssetKind.Icon, AssetKind.NotificationIcon, AssetKind.SettingsIcon, AssetKind.SpotlightIcon].find( - (i) => i === a.kind, - ), - ); + const icons = Object.values(IosAssetTemplates).filter((a) => [AssetKind.Icon].find((i) => i === a.kind)); return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); } private async generateIcons(asset: InputAsset, project: Project): Promise { - const icons = Object.values(IosAssetTemplates).filter((a) => - [AssetKind.Icon, AssetKind.NotificationIcon, AssetKind.SettingsIcon, AssetKind.SpotlightIcon].find( - (i) => i === a.kind, - ), - ); - - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); - } - - private async generateNotificationIcons(asset: InputAsset, project: Project): Promise { - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.NotificationIcon); - - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); - } - - private async generateSettingsIcons(asset: InputAsset, project: Project): Promise { - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.SettingsIcon); - - return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); - } - - private async generateSpotlightIcons(asset: InputAsset, project: Project): Promise { - const icons = Object.values(IosAssetTemplates).filter((a) => a.kind === AssetKind.SpotlightIcon); + const icons = Object.values(IosAssetTemplates).filter((a) => [AssetKind.Icon].find((i) => i === a.kind)); return this._generateIcons(asset, project, icons as IosOutputAssetTemplate[]); } @@ -308,36 +273,29 @@ export class IosAssetGenerator extends AssetGenerator { } private async updateIconsContentsJson(generated: OutputAsset[], project: Project) { - const contentsJsonPath = join(project.config.ios!.path!, IOS_APP_ICON_SET_PATH, 'Contents.json'); + const assetsPath = join(project.config.ios!.path!, IOS_APP_ICON_SET_PATH); + const contentsJsonPath = join(assetsPath, 'Contents.json'); const json = await readFile(contentsJsonPath, { encoding: 'utf-8' }); const parsed = JSON.parse(json); - const withoutMissing = parsed.images.filter((i: any) => !!i.filename); - + const withoutMissing = []; for (const g of generated) { - const width = g.template.width / (g.template.scale ?? 1); - const height = g.template.height / (g.template.scale ?? 1); - const scale = g.template.scale ?? 1; + const width = g.template.width; + const height = g.template.height; - const existing = withoutMissing.find( - (f: any) => - f.scale === `${scale}x` && - f.size === `${width}x${height}` && - f.idiom === (g.template as IosOutputAssetTemplate).idiom && - typeof f.appearances === 'undefined', - ); + parsed.images.map((i: any) => { + if (i.filename !== (g.template as IosOutputAssetTemplate).name) { + rmSync(join(assetsPath, i.filename)); + } + }); - if (existing) { - existing.filename = (g.template as IosOutputAssetTemplate).name; - } else { - withoutMissing.push({ - idiom: (g.template as IosOutputAssetTemplate).idiom, - size: `${width}x${height}`, - scale: `${scale}x`, - filename: (g.template as IosOutputAssetTemplate).name, - }); - } + withoutMissing.push({ + idiom: (g.template as IosOutputAssetTemplate).idiom, + size: `${width}x${height}`, + filename: (g.template as IosOutputAssetTemplate).name, + platform: Platform.Ios, + }); } parsed.images = withoutMissing; diff --git a/src/project.ts b/src/project.ts index 374825c..325bf10 100644 --- a/src/project.ts +++ b/src/project.ts @@ -62,9 +62,6 @@ export class Project extends MobileProject { iosIcon: await this.loadInputAsset('ios/icon', AssetKind.Icon, Platform.Ios), iosSplash: await this.loadInputAsset('ios/splash', AssetKind.Splash, Platform.Ios), iosSplashDark: await this.loadInputAsset('ios/splash-dark', AssetKind.SplashDark, Platform.Ios), - iosNotificationIcon: await this.loadInputAsset('ios/notification-icon', AssetKind.NotificationIcon, Platform.Ios), - iosSettingsIcon: await this.loadInputAsset('ios/settings-icon', AssetKind.SettingsIcon, Platform.Ios), - iosSpotlightIcon: await this.loadInputAsset('ios/spotlight-icon', AssetKind.SpotlightIcon, Platform.Ios), androidIcon: await this.loadInputAsset('android/icon', AssetKind.Icon, Platform.Android), androidIconForeground: await this.loadInputAsset('android/icon-foreground', AssetKind.Icon, Platform.Android), diff --git a/test/asset.test.ts b/test/asset.test.ts index e204598..1a46d44 100644 --- a/test/asset.test.ts +++ b/test/asset.test.ts @@ -40,17 +40,5 @@ describe('Asset test', () => { expect(assets.iosIcon?.format()).toBe(Format.Png); expect(assets.iosIcon?.width).toBe(1024); expect(assets.iosIcon?.height).toBe(1024); - expect(assets.iosNotificationIcon).not.toBeNull(); - expect(assets.iosNotificationIcon?.format()).toBe(Format.Png); - expect(assets.iosNotificationIcon?.width).toBe(1024); - expect(assets.iosNotificationIcon?.height).toBe(1024); - expect(assets.iosSettingsIcon).not.toBeNull(); - expect(assets.iosSettingsIcon?.format()).toBe(Format.Png); - expect(assets.iosSettingsIcon?.width).toBe(1024); - expect(assets.iosSettingsIcon?.height).toBe(1024); - expect(assets.iosSpotlightIcon).not.toBeNull(); - expect(assets.iosSpotlightIcon?.format()).toBe(Format.Png); - expect(assets.iosSpotlightIcon?.width).toBe(1024); - expect(assets.iosSpotlightIcon?.height).toBe(1024); }); }); diff --git a/test/fixtures/app-logo-only/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json b/test/fixtures/app-logo-only/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json index dd3b8bc..5480105 100644 --- a/test/fixtures/app-logo-only/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/test/fixtures/app-logo-only/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,112 +1,10 @@ { "images": [ { - "size": "20x20", - "idiom": "iphone", - "filename": "AppIcon-20x20@2x.png", - "scale": "2x" - }, - { - "size": "20x20", - "idiom": "iphone", - "filename": "AppIcon-20x20@3x.png", - "scale": "3x" - }, - { - "size": "29x29", - "idiom": "iphone", - "filename": "AppIcon-29x29@2x-1.png", - "scale": "2x" - }, - { - "size": "29x29", - "idiom": "iphone", - "filename": "AppIcon-29x29@3x.png", - "scale": "3x" - }, - { - "size": "40x40", - "idiom": "iphone", - "filename": "AppIcon-40x40@2x.png", - "scale": "2x" - }, - { - "size": "40x40", - "idiom": "iphone", - "filename": "AppIcon-40x40@3x.png", - "scale": "3x" - }, - { - "size": "60x60", - "idiom": "iphone", - "filename": "AppIcon-60x60@2x.png", - "scale": "2x" - }, - { - "size": "60x60", - "idiom": "iphone", - "filename": "AppIcon-60x60@3x.png", - "scale": "3x" - }, - { - "size": "20x20", - "idiom": "ipad", - "filename": "AppIcon-20x20@1x.png", - "scale": "1x" - }, - { - "size": "20x20", - "idiom": "ipad", - "filename": "AppIcon-20x20@2x-1.png", - "scale": "2x" - }, - { - "size": "29x29", - "idiom": "ipad", - "filename": "AppIcon-29x29@1x.png", - "scale": "1x" - }, - { - "size": "29x29", - "idiom": "ipad", - "filename": "AppIcon-29x29@2x.png", - "scale": "2x" - }, - { - "size": "40x40", - "idiom": "ipad", - "filename": "AppIcon-40x40@1x.png", - "scale": "1x" - }, - { - "size": "40x40", - "idiom": "ipad", - "filename": "AppIcon-40x40@2x-1.png", - "scale": "2x" - }, - { - "size": "76x76", - "idiom": "ipad", - "filename": "AppIcon-76x76@1x.png", - "scale": "1x" - }, - { - "size": "76x76", - "idiom": "ipad", - "filename": "AppIcon-76x76@2x.png", - "scale": "2x" - }, - { - "size": "83.5x83.5", - "idiom": "ipad", - "filename": "AppIcon-83.5x83.5@2x.png", - "scale": "2x" - }, - { - "size": "1024x1024", - "idiom": "ios-marketing", "filename": "AppIcon-512@2x.png", - "scale": "1x" + "idiom": "universal", + "platform": "ios", + "size": "1024x1024" } ], "info": { diff --git a/test/fixtures/app/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json b/test/fixtures/app/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json index 90eea7e..92356ae 100644 --- a/test/fixtures/app/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/test/fixtures/app/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,112 +1,10 @@ { "images" : [ { - "size" : "20x20", - "idiom" : "iphone", - "filename" : "AppIcon-20x20@2x.png", - "scale" : "2x" - }, - { - "size" : "20x20", - "idiom" : "iphone", - "filename" : "AppIcon-20x20@3x.png", - "scale" : "3x" - }, - { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "AppIcon-29x29@2x-1.png", - "scale" : "2x" - }, - { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "AppIcon-29x29@3x.png", - "scale" : "3x" - }, - { - "size" : "40x40", - "idiom" : "iphone", - "filename" : "AppIcon-40x40@2x.png", - "scale" : "2x" - }, - { - "size" : "40x40", - "idiom" : "iphone", - "filename" : "AppIcon-40x40@3x.png", - "scale" : "3x" - }, - { - "size" : "60x60", - "idiom" : "iphone", - "filename" : "AppIcon-60x60@2x.png", - "scale" : "2x" - }, - { - "size" : "60x60", - "idiom" : "iphone", - "filename" : "AppIcon-60x60@3x.png", - "scale" : "3x" - }, - { - "size" : "20x20", - "idiom" : "ipad", - "filename" : "AppIcon-20x20@1x.png", - "scale" : "1x" - }, - { - "size" : "20x20", - "idiom" : "ipad", - "filename" : "AppIcon-20x20@2x-1.png", - "scale" : "2x" - }, - { - "size" : "29x29", - "idiom" : "ipad", - "filename" : "AppIcon-29x29@1x.png", - "scale" : "1x" - }, - { - "size" : "29x29", - "idiom" : "ipad", - "filename" : "AppIcon-29x29@2x.png", - "scale" : "2x" - }, - { - "size" : "40x40", - "idiom" : "ipad", - "filename" : "AppIcon-40x40@1x.png", - "scale" : "1x" - }, - { - "size" : "40x40", - "idiom" : "ipad", - "filename" : "AppIcon-40x40@2x-1.png", - "scale" : "2x" - }, - { - "size" : "76x76", - "idiom" : "ipad", - "filename" : "AppIcon-76x76@1x.png", - "scale" : "1x" - }, - { - "size" : "76x76", - "idiom" : "ipad", - "filename" : "AppIcon-76x76@2x.png", - "scale" : "2x" - }, - { - "size" : "83.5x83.5", - "idiom" : "ipad", - "filename" : "AppIcon-83.5x83.5@2x.png", - "scale" : "2x" - }, - { - "size" : "1024x1024", - "idiom" : "ios-marketing", - "filename" : "AppIcon-512@2x.png", - "scale" : "1x" + "filename": "AppIcon-512@2x.png", + "idiom": "universal", + "platform": "ios", + "size": "1024x1024" } ], "info" : { diff --git a/test/platforms/ios.asset.test.ts b/test/platforms/ios.asset.test.ts index 190d6ce..065fed3 100644 --- a/test/platforms/ios.asset.test.ts +++ b/test/platforms/ios.asset.test.ts @@ -76,7 +76,7 @@ describe('iOS Asset Test', () => { it('Should generate ios icons', async () => { const exportedIcons = Object.values(IosAssets).filter( (a) => - [AssetKind.Icon, AssetKind.NotificationIcon, AssetKind.SettingsIcon, AssetKind.SpotlightIcon].indexOf(a.kind) >= + [AssetKind.Icon].indexOf(a.kind) >= 0, ); @@ -88,45 +88,6 @@ describe('iOS Asset Test', () => { await verifyExists(generatedAssets); await verifySizes(generatedAssets); }); - - it('Should generate ios notification icons', async () => { - const exportedIcons = Object.values(IosAssets).filter((a) => a.kind === AssetKind.NotificationIcon); - - const strategy = new IosAssetGenerator(); - let generatedAssets = ((await assets.iosNotificationIcon?.generate(strategy, ctx.project)) ?? - []) as OutputAsset[]; - expect(generatedAssets.length).toBeGreaterThanOrEqual(0); - expect(generatedAssets.length).toBe(exportedIcons.length); - - await verifyExists(generatedAssets); - await verifySizes(generatedAssets); - }); - - it('Should generate ios settings icons', async () => { - const exportedIcons = Object.values(IosAssets).filter((a) => a.kind === AssetKind.SettingsIcon); - - const strategy = new IosAssetGenerator(); - let generatedAssets = ((await assets.iosSettingsIcon?.generate(strategy, ctx.project)) ?? - []) as OutputAsset[]; - expect(generatedAssets.length).toBeGreaterThanOrEqual(0); - expect(generatedAssets.length).toBe(exportedIcons.length); - - await verifyExists(generatedAssets); - await verifySizes(generatedAssets); - }); - - it('Should generate ios spotlight icons', async () => { - const exportedIcons = Object.values(IosAssets).filter((a) => a.kind === AssetKind.SpotlightIcon); - - const strategy = new IosAssetGenerator(); - let generatedAssets = ((await assets.iosSpotlightIcon?.generate(strategy, ctx.project)) ?? - []) as OutputAsset[]; - expect(generatedAssets.length).toBeGreaterThanOrEqual(0); - expect(generatedAssets.length).toBe(exportedIcons.length); - - await verifyExists(generatedAssets); - await verifySizes(generatedAssets); - }); }); describe('iOS Asset Test - Logo Only', () => { @@ -171,9 +132,6 @@ describe('iOS Asset Test - Logo Only', () => { (a) => [ AssetKind.Icon, - AssetKind.SettingsIcon, - AssetKind.NotificationIcon, - AssetKind.SpotlightIcon, AssetKind.Splash, AssetKind.SplashDark, ].indexOf(a.kind) >= 0, @@ -204,9 +162,6 @@ describe('iOS Asset Test - Logo Only', () => { [ AssetKind.Icon, AssetKind.Splash, - AssetKind.SettingsIcon, - AssetKind.NotificationIcon, - AssetKind.SpotlightIcon, AssetKind.SplashDark, ].indexOf(a.kind) >= 0, );