Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

app.config.ts

471 lines17.0 KB

1import type { ExpoConfig } from "expo/config";
2​
3import { BRAND_ASSET_PATHS } from "../../scripts/lib/brand-assets.ts";
4import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
5​
6type AppVariant = "development" | "preview" | "production";
7​
8const repoEnv = loadRepoEnv();
9Object.assign(process.env, repoEnv);
10​
11const APP_VARIANT = resolveAppVariant(repoEnv.APP_VARIANT);
12const isIosPersonalTeamBuild = repoEnv.T3CODE_IOS_PERSONAL_TEAM === "1";
13const runtimeVersionPolicy =
14 process.env.MOBILE_VERSION_POLICY ??
15 (APP_VARIANT === "development" ? "appVersion" : "fingerprint");
16​
17const personalTeamBundleIdentifier = repoEnv.T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID?.trim();
18const IOS_BUNDLE_IDENTIFIER_PATTERN = /^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/;
19​
20// Compiled into the native project. Without a relay, Observe's native side could dispatch to
21// Expo's own ingest before observe.ts turns it off; `.invalid` never resolves (RFC 6761).
22const observeEndpointUrl = repoEnv.T3CODE_RELAY_URL?.trim()
23 ? new URL("/v1/mobile/observe", repoEnv.T3CODE_RELAY_URL.trim()).toString()
24 : "https://observe.invalid";
25​
26const fromRepoRoot = (relativePath: string) => `../../${relativePath}`;
27const androidAdaptiveForeground = "./assets/android-icon-foreground.png";
28​
29if (
30 isIosPersonalTeamBuild &&
31 (!personalTeamBundleIdentifier ||
32 !IOS_BUNDLE_IDENTIFIER_PATTERN.test(personalTeamBundleIdentifier))
33) {
34 throw new Error(
35 "T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID must be a reverse-DNS identifier such as com.example.t3code when T3CODE_IOS_PERSONAL_TEAM=1.",
36 );
38​
39const DEVELOPMENT_ASSETS = {
40 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
41 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIconComposerProject),
42 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
43 androidAdaptiveForeground,
44 androidAdaptiveBackgroundColor: "#347FF8",
45 androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
46 androidSplashIcon: "./assets/android-splash-icon-dev.png",
47 androidMonochromeIcon: "./assets/android-icon-mark.png",
48 androidNotificationIcon: "./assets/android-notification-icon.png",
49 androidNotificationColor: "#00639B",
50} as const;
51​
52const PREVIEW_ASSETS = {
53 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
54 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIconComposerProject),
55 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
56 androidAdaptiveForeground,
57 androidAdaptiveBackgroundColor: "#111533",
58 androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
59 androidSplashIcon: "./assets/android-splash-icon-nightly.png",
60 androidMonochromeIcon: "./assets/android-icon-mark.png",
61 androidNotificationIcon: "./assets/android-notification-icon.png",
62 androidNotificationColor: "#7565C7",
63} as const;
64​
65const RELEASE_ASSETS = {
66 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
67 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIconComposerProject),
68 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
69 androidAdaptiveForeground,
70 androidAdaptiveBackgroundColor: "#000000",
71 androidAdaptiveBackgroundImage: undefined,
72 androidSplashIcon: "./assets/android-splash-icon-prod.png",
73 androidMonochromeIcon: "./assets/android-icon-mark.png",
74 androidNotificationIcon: "./assets/android-notification-icon.png",
75 androidNotificationColor: "#FFFFFF",
76} as const;
77​
78const VARIANT_CONFIG = {
79 development: {
80 appName: "T3 Code Dev",
81 scheme: "t3code-dev",
82 iosBundleIdentifier: "com.t3tools.t3code.dev",
83 androidPackage: "com.t3tools.t3code.dev",
84 relyingParty: "clerk.t3.codes",
85 assets: DEVELOPMENT_ASSETS,
86 },
87 preview: {
88 appName: "T3 Code Preview",
89 scheme: "t3code-preview",
90 iosBundleIdentifier: "com.t3tools.t3code.preview",
91 androidPackage: "com.t3tools.t3code.preview",
92 relyingParty: "clerk.t3.codes",
93 assets: PREVIEW_ASSETS,
94 },
95 production: {
96 appName: "T3 Code",
97 scheme: "t3code",
98 iosBundleIdentifier: "com.t3tools.t3code",
99 androidPackage: "com.t3tools.t3code",
100 relyingParty: "clerk.t3.codes",
101 assets: RELEASE_ASSETS,
102 },
103} as const;
104​
105function resolveAppVariant(value: string | undefined): AppVariant {
106 switch (value) {
107 case "development":
108 case "preview":
109 case "production":
110 return value;
111 case undefined:
112 return "production";
113 default:
114 throw new Error("APP_VARIANT must be development, preview, or production.");
115 }
117​
118const variant = VARIANT_CONFIG[APP_VARIANT];
119const iosBundleIdentifier = isIosPersonalTeamBuild
120 ? personalTeamBundleIdentifier!
121 : variant.iosBundleIdentifier;
122​
123const dmSansFonts = {
124 regular: "@expo-google-fonts/dm-sans/400Regular/DMSans_400Regular.ttf",
125 medium: "@expo-google-fonts/dm-sans/500Medium/DMSans_500Medium.ttf",
126 bold: "@expo-google-fonts/dm-sans/700Bold/DMSans_700Bold.ttf",
127} as const;
128​
129const widgetsPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
130 "expo-widgets",
131 {
132 bundleIdentifier: `${iosBundleIdentifier}.widgets`,
133 groupIdentifier: `group.${iosBundleIdentifier}`,
134 enablePushNotifications: true,
135 // Frequent updates need the iOS entitlement to avoid early throttling.
136 frequentUpdates: true,
137 enableAndroid: true,
138 widgets: [
139 {
140 name: "SubscriptionUsage",
141 displayName: "Subscription usage",
142 description: "Subscription quotas from your connected T3 Code environments.",
143 ios: {
144 configuration: {
145 title: "Subscription usage",
146 description:
147 "Both shows Session and Weekly when available. The Lock Screen shows the tightest selected limit.",
148 parameters: {
149 codexPeriod: {
150 title: "Codex limits",
151 type: "enum",
152 default: "auto",
153 values: [
154 { name: "Both", value: "auto" },
155 { name: "Session", value: "session" },
156 { name: "Weekly", value: "weekly" },
157 ],
158 },
159 claudePeriod: {
160 title: "Claude limits",
161 type: "enum",
162 default: "auto",
163 values: [
164 { name: "Both", value: "auto" },
165 { name: "Session", value: "session" },
166 { name: "Weekly", value: "weekly" },
167 ],
168 },
169 },
170 },
171 supportedFamilies: [
172 "systemSmall",
173 "systemMedium",
174 "systemLarge",
175 "systemExtraLarge",
176 "accessoryRectangular",
177 ],
178 },
179 android: {
180 minWidth: 250,
181 minHeight: 180,
182 targetCellWidth: 4,
183 targetCellHeight: 3,
184 resizeMode: "both",
185 // The embedded layout renders before first launch; publishing replaces it with stored props.
186 initialLayout: "./src/widgets/SubscriptionUsage.android.tsx",
187 },
188 },
189 {
190 name: "AgentActivity",
191 displayName: "Agent Activity",
192 description: "Shows the current state of active T3 Code agents.",
193 android: null,
194 ios: { supportedFamilies: ["systemSmall", "systemMedium", "accessoryRectangular"] },
195 },
196 ],
197 },
198];
199​
200const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
201 "expo-sharing",
202 {
203 ios: {
204 // Personal Teams cannot sign App Groups or extension targets; keep local builds usable.
205 enabled: !isIosPersonalTeamBuild,
206 extensionBundleIdentifier: `${iosBundleIdentifier}.sharing`,
207 appGroupId: `group.${iosBundleIdentifier}`,
208 activationRule: {
209 supportsText: true,
210 supportsWebUrlWithMaxCount: 1,
211 supportsImageWithMaxCount: 8,
212 supportsMovieWithMaxCount: 8,
213 supportsFileWithMaxCount: 8,
214 },
215 },
216 android: {
217 enabled: true,
218 singleShareMimeTypes: ["*/*"],
219 multipleShareMimeTypes: ["*/*"],
220 },
221 },
222];
223​
224// Match iOS PostScript names on Android so RN and the native composer share fonts before runtime loading.
225​
226const config: ExpoConfig = {
227 name: variant.appName,
228 slug: "t3-code",
229 platforms: ["ios", "android"],
230 scheme: variant.scheme,
231 version: repoEnv.T3CODE_MOBILE_VERSION ?? "2.2.0",
232 runtimeVersion: {
233 // Skip costly fingerprinting on dev launches; preview and production OTAs require matching native projects.
234 policy: runtimeVersionPolicy,
235 },
236 orientation: "portrait",
237 icon: variant.assets.appIcon,
238 userInterfaceStyle: "automatic",
239 updates: {
240 enabled: repoEnv.T3CODE_MOBILE_UPDATES_ENABLED !== "0",
241 url: "https://u.expo.dev/d763fcb8-d37c-41ea-a773-b54a0ab4a454",
242 checkAutomatically: "ON_LOAD",
243 fallbackToCacheTimeout: 0,
244 },
245 ios: {
246 icon: variant.assets.iosIcon,
247 supportsTablet: true,
248 requireFullScreen: process.env.T3_SHOWCASE_CAPTURE_BUILD === "1",
249 bundleIdentifier: iosBundleIdentifier,
250 // Avoid Personal Team fallback: it cannot sign App Groups, Apple sign-in or push entitlements.
251 appleTeamId: "ARK85ZXQ4Z",
252 associatedDomains: [
253 `applinks:${variant.relyingParty}`,
254 `webcredentials:${variant.relyingParty}`,
255 ],
256 entitlements: {
257 "keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
258 },
259 infoPlist: {
260 UISupportedInterfaceOrientations: [
261 "UIInterfaceOrientationPortrait",
262 "UIInterfaceOrientationLandscapeLeft",
263 "UIInterfaceOrientationLandscapeRight",
264 ],
265 NSAppTransportSecurity: {
266 NSAllowsArbitraryLoads: true,
267 },
268 NSLocalNetworkUsageDescription:
269 "Allow T3 Code to connect to T3 Code servers on your local network or tailnet.",
270 NSPhotoLibraryAddUsageDescription: "Allow T3 Code to save images to your photo library.",
271 // System picture in picture needs background audio to start and survive outside the app.
272 UIBackgroundModes: ["audio"],
273 ITSAppUsesNonExemptEncryption: false,
274 // Capture builds disable multitasking because iPadOS otherwise ignores orientation requests.
275 ...(process.env.T3_SHOWCASE_CAPTURE_BUILD === "1"
276 ? {
277 "UISupportedInterfaceOrientations~ipad": [
278 "UIInterfaceOrientationPortrait",
279 "UIInterfaceOrientationPortraitUpsideDown",
280 "UIInterfaceOrientationLandscapeLeft",
281 "UIInterfaceOrientationLandscapeRight",
282 ],
283 }
284 : {}),
285 },
286 },
287 android: {
288 icon: variant.assets.appIcon,
289 package: variant.androidPackage,
290 ...(repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE
291 ? { googleServicesFile: repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE }
292 : {}),
293 adaptiveIcon: {
294 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
295 ...(variant.assets.androidAdaptiveBackgroundImage
296 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
297 : {}),
298 foregroundImage: variant.assets.androidAdaptiveForeground,
299 monochromeImage: variant.assets.androidMonochromeIcon,
300 },
301 // JS back dispatch needs RN's Android 16 shim and withAndroidPredictiveBackCompat on Android 13-15.
302 predictiveBackGestureEnabled: true,
303 // expo-sensors declares this for its pedometer, which the app does not use.
304 blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
305 },
306 web: {
307 favicon: variant.assets.appIcon,
308 },
309 plugins: [
310 "expo-asset",
311 "react-native-pdf-jsi",
312 [
313 "expo-font",
314 {
315 ios: {
316 fonts: [dmSansFonts.regular, dmSansFonts.medium, dmSansFonts.bold],
317 },
318 android: {
319 fonts: [
320 {
321 fontFamily: "DMSans-Regular",
322 fontDefinitions: [{ path: dmSansFonts.regular, weight: 400 }],
323 },
324 {
325 fontFamily: "DMSans-Medium",
326 fontDefinitions: [{ path: dmSansFonts.medium, weight: 500 }],
327 },
328 {
329 fontFamily: "DMSans-Bold",
330 fontDefinitions: [{ path: dmSansFonts.bold, weight: 700 }],
331 },
332 ],
333 },
334 },
335 ],
336 "expo-secure-store",
337 "expo-sqlite",
338 ...(isIosPersonalTeamBuild
339 ? [sharingPlugin]
340 : ["./plugins/withShareExtensionDisplayName.cjs", sharingPlugin]),
341 [
342 "expo-notifications",
343 {
344 icon: variant.assets.androidNotificationIcon,
345 color: variant.assets.androidNotificationColor,
346 mode: APP_VARIANT === "development" ? "development" : "production",
347 },
348 ],
349 // Gate Clerk here: withoutIosPersonalTeamCapabilities runs too early to strip its entitlement.
350 ["@clerk/expo", { theme: "./clerk-theme.json", appleSignIn: !isIosPersonalTeamBuild }],
351 "expo-web-browser",
352 [
353 "expo-quick-actions",
354 {
355 androidIcons: {
356 shortcut_icon: {
357 foregroundImage: variant.assets.androidAdaptiveForeground,
358 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
359 ...(variant.assets.androidAdaptiveBackgroundImage
360 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
361 : {}),
362 },
363 },
364 },
365 ],
366 [
367 "expo-audio",
368 {
369 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
370 recordAudioAndroid: false,
371 enableBackgroundPlayback: false,
372 enableBackgroundRecording: false,
373 },
374 ],
375 [
376 "expo-camera",
377 {
378 cameraPermission: "Allow T3 Code to access your camera so you can scan pairing QR codes.",
379 microphonePermission: false,
380 barcodeScannerEnabled: true,
381 recordAudioAndroid: false,
382 },
383 ],
384 ["expo-image-picker", { photosPermission: false, microphonePermission: false }],
385 [
386 "expo-splash-screen",
387 {
388 image: variant.assets.splashIcon,
389 resizeMode: "contain",
390 backgroundColor: "#ffffff",
391 imageWidth: 220,
392 dark: {
393 image: variant.assets.splashIcon,
394 backgroundColor: "#0a0a0a",
395 },
396 android: {
397 // Android 12+ masks the central two thirds of the 288dp canvas; adaptive layers avoid clipped corners.
398 image: variant.assets.androidSplashIcon,
399 imageWidth: 288,
400 dark: { image: variant.assets.androidSplashIcon },
401 },
402 },
403 ],
404 [
405 "expo-build-properties",
406 {
407 android: {
408 minSdkVersion: 24,
409 // SDK 58 lacks Kotlin 2.3's runtime-inert annotation. R8 needs explicit InputMerger constructors for widgets.
410 extraProguardRules: [
411 "-dontwarn kotlin.MustUseReturnValues",
412 "-keep class * extends androidx.work.InputMerger { <init>(); }",
413 ].join("\n"),
414 },
415 ios: {
416 deploymentTarget: "18.0",
417 // AppCheckCore 11.3+ includes Swift and needs module maps for these Objective-C dependencies.
418 extraPods: [
419 { name: "GoogleUtilities", modular_headers: true },
420 { name: "RecaptchaInterop", modular_headers: true },
421 ],
422 },
423 },
424 ],
425 "./plugins/withIosCocoaPodsUuidCache.cjs",
426 // Compile out the unused pedometer to avoid an iOS motion purpose string.
427 ["expo-sensors", { motionPermission: false }],
428 // Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
429 ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
430 "./plugins/withAndroidNetworkSecurityConfig.cjs",
431 "./plugins/withAndroidGradleHeap.cjs",
432 "./plugins/withAndroidInputBackground.cjs",
433 "./plugins/withAndroidModernPopupMenu.cjs",
434 "./plugins/withAndroidModernAlertDialog.cjs",
435 "./plugins/withAndroidPredictiveBackCompat.cjs",
436 "./plugins/withAndroidTabletOrientation.cjs",
437 ...(isIosPersonalTeamBuild ? ["./plugins/withoutIosPersonalTeamCapabilities.cjs"] : []),
438 ],
439 extra: {
440 appVariant: APP_VARIANT,
441 iosPersonalTeamBuild: isIosPersonalTeamBuild,
442 relay: {
443 url: repoEnv.T3CODE_RELAY_URL ?? null,
444 },
445 clerk: {
446 publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
447 jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
448 },
449 // Clerk reads these exact names at prebuild. Omit unset values: manifest null becomes truthy {}.
450 EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
451 EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
452 EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID,
453 EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME,
454 observability: {
455 tracesUrl: repoEnv.EXPO_PUBLIC_OTLP_TRACES_URL ?? "https://api.axiom.co/v1/traces",
456 tracesDataset: repoEnv.EXPO_PUBLIC_OTLP_TRACES_DATASET ?? null,
457 tracesToken: repoEnv.EXPO_PUBLIC_OTLP_TRACES_TOKEN ?? null,
458 },
459 eas: {
460 projectId: "d763fcb8-d37c-41ea-a773-b54a0ab4a454",
461 observe: { endpointUrl: observeEndpointUrl },
462 },
463 },
464 owner: "pingdotgg",
465 experiments: {
466 // Metro only runs babel-plugin-react-compiler when this is set; see src/reactCompilerCoverage.test.ts.
467 reactCompiler: true,
468 },
469};
470​
471export default config;