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jG,CAAC;AApED,sCAoEC;AAED;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,WAAmB;IACjD,MAAM,WAAW,GAAG,0BAAc,CAAC,WAAW,CAAC,CAAC;IAChD,OAAO,WAAI,CAAC,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa;IACnD,OAAO,YAAY,IAAI,IAAI,IAAI,IAAI,KAAK,OAAO,CAAC;AAClD,CAAC","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport { generateImageAsync } from '@expo/image-utils';\nimport * as fs from 'fs-extra';\nimport { join } from 'path';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withDangerousMod } from '../plugins/core-plugins';\nimport * as WarningAggregator from '../utils/warnings';\nimport { ContentsJson, ContentsJsonImageIdiom, writeContentsJsonAsync } from './AssetContents';\nimport { getProjectName } from './utils/Xcodeproj';\n\nexport const withIcons: ConfigPlugin = config => {\n return withDangerousMod(config, [\n 'ios',\n async config => {\n await setIconsAsync(config, config.modRequest.projectRoot);\n return config;\n },\n ]);\n};\n\nconst IMAGE_CACHE_NAME = 'icons';\nconst IMAGESET_PATH = 'Images.xcassets/AppIcon.appiconset';\n\n// Hard-coding seemed like the clearest and safest way to implement the sizes.\nexport const ICON_CONTENTS: {\n idiom: ContentsJsonImageIdiom;\n sizes: { size: number; scales: (1 | 2 | 3)[] }[];\n}[] = [\n {\n idiom: 'iphone',\n sizes: [\n {\n size: 20,\n scales: [2, 3],\n },\n {\n size: 29,\n scales: [1, 2, 3],\n },\n {\n size: 40,\n scales: [2, 3],\n },\n {\n size: 60,\n scales: [2, 3],\n },\n // TODO: 76x76@2x seems unused now\n // {\n // size: 76,\n // scales: [2],\n // },\n ],\n },\n {\n idiom: 'ipad',\n sizes: [\n {\n size: 20,\n scales: [1, 2],\n },\n {\n size: 29,\n scales: [1, 2],\n },\n {\n size: 40,\n scales: [1, 2],\n },\n {\n size: 76,\n scales: [1, 2],\n },\n {\n size: 83.5,\n scales: [2],\n },\n ],\n },\n {\n idiom: 'ios-marketing',\n sizes: [\n {\n size: 1024,\n scales: [1],\n },\n ],\n },\n];\n\nexport function getIcons(config: Pick): string | null {\n // No support for empty strings.\n return config.ios?.icon || config.icon || null;\n}\n\nexport async function setIconsAsync(config: ExpoConfig, projectRoot: string) {\n const icon = getIcons(config);\n if (!icon) {\n WarningAggregator.addWarningIOS(\n 'icon',\n 'This is the image that your app uses on your home screen, you will need to configure it manually.'\n );\n return;\n }\n\n // Something like projectRoot/ios/MyApp/\n const iosNamedProjectRoot = getIosNamedProjectPath(projectRoot);\n\n // Ensure the Images.xcassets/AppIcon.appiconset path exists\n await fs.ensureDir(join(iosNamedProjectRoot, IMAGESET_PATH));\n\n // Store the image JSON data for assigning via the Contents.json\n const imagesJson: ContentsJson['images'] = [];\n\n // keep track of icons that have been generated so we can reuse them in the Contents.json\n const generatedIcons: Record = {};\n\n for (const platform of ICON_CONTENTS) {\n const isMarketing = platform.idiom === 'ios-marketing';\n for (const { size, scales } of platform.sizes) {\n for (const scale of scales) {\n // The marketing icon is special because it makes no sense.\n const filename = isMarketing ? 'ItunesArtwork@2x.png' : getAppleIconName(size, scale);\n // Only create an image that hasn't already been generated.\n if (!(filename in generatedIcons)) {\n const iconSizePx = size * scale;\n\n // Using this method will cache the images in `.expo` based on the properties used to generate them.\n // this method also supports remote URLs and using the global sharp instance.\n const { source } = await generateImageAsync(\n { projectRoot, cacheType: IMAGE_CACHE_NAME },\n {\n src: icon,\n name: filename,\n width: iconSizePx,\n height: iconSizePx,\n removeTransparency: true,\n // The icon should be square, but if it's not then it will be cropped.\n resizeMode: 'cover',\n // Force the background color to solid white to prevent any transparency.\n // TODO: Maybe use a more adaptive option based on the icon color?\n backgroundColor: '#ffffff',\n }\n );\n // Write image buffer to the file system.\n const assetPath = join(iosNamedProjectRoot, IMAGESET_PATH, filename);\n await fs.writeFile(assetPath, source);\n // Save a reference to the generated image so we don't create a duplicate.\n generatedIcons[filename] = true;\n }\n imagesJson.push({\n idiom: platform.idiom,\n size: `${size}x${size}`,\n // @ts-ignore: template types not supported in TS yet\n scale: `${scale}x`,\n filename,\n });\n }\n }\n }\n\n // Finally, write the Config.json\n await writeContentsJsonAsync(join(iosNamedProjectRoot, IMAGESET_PATH), { images: imagesJson });\n}\n\n/**\n * Return the project's named iOS path: ios/MyProject/\n *\n * @param projectRoot Expo project root path.\n */\nfunction getIosNamedProjectPath(projectRoot: string): string {\n const projectName = getProjectName(projectRoot);\n return join(projectRoot, 'ios', projectName);\n}\n\nfunction getAppleIconName(size: number, scale: number): string {\n return `App-Icon-${size}x${size}@${scale}x.png`;\n}\n"]}