Skip to content

Commit

Permalink
tidy up fixture generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Sep 18, 2024
1 parent 66ec5e7 commit 98abcfc
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions scripts/generate-react-native-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const DEPENDENCIES = [
`@bugsnag/react-native@${notifierVersion}`
]

const REACT_NAVIGATION_DEPENDENCIES = [
`@bugsnag/plugin-react-navigation@${notifierVersion}`,
'@react-navigation/native',
'@react-navigation/native-stack',
'react-native-screens',
'react-native-safe-area-context'
]

if (!process.env.SKIP_GENERATE_FIXTURE) {
// remove the fixture directory if it already exists
if (fs.existsSync(fixtureDir)) {
Expand Down Expand Up @@ -109,8 +117,7 @@ if (process.env.BUILD_IOS === 'true' || process.env.BUILD_IOS === '1') {

function installFixtureDependencies () {
if (!isNewArchEnabled) {
const reactNavigationDependencies = getReactNavigationDependencies()
DEPENDENCIES.push(...reactNavigationDependencies)
DEPENDENCIES.push(...REACT_NAVIGATION_DEPENDENCIES)
}

const fixtureDependencyArgs = DEPENDENCIES.join(' ')
Expand Down Expand Up @@ -178,6 +185,12 @@ function replaceGeneratedFixtureFiles () {
fs.writeFileSync(`${fixtureDir}/ios/Podfile`, podfileContents)

// react navigation setup
if (!isNewArchEnabled) {
configureReactNavigationAndroid()
}
}

function configureReactNavigationAndroid () {
const fileExtension = parseFloat(reactNativeVersion) < 0.73 ? 'java' : 'kt'
let mainActivityPattern, mainActivityReplacement
if (fileExtension === 'java') {
Expand Down Expand Up @@ -218,22 +231,3 @@ class MainActivity : ReactActivity() {
mainActivityContents = mainActivityContents.replace(mainActivityPattern, mainActivityReplacement)
fs.writeFileSync(mainActivityPath, mainActivityContents)
}

function getReactNavigationDependencies () {
let reactNativeScreensVersion
switch (reactNativeVersion) {
case '0.71':
reactNativeScreensVersion = '3.32.0'
break
default:
reactNativeScreensVersion = 'latest'
}

return [
`@bugsnag/plugin-react-navigation@${notifierVersion}`,
'@react-navigation/native',
'@react-navigation/native-stack',
`react-native-screens@${reactNativeScreensVersion}`,
'react-native-safe-area-context'
]
}

0 comments on commit 98abcfc

Please sign in to comment.