-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.config.ts
More file actions
176 lines (155 loc) · 5.57 KB
/
Copy pathapp.config.ts
File metadata and controls
176 lines (155 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import type { ConfigContext, ExpoConfig } from '@expo/config';
import { withAppBuildGradle } from 'expo/config-plugins';
import { existsSync } from 'fs';
import { isAbsolute, join, resolve } from 'path';
enum AppVariant {
Development = 'development',
Production = 'production',
}
const resolveAppVariant = (): AppVariant => {
const rawVariant = (process.env.APP_VARIANT ?? AppVariant.Development).trim().toLowerCase();
return rawVariant === AppVariant.Production ? AppVariant.Production : AppVariant.Development;
};
const APP_VARIANT = resolveAppVariant();
const IS_DEV = APP_VARIANT === AppVariant.Development;
const getOptionalEnv = (name: string): string | undefined => {
const value = process.env[name]?.trim();
return value ? value : undefined;
};
const getUniqueIdentifier = () => {
if (IS_DEV) {
return 'com.appcalipse.digitalbrain.dev';
}
return 'com.appcalipse.digitalbrain';
};
const getAppName = () => {
if (IS_DEV) {
return 'Digital Brain Dev';
}
return 'Digital Brain';
};
const requireConfigFile = (relativePath: string, envPathName?: string) => {
const configuredPath = envPathName ? getOptionalEnv(envPathName) : undefined;
const resolvedPath = configuredPath
? isAbsolute(configuredPath)
? configuredPath
: resolve(__dirname, configuredPath)
: join(__dirname, relativePath);
const displayPath = configuredPath ?? relativePath;
if (!existsSync(resolvedPath)) {
throw new Error(
`Missing required config file: ${displayPath} for APP_VARIANT=${APP_VARIANT}.${envPathName ? ` Set ${envPathName} to an absolute or project-relative path when building locally.` : ''}`,
);
}
return resolvedPath;
};
const appJson = require('./app.json');
type PluginEntry = NonNullable<ExpoConfig['plugins']>[number];
const withPlugin = (
plugins: ExpoConfig['plugins'],
pluginName: string,
options?: Record<string, unknown>,
): PluginEntry[] => {
const nextPlugins = [...(plugins ?? [])];
const hasOptions = !!options && Object.keys(options).length > 0;
const nextPlugin: PluginEntry = hasOptions ? [pluginName, options] : pluginName;
const existingPluginIndex = nextPlugins.findIndex((plugin) =>
Array.isArray(plugin) ? plugin[0] === pluginName : plugin === pluginName,
);
if (existingPluginIndex >= 0) {
nextPlugins[existingPluginIndex] = nextPlugin;
} else {
nextPlugins.push(nextPlugin);
}
return nextPlugins;
};
function withSystemDebugKeystore(config: ExpoConfig) {
return withAppBuildGradle(config, (mod) => {
if (mod.modResults.contents) {
mod.modResults.contents = mod.modResults.contents.replace(
/storeFile file\('debug\.keystore'\)/,
'storeFile file("${System.getProperty(\'user.home\')}/.android/debug.keystore")',
);
}
return mod;
});
}
export default ({ config }: ConfigContext): ExpoConfig => {
const appName = getAppName();
const bundleId = getUniqueIdentifier();
const androidGoogleServicesFile = requireConfigFile(
'./google-services.json',
'GOOGLE_SERVICES_FILE',
);
const googleMapsApiKey = process.env.EXPO_PUBLIC_GOOGLE_MAPS_API_KEY;
const buildTimestamp = process.env.EXPO_PUBLIC_BUILD_TIMESTAMP ?? new Date().toISOString();
const appScheme = getOptionalEnv('APP_SCHEME');
const expoOwner = getOptionalEnv('EXPO_ACCOUNT_OWNER');
const easProjectId = getOptionalEnv('EXPO_PUBLIC_EAS_PROJECT_ID');
const googleIosUrlScheme = getOptionalEnv('GOOGLE_IOS_URL_SCHEME');
const extra = {
...(appJson.expo.extra ?? {}),
...(config.extra ?? {}),
buildTimestamp,
...(easProjectId
? {
eas: {
...((appJson.expo.extra as { eas?: Record<string, unknown> } | undefined)?.eas ?? {}),
...((config.extra as { eas?: Record<string, unknown> } | undefined)?.eas ?? {}),
projectId: easProjectId,
},
}
: {}),
};
const merged = {
...appJson.expo,
...config,
extra,
name: appName,
...(appScheme ? { scheme: appScheme } : {}),
...(expoOwner ? { owner: expoOwner } : {}),
ios: {
...(appJson.expo.ios ?? {}),
...(config.ios ?? {}),
bundleIdentifier: bundleId,
},
android: {
...(appJson.expo.android ?? {}),
...(config.android ?? {}),
package: bundleId,
googleServicesFile: androidGoogleServicesFile,
},
};
const pluginsWithMaps = withPlugin(merged.plugins, 'react-native-maps', {
...(googleMapsApiKey ? { androidGoogleMapsApiKey: googleMapsApiKey } : {}),
...(googleMapsApiKey ? { iosGoogleMapsApiKey: googleMapsApiKey } : {}),
});
const pluginsWithGoogleSignin = withPlugin(
pluginsWithMaps,
'@react-native-google-signin/google-signin',
googleIosUrlScheme ? { iosUrlScheme: googleIosUrlScheme } : undefined,
);
const pluginsWithAsset = withPlugin(pluginsWithGoogleSignin, 'expo-asset');
const pluginsWithAudioStudio = withPlugin(pluginsWithAsset, '@siteed/audio-studio', {
enablePhoneStateHandling: false,
enableNotifications: false,
enableBackgroundAudio: false,
enableDeviceDetection: false,
iosBackgroundModes: {
useVoIP: false,
useAudio: false,
useProcessing: false,
useLocation: false,
useExternalAccessory: false,
},
iosConfig: {
microphoneUsageDescription:
'Digital Brain uses your microphone so you can dictate chat messages with on-device Whisper transcription.',
notificationUsageDescription: 'Digital Brain can show recording controls while capturing audio.',
},
});
return withSystemDebugKeystore({
...merged,
plugins: withPlugin(pluginsWithAudioStudio, 'expo-background-task'),
});
};