2022-01-02 22:28:33 +01:00
|
|
|
import * as Updates from 'expo-updates'
|
|
|
|
|
|
|
|
const mapEnvironment = <T = unknown>({
|
|
|
|
release,
|
|
|
|
candidate,
|
|
|
|
development
|
|
|
|
}: {
|
|
|
|
release: T
|
|
|
|
candidate?: T
|
|
|
|
development?: T
|
|
|
|
}): T => {
|
|
|
|
if (isDevelopment) {
|
|
|
|
if (development) {
|
|
|
|
return development
|
|
|
|
} else {
|
|
|
|
throw new Error('Development environment but no development handler')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isCandidate) {
|
|
|
|
if (candidate) {
|
|
|
|
return candidate
|
|
|
|
} else {
|
|
|
|
throw new Error('Candidate environment but no candidate handler')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRelease) {
|
|
|
|
return release
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
`Environment not set. Please set the environment in the Expo project settings.`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const isDevelopment =
|
|
|
|
__DEV__ ||
|
2022-08-17 14:14:18 +02:00
|
|
|
['development'].some(channel => (Updates.channel || Updates.releaseChannel) === channel)
|
2022-01-02 22:28:33 +01:00
|
|
|
|
|
|
|
const isCandidate = ['candidate'].some(channel =>
|
2022-08-17 14:14:18 +02:00
|
|
|
(Updates.channel || Updates.releaseChannel) === channel
|
2022-01-02 22:28:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const isRelease = ['release'].some(channel =>
|
2022-08-17 14:14:18 +02:00
|
|
|
(Updates.channel || Updates.releaseChannel) === channel
|
2022-01-02 22:28:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
export { mapEnvironment, isDevelopment, isCandidate, isRelease }
|