1import fs from 'fs-extra'; 2import { join } from 'path'; 3 4export type ContentsJsonImageIdiom = 5 | 'iphone' 6 | 'ipad' 7 | 'watchos' 8 | 'ios' 9 | 'ios-marketing' 10 | 'universal'; 11 12export type ContentsJsonImageAppearance = { 13 appearance: 'luminosity'; 14 value: 'dark'; 15}; 16 17export type ContentsJsonImageScale = '1x' | '2x' | '3x'; 18 19export interface ContentsJsonImage { 20 appearances?: ContentsJsonImageAppearance[]; 21 idiom: ContentsJsonImageIdiom; 22 size?: string; 23 scale?: ContentsJsonImageScale; 24 filename?: string; 25 platform?: ContentsJsonImageIdiom; 26} 27 28export interface ContentsJson { 29 images: ContentsJsonImage[]; 30 info: { 31 version: number; 32 author: string; 33 }; 34} 35 36export function createContentsJsonItem(item: ContentsJsonImage): ContentsJsonImage { 37 return item; 38} 39 40/** 41 * Writes the Config.json which is used to assign images to their respective platform, dpi, and idiom. 42 * 43 * @param directory path to add the Contents.json to. 44 * @param contents image json data 45 */ 46export async function writeContentsJsonAsync( 47 directory: string, 48 { images }: Pick<ContentsJson, 'images'> 49): Promise<void> { 50 await fs.ensureDir(directory); 51 52 await fs.writeFile( 53 join(directory, 'Contents.json'), 54 JSON.stringify( 55 { 56 images, 57 info: { 58 version: 1, 59 // common practice is for the tool that generated the icons to be the "author" 60 author: 'expo', 61 }, 62 }, 63 null, 64 2 65 ) 66 ); 67} 68