import * as Updates from 'expo-updates'; import { Platform } from 'react-native'; import * as env from './environment'; import { AppConfig, Stage } from './types'; const envConfig = env.environmentVariables as EnvironmentConfig; const environments: Record = { [Stage.Development]: env.dev, [Stage.Local]: env.local, [Stage.Production]: env.prod, }; function getStagWeb(): Stage { return envConfig.stage; } function getStageApp(): Stage { const channel = Updates.releaseChannel || ''; const isProd = channel.includes(Stage.Production); if (isProd) { return Stage.Production; } return envConfig.stage; } const getStage = Platform.select({ default: getStageApp, web: getStagWeb, }); export function getAppConfig() { const stage = getStage(); const configuration = environments[stage]; return configuration; } export const config = getAppConfig(); interface EnvironmentConfig { stage: Stage; }