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