All files / config features.ts

71.42% Statements 5/7
50% Branches 4/8
100% Functions 1/1
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                    1x               1x     1x           1x 1x                                      
/**
 * 功能开关配置
 * 用于控制是否启用新功能
 */
 
import { isSupabaseConfigured } from '@/src/lib/supabase';
 
/**
 * 功能开关
 */
export const FEATURES = {
  /**
   * 使用Supabase直连替代Django API
   *
   * 环境变量控制:EXPO_PUBLIC_USE_SUPABASE=true
   * 优先级:环境变量 > 自动检测(是否配置了Supabase)
   */
  USE_SUPABASE: (() => {
    const envValue = process.env.EXPO_PUBLIC_USE_SUPABASE;
 
    // 如果环境变量明确设置了,使用环境变量
    Iif (envValue !== undefined) {
      return envValue === 'true' || envValue === '1';
    }
 
    // 否则,根据是否配置了Supabase自动决定
    // 在开发环境下,如果配置了Supabase就使用它
    Eif (__DEV__ && isSupabaseConfigured()) {
      return true;
    }
 
    // 生产环境默认使用Django API(稳定)
    return false;
  })(),
 
  /**
   * 启用Supabase实时订阅
   */
  ENABLE_REALTIME: process.env.EXPO_PUBLIC_ENABLE_REALTIME === 'true',
 
  /**
   * 启用性能监控
   */
  ENABLE_PERFORMANCE_MONITORING: __DEV__,
};
 
export default FEATURES;