1import { ExpoConfig } from '@expo/config-types';
2
3import { createInfoPlistPluginWithPropertyGuard } from '../plugins/ios-plugins';
4import { InfoPlist } from './IosConfig.types';
5
6export const withVersion = createInfoPlistPluginWithPropertyGuard(
7  setVersion,
8  {
9    infoPlistProperty: 'CFBundleShortVersionString',
10    expoConfigProperty: 'version',
11  },
12  'withVersion'
13);
14
15export const withBuildNumber = createInfoPlistPluginWithPropertyGuard(
16  setBuildNumber,
17  {
18    infoPlistProperty: 'CFBundleVersion',
19    expoConfigProperty: 'ios.buildNumber',
20  },
21  'withBuildNumber'
22);
23
24export function getVersion(config: Pick<ExpoConfig, 'version'>) {
25  return config.version || '1.0.0';
26}
27
28export function setVersion(config: Pick<ExpoConfig, 'version'>, infoPlist: InfoPlist): InfoPlist {
29  return {
30    ...infoPlist,
31    CFBundleShortVersionString: getVersion(config),
32  };
33}
34
35export function getBuildNumber(config: Pick<ExpoConfig, 'ios'>) {
36  return config.ios?.buildNumber ? config.ios.buildNumber : '1';
37}
38
39export function setBuildNumber(config: Pick<ExpoConfig, 'ios'>, infoPlist: InfoPlist): InfoPlist {
40  return {
41    ...infoPlist,
42    CFBundleVersion: getBuildNumber(config),
43  };
44}
45