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

app.config.ts

494 lines18.5 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​
20const fromRepoRoot = (relativePath: string) => `../../${relativePath}`;
21const androidAdaptiveForeground = "./assets/android-icon-foreground.png";
22​
23if (
24 isIosPersonalTeamBuild &&
25 (!personalTeamBundleIdentifier ||
26 !IOS_BUNDLE_IDENTIFIER_PATTERN.test(personalTeamBundleIdentifier))
27) {
28 throw new Error(
29 "T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID must be a reverse-DNS identifier such as com.example.t3code when T3CODE_IOS_PERSONAL_TEAM=1.",
30 );
32​
33const DEVELOPMENT_ASSETS = {
34 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
35 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIconComposerProject),
36 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
37 androidAdaptiveForeground,
38 androidAdaptiveBackgroundColor: "#347FF8",
39 androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
40 androidSplashIcon: "./assets/android-splash-icon-dev.png",
41 androidMonochromeIcon: "./assets/android-icon-mark.png",
42 androidNotificationIcon: "./assets/android-notification-icon.png",
43 androidNotificationColor: "#00639B",
44} as const;
45​
46const PREVIEW_ASSETS = {
47 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
48 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIconComposerProject),
49 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
50 androidAdaptiveForeground,
51 androidAdaptiveBackgroundColor: "#111533",
52 androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
53 androidSplashIcon: "./assets/android-splash-icon-nightly.png",
54 androidMonochromeIcon: "./assets/android-icon-mark.png",
55 androidNotificationIcon: "./assets/android-notification-icon.png",
56 androidNotificationColor: "#7565C7",
57} as const;
58​
59const RELEASE_ASSETS = {
60 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
61 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIconComposerProject),
62 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
63 androidAdaptiveForeground,
64 androidAdaptiveBackgroundColor: "#000000",
65 androidAdaptiveBackgroundImage: undefined,
66 androidSplashIcon: "./assets/android-splash-icon-prod.png",
67 androidMonochromeIcon: "./assets/android-icon-mark.png",
68 androidNotificationIcon: "./assets/android-notification-icon.png",
69 androidNotificationColor: "#FFFFFF",
70} as const;
71​
72const VARIANT_CONFIG = {
73 development: {
74 appName: "T3 Code Dev",
75 scheme: "t3code-dev",
76 iosBundleIdentifier: "com.t3tools.t3code.dev",
77 androidPackage: "com.t3tools.t3code.dev",
78 relyingParty: "clerk.t3.codes",
79 assets: DEVELOPMENT_ASSETS,
80 },
81 preview: {
82 appName: "T3 Code Preview",
83 scheme: "t3code-preview",
84 iosBundleIdentifier: "com.t3tools.t3code.preview",
85 androidPackage: "com.t3tools.t3code.preview",
86 relyingParty: "clerk.t3.codes",
87 assets: PREVIEW_ASSETS,
88 },
89 production: {
90 appName: "T3 Code",
91 scheme: "t3code",
92 iosBundleIdentifier: "com.t3tools.t3code",
93 androidPackage: "com.t3tools.t3code",
94 relyingParty: "clerk.t3.codes",
95 assets: RELEASE_ASSETS,
96 },
97} as const;
98​
99function resolveAppVariant(value: string | undefined): AppVariant {
100 switch (value) {
101 case "development":
102 case "preview":
103 case "production":
104 return value;
105 default:
106 return "production";
107 }
109​
110const variant = VARIANT_CONFIG[APP_VARIANT];
111const iosBundleIdentifier = isIosPersonalTeamBuild
112 ? personalTeamBundleIdentifier!
113 : variant.iosBundleIdentifier;
114​
115const dmSansFonts = {
116 regular: "@expo-google-fonts/dm-sans/400Regular/DMSans_400Regular.ttf",
117 medium: "@expo-google-fonts/dm-sans/500Medium/DMSans_500Medium.ttf",
118 bold: "@expo-google-fonts/dm-sans/700Bold/DMSans_700Bold.ttf",
119} as const;
120​
121const widgetsPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
122 "expo-widgets",
123 {
124 bundleIdentifier: `${iosBundleIdentifier}.widgets`,
125 groupIdentifier: `group.${iosBundleIdentifier}`,
126 enablePushNotifications: true,
127 // Agent activity can update many times an hour; without the
128 // frequent-updates entitlement iOS throttles the update budget sooner.
129 frequentUpdates: true,
130 enableAndroid: true,
131 widgets: [
132 {
133 name: "SubscriptionUsage",
134 displayName: "Subscription usage",
135 description: "Subscription quotas from your connected T3 Code environments.",
136 ios: {
137 configuration: {
138 title: "Subscription usage",
139 description:
140 "Both shows Session and Weekly when available. The Lock Screen shows the tightest selected limit.",
141 parameters: {
142 codexPeriod: {
143 title: "Codex limits",
144 type: "enum",
145 default: "auto",
146 values: [
147 { name: "Both", value: "auto" },
148 { name: "Session", value: "session" },
149 { name: "Weekly", value: "weekly" },
150 ],
151 },
152 claudePeriod: {
153 title: "Claude limits",
154 type: "enum",
155 default: "auto",
156 values: [
157 { name: "Both", value: "auto" },
158 { name: "Session", value: "session" },
159 { name: "Weekly", value: "weekly" },
160 ],
161 },
162 },
163 },
164 supportedFamilies: [
165 "systemSmall",
166 "systemMedium",
167 "systemLarge",
168 "systemExtraLarge",
169 "accessoryRectangular",
170 ],
171 },
172 android: {
173 minWidth: 250,
174 minHeight: 180,
175 targetCellWidth: 4,
176 targetCellHeight: 3,
177 resizeMode: "both",
178 // Embeds the layout in the APK so the widget renders before the app
179 // has run once; the app replaces it with stored props on publish.
180 initialLayout: "./src/widgets/SubscriptionUsage.android.tsx",
181 },
182 },
183 {
184 name: "AgentActivity",
185 displayName: "Agent Activity",
186 description: "Shows the current state of active T3 Code agents.",
187 android: null,
188 ios: { supportedFamilies: ["systemSmall", "systemMedium", "accessoryRectangular"] },
189 },
190 ],
191 },
192];
193​
194const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
195 "expo-sharing",
196 {
197 ios: {
198 // Personal Teams cannot sign App Groups or extension targets. Keep the
199 // reduced-capability local build usable while release builds expose the
200 // real system share target.
201 enabled: !isIosPersonalTeamBuild,
202 extensionBundleIdentifier: `${iosBundleIdentifier}.sharing`,
203 appGroupId: `group.${iosBundleIdentifier}`,
204 activationRule: {
205 supportsText: true,
206 supportsWebUrlWithMaxCount: 1,
207 supportsImageWithMaxCount: 8,
208 supportsMovieWithMaxCount: 8,
209 supportsFileWithMaxCount: 8,
210 },
211 },
212 android: {
213 enabled: true,
214 singleShareMimeTypes: ["*/*"],
215 multipleShareMimeTypes: ["*/*"],
216 },
217 },
218];
219​
220// These aliases match the fonts' PostScript names on iOS. Register the same
221// names on Android so React Native and the native composer use one set of
222// family names without waiting for runtime font loading.
223​
224const config: ExpoConfig = {
225 name: variant.appName,
226 slug: "t3-code",
227 platforms: ["ios", "android"],
228 scheme: variant.scheme,
229 version: repoEnv.T3CODE_MOBILE_VERSION ?? "2.0.0",
230 runtimeVersion: {
231 // Development manifests resolve on every launch, so avoid fingerprint's
232 // expensive native-project calculation there. Preview and production stay
233 // fingerprinted so OTAs only reach binaries with 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 // Pin code signing to the T3 Tools team so non-interactive `expo run:ios`
251 // does not fall back to a personal team (which cannot sign app groups,
252 // Sign in with Apple, or push notification entitlements).
253 appleTeamId: "ARK85ZXQ4Z",
254 associatedDomains: [
255 `applinks:${variant.relyingParty}`,
256 `webcredentials:${variant.relyingParty}`,
257 ],
258 entitlements: {
259 "keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
260 },
261 infoPlist: {
262 UISupportedInterfaceOrientations: [
263 "UIInterfaceOrientationPortrait",
264 "UIInterfaceOrientationLandscapeLeft",
265 "UIInterfaceOrientationLandscapeRight",
266 ],
267 NSAppTransportSecurity: {
268 NSAllowsArbitraryLoads: true,
269 },
270 NSLocalNetworkUsageDescription:
271 "Allow T3 Code to connect to T3 Code servers on your local network or tailnet.",
272 NSPhotoLibraryAddUsageDescription: "Allow T3 Code to save images to your photo library.",
273 // "Audio, AirPlay, and Picture in Picture": the browser screen's system
274 // picture in picture needs it to start and to stay up outside the app.
275 UIBackgroundModes: ["audio"],
276 ITSAppUsesNonExemptEncryption: false,
277 // The App Store screenshot harness rotates the iPad interface from
278 // inside the app (CI denies osascript the Accessibility access that
279 // Simulator menu scripting needs), and iPadOS ignores programmatic
280 // orientation requests for multitasking-capable apps — so the capture
281 // build opts out of multitasking and declares landscape support.
282 ...(process.env.T3_SHOWCASE_CAPTURE_BUILD === "1"
283 ? {
284 "UISupportedInterfaceOrientations~ipad": [
285 "UIInterfaceOrientationPortrait",
286 "UIInterfaceOrientationPortraitUpsideDown",
287 "UIInterfaceOrientationLandscapeLeft",
288 "UIInterfaceOrientationLandscapeRight",
289 ],
290 }
291 : {}),
292 },
293 },
294 android: {
295 icon: variant.assets.appIcon,
296 package: variant.androidPackage,
297 ...(repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE
298 ? { googleServicesFile: repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE }
299 : {}),
300 adaptiveIcon: {
301 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
302 ...(variant.assets.androidAdaptiveBackgroundImage
303 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
304 : {}),
305 foregroundImage: variant.assets.androidAdaptiveForeground,
306 monochromeImage: variant.assets.androidMonochromeIcon,
307 },
308 // Opts into OnBackInvokedCallback-based back dispatch (Android 13+).
309 // JS back handling survives it via react-native's Android 16 shim plus
310 // withAndroidPredictiveBackCompat on Android 13-15.
311 predictiveBackGestureEnabled: true,
312 // expo-sensors declares this for its pedometer, which the app does not use.
313 blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
314 },
315 web: {
316 favicon: variant.assets.appIcon,
317 },
318 plugins: [
319 "expo-asset",
320 [
321 "expo-font",
322 {
323 ios: {
324 fonts: [dmSansFonts.regular, dmSansFonts.medium, dmSansFonts.bold],
325 },
326 android: {
327 fonts: [
328 {
329 fontFamily: "DMSans-Regular",
330 fontDefinitions: [{ path: dmSansFonts.regular, weight: 400 }],
331 },
332 {
333 fontFamily: "DMSans-Medium",
334 fontDefinitions: [{ path: dmSansFonts.medium, weight: 500 }],
335 },
336 {
337 fontFamily: "DMSans-Bold",
338 fontDefinitions: [{ path: dmSansFonts.bold, weight: 700 }],
339 },
340 ],
341 },
342 },
343 ],
344 "expo-secure-store",
345 "expo-sqlite",
346 ...(isIosPersonalTeamBuild
347 ? [sharingPlugin]
348 : ["./plugins/withShareExtensionDisplayName.cjs", sharingPlugin]),
349 [
350 "expo-notifications",
351 {
352 icon: variant.assets.androidNotificationIcon,
353 color: variant.assets.androidNotificationColor,
354 mode: APP_VARIANT === "development" ? "development" : "production",
355 },
356 ],
357 // appleSignIn must be gated here: withoutIosPersonalTeamCapabilities.cjs runs before
358 // plugins earlier in this array, so it cannot strip the entitlement Clerk would add.
359 ["@clerk/expo", { theme: "./clerk-theme.json", appleSignIn: !isIosPersonalTeamBuild }],
360 "expo-web-browser",
361 [
362 "expo-quick-actions",
363 {
364 // Adaptive launcher-shortcut icon; referenced by resource name from
365 // the shortcut items set in src/features/shortcuts.
366 androidIcons: {
367 shortcut_icon: {
368 foregroundImage: variant.assets.androidAdaptiveForeground,
369 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
370 ...(variant.assets.androidAdaptiveBackgroundImage
371 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
372 : {}),
373 },
374 },
375 },
376 ],
377 [
378 "expo-audio",
379 {
380 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
381 recordAudioAndroid: false,
382 enableBackgroundPlayback: false,
383 enableBackgroundRecording: false,
384 },
385 ],
386 [
387 "expo-camera",
388 {
389 cameraPermission: "Allow T3 Code to access your camera so you can scan pairing QR codes.",
390 microphonePermission: false,
391 barcodeScannerEnabled: true,
392 recordAudioAndroid: false,
393 },
394 ],
395 ["expo-image-picker", { photosPermission: false, microphonePermission: false }],
396 [
397 "expo-splash-screen",
398 {
399 image: variant.assets.splashIcon,
400 resizeMode: "contain",
401 backgroundColor: "#ffffff",
402 imageWidth: 220,
403 dark: {
404 image: variant.assets.splashIcon,
405 backgroundColor: "#0a0a0a",
406 },
407 android: {
408 // Android 12+ masks the splash icon to a circle over the central two thirds of
409 // its 288dp canvas, so the iOS export's corners get cut. A full-canvas image of
410 // the composed adaptive layers puts the wordmark in the same frame the launcher
411 // icon uses.
412 image: variant.assets.androidSplashIcon,
413 imageWidth: 288,
414 dark: { image: variant.assets.androidSplashIcon },
415 },
416 },
417 ],
418 [
419 "expo-build-properties",
420 {
421 android: {
422 minSdkVersion: 24,
423 // kotlinx-io uses Kotlin 2.3's return-value checker annotation, while
424 // SDK 58 builds with Kotlin 2.2. It has no runtime behavior.
425 // WorkManager 2.9 keeps InputMerger classes but not their constructors,
426 // and R8 full mode no longer keeps a default constructor implicitly.
427 // Without it no work request can start, so the Glance session behind
428 // the widget never renders and it stays on "Loading widget".
429 extraProguardRules: [
430 "-dontwarn kotlin.MustUseReturnValues",
431 "-keep class * extends androidx.work.InputMerger { <init>(); }",
432 ].join("\n"),
433 },
434 ios: {
435 deploymentTarget: "18.0",
436 // AppCheckCore 11.3+ includes Swift and needs module maps for these Objective-C dependencies.
437 extraPods: [
438 { name: "GoogleUtilities", modular_headers: true },
439 { name: "RecaptchaInterop", modular_headers: true },
440 ],
441 },
442 },
443 ],
444 "./plugins/withIosCocoaPodsUuidCache.cjs",
445 // Only the accelerometer is used (device viewer shake). Compile out the
446 // pedometer so iOS needs no motion purpose string.
447 ["expo-sensors", { motionPermission: false }],
448 // Must be listed BEFORE expo-widgets: same-type mods run last-registered-
449 // first, so registering earlier makes this plugin's mods run AFTER
450 // expo-widgets' — its dangerous mod wipes ios/ExpoWidgetsTarget/ (which
451 // would delete the asset catalog) and its xcodeproj mod creates the widget
452 // target (which must exist before the compile phase can be attached).
453 ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
454 "./plugins/withAndroidCleartextTraffic.cjs",
455 "./plugins/withAndroidGradleHeap.cjs",
456 "./plugins/withAndroidInputBackground.cjs",
457 "./plugins/withAndroidModernPopupMenu.cjs",
458 "./plugins/withAndroidModernAlertDialog.cjs",
459 "./plugins/withAndroidPredictiveBackCompat.cjs",
460 "./plugins/withAndroidTabletOrientation.cjs",
461 ...(isIosPersonalTeamBuild ? ["./plugins/withoutIosPersonalTeamCapabilities.cjs"] : []),
462 ],
463 extra: {
464 appVariant: APP_VARIANT,
465 iosPersonalTeamBuild: isIosPersonalTeamBuild,
466 relay: {
467 url: repoEnv.T3CODE_RELAY_URL ?? null,
468 },
469 clerk: {
470 publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
471 jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
472 },
473 // @clerk/expo reads these from `extra`
474 // under their exact env-var names (not nested), and its config plugin reads
475 // the iOS URL scheme at prebuild to register it in Info.plist.
476 // Unset values must be omitted (not null): the public manifest serializes
477 // null to {}, which is truthy and would defeat Clerk's fallback checks.
478 EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
479 EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
480 EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID,
481 EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME,
482 observability: {
483 tracesUrl: repoEnv.EXPO_PUBLIC_OTLP_TRACES_URL ?? "https://api.axiom.co/v1/traces",
484 tracesDataset: repoEnv.EXPO_PUBLIC_OTLP_TRACES_DATASET ?? null,
485 tracesToken: repoEnv.EXPO_PUBLIC_OTLP_TRACES_TOKEN ?? null,
486 },
487 eas: {
488 projectId: "d763fcb8-d37c-41ea-a773-b54a0ab4a454",
489 },
490 },
491 owner: "pingdotgg",
492};
493​
494export default config;