1import JsonFile from '@expo/json-file'; 2import { boolish } from 'getenv'; 3import { homedir } from 'os'; 4import * as path from 'path'; 5 6export type UserSettingsData = { 7 developmentCodeSigningId?: string; 8 appleId?: string; 9 accessToken?: string; 10 auth?: UserData | null; 11 ignoreBundledBinaries?: string[]; 12 openDevToolsAtStartup?: boolean; 13 PATH?: string; 14 sendTo?: string; 15 uuid?: string; 16}; 17 18export type UserData = { 19 appleId?: string; 20 userId?: string; 21 username?: string; 22 currentConnection?: ConnectionType; 23 sessionSecret?: string; 24}; 25 26export type ConnectionType = 27 | 'Access-Token-Authentication' 28 | 'Username-Password-Authentication' 29 | 'facebook' 30 | 'google-oauth2' 31 | 'github'; 32 33// The ~/.expo directory is used to store authentication sessions, 34// which are shared between EAS CLI and Expo CLI. 35export function getExpoHomeDirectory() { 36 const home = homedir(); 37 38 if (process.env.__UNSAFE_EXPO_HOME_DIRECTORY) { 39 return process.env.__UNSAFE_EXPO_HOME_DIRECTORY; 40 } else if (boolish('EXPO_STAGING', false)) { 41 return path.join(home, '.expo-staging'); 42 } else if (boolish('EXPO_LOCAL', false)) { 43 return path.join(home, '.expo-local'); 44 } 45 return path.join(home, '.expo'); 46} 47 48export function getUserStatePath() { 49 return path.join(getExpoHomeDirectory(), 'state.json'); 50} 51 52export function getUserState() { 53 return new JsonFile<UserSettingsData>(getUserStatePath(), { 54 jsonParseErrorDefault: {}, 55 // This will ensure that an error isn't thrown if the file doesn't exist. 56 cantReadFileDefault: {}, 57 }); 58} 59