Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created May 11, 2022 14:14
Show Gist options
  • Select an option

  • Save codebutler/a14b1117d85fa2c1db7fffa5e4288361 to your computer and use it in GitHub Desktop.

Select an option

Save codebutler/a14b1117d85fa2c1db7fffa5e4288361 to your computer and use it in GitHub Desktop.
// Expo config plugin for Plaid SDK
// Adds Plaid support to managed expo apps using the dev client
//
// https://docs.expo.dev/guides/config-plugins/
// https://github.com/plaid/react-native-plaid-link-sdk#android-setup
import { ExpoConfig } from "@expo/config";
import {
ConfigPlugin,
withAppBuildGradle,
withMainApplication,
withPlugins,
withSettingsGradle,
} from "@expo/config-plugins";
import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
const withPlaidGradleBuild: ConfigPlugin = (config: ExpoConfig) =>
withAppBuildGradle(config, (gradleConfig) => {
gradleConfig.modResults.contents = mergeContents({
tag: "plaid-gradle–build",
src: gradleConfig.modResults.contents,
newSrc: `
implementation project(':react-native-plaid-link-sdk')
`,
anchor: /dependencies/,
offset: 1,
comment: "//",
}).contents;
return gradleConfig;
});
const withPlaidGradleSettings: ConfigPlugin = (config: ExpoConfig) =>
withSettingsGradle(config, (gradleConfig) => {
gradleConfig.modResults.contents = mergeContents({
tag: "plaid-gradle-settings",
src: gradleConfig.modResults.contents,
newSrc: `
include ':react-native-plaid-link-sdk'
project(':react-native-plaid-link-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-plaid-link-sdk/android')
`,
anchor: /include ':app'/,
offset: -1,
comment: "//",
}).contents;
return gradleConfig;
});
const withPlaidApplication: ConfigPlugin = (config) =>
withMainApplication(config, (appConfig) => {
let contents = appConfig.modResults.contents;
contents = mergeContents({
tag: "plaid-app-imports",
src: contents,
newSrc: `
import com.plaid.PlaidPackage;`,
anchor: /import java.lang.reflect.InvocationTargetException/,
offset: 1,
comment: "//",
}).contents;
contents = mergeContents({
tag: "plaid-app-package",
src: contents,
newSrc: "packages.add(new PlaidPackage());",
anchor: /new PackageList/,
offset: 1,
comment: "//",
}).contents;
appConfig.modResults.contents = contents;
return appConfig;
});
const withPlaid: ConfigPlugin = (config) =>
withPlugins(config, [
withPlaidGradleBuild,
withPlaidGradleSettings,
withPlaidApplication,
]);
export default withPlaid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment