-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
673eb65
commit 94d6a2c
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { AndroidConfig, withDangerousMod } = require('@expo/config-plugins'); | ||
const { | ||
createGeneratedHeaderComment, | ||
removeContents, | ||
} = require('@expo/config-plugins/build/utils/generateCode'); | ||
const codeModAndroid = require('@expo/config-plugins/build/android/codeMod'); | ||
const fs = require('fs'); | ||
|
||
const withAppAuthAppBuildGradle = (rootConfig, options) => | ||
withDangerousMod(rootConfig, [ | ||
'android', | ||
config => { | ||
// detauls to app scheme | ||
const authScheme = options?.authScheme ?? config.scheme ?? ''; | ||
|
||
// find the app/build.gradle file and checks its format | ||
const appBuildGradlePath = AndroidConfig.Paths.getAppBuildGradleFilePath( | ||
config.modRequest.projectRoot | ||
); | ||
|
||
// BEWARE: we update the app/build.gradle file *outside* of the standard Expo config procedure ! | ||
let contents = fs.readFileSync(appBuildGradlePath, 'utf-8'); | ||
|
||
if (contents.includes('manifestPlaceholders')) { | ||
throw new Error( | ||
'app/build.gradle already contains manifestPlaceholders, cannot update automatically !' | ||
); | ||
} | ||
|
||
// let's add the manifestPlaceholders section ! | ||
contents = removeContents({ | ||
src: contents, | ||
tag: 'react-native-app-auth', | ||
}).contents; | ||
contents = codeModAndroid.appendContentsInsideDeclarationBlock( | ||
contents, | ||
'defaultConfig', | ||
` | ||
${createGeneratedHeaderComment(contents, 'react-native-app-auth', '//')} | ||
manifestPlaceholders = [ | ||
'appAuthRedirectScheme': '${authScheme}', | ||
] | ||
// @generated end react-native-app-auth | ||
` | ||
); | ||
|
||
// and finally we write the file back to the disk | ||
fs.writeFileSync(appBuildGradlePath, contents, 'utf-8'); | ||
|
||
return config; | ||
}, | ||
]); | ||
|
||
module.exports = { withAppAuthAppBuildGradle }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { withAppAuthAppBuildGradle } = require('./app-build-gradle'); | ||
|
||
module.exports = { | ||
withAppAuthAppBuildGradle, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters