This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expo plugin to simplify installation with expo #2415
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a97fd99
Make android configuration paths dynamic
deggertsen e109e89
Add expo plugin
deggertsen 85d18ec
Add @expo/config-plugins package for expo compatibility
deggertsen 69d8571
Add expo plugin
deggertsen f298984
Add docs for plugin installation for expo
deggertsen 0f74117
Shouldn't need the clean tag for expo prebuild
deggertsen 252f718
Fix title to reflect that this is for IOS, not Android.
deggertsen 38840a3
Merge branch 'master' into master
deggertsen 80a96fb
Add optional CodePushPublicKey to android types for expo plugin
deggertsen 1f81963
If CodePushPublicKey is defined in expo config, add public key as a s…
deggertsen 3e20862
Add to docs concerning codepush public key
deggertsen f52c6ef
Fix for react native 71
deggertsen 887ac2d
Apply the case for react native 71
deggertsen ef49c1e
Include the react-native-code-push settings at the bottom of the file
deggertsen 8e318fa
Merge branch 'master' into master
deggertsen bd27f03
Merge branch 'master' into master
deggertsen 9ac6ea9
Update buildscriptDependency.ts
deggertsen 2c85f66
Apply suggestions from code review
deggertsen 93a082f
Merge branch 'master' into master
deggertsen 2e1ad0c
Update expo config plugins package
deggertsen f9208a7
Fix expo config plugins imports
deggertsen 22722f7
Merge branch 'master' into master
AnatolyPristensky 383115f
Merge branch 'master' into master
deggertsen 3f92f71
Merge branch 'master' into master
deggertsen 357cbea
Merge branch 'master' into master
MikhailSuendukov 7b4c99a
Merge branch 'master' into master
deggertsen 2639f6b
Merge branch 'master' into master
deggertsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| module.exports = require('./plugin/build'); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,44 @@ | ||
| import { ConfigPlugin, withAppBuildGradle } from 'expo/config-plugins' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| /** | ||
| * Update `<project>/build.gradle` by adding the codepush.gradle file | ||
| * as an additional build task definition underneath react.gradle | ||
| */ | ||
|
|
||
| function applyImplementation(appBuildGradle: string) { | ||
| const codePushImplementation = `apply from: new File(["node", "--print", "require.resolve('react-native-code-push/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/android/codepush.gradle"`; | ||
|
|
||
| // Make sure the project does not have the dependency already | ||
| if (!appBuildGradle.includes(codePushImplementation)) { | ||
| const reactNativeFileClassGradleInclude = `'apply from: new File(reactNativeRoot, "react.gradle")`; | ||
| if (appBuildGradle.includes(reactNativeFileClassGradleInclude)) { | ||
| return appBuildGradle.replace( | ||
| reactNativeFileClassGradleInclude, | ||
| `${reactNativeFileClassGradleInclude}\n${codePushImplementation}` | ||
| ); | ||
| } | ||
| const reactNativeRawGradleInclude = `apply from: "../../node_modules/react-native/react.gradle"`; | ||
| if (appBuildGradle.includes(reactNativeRawGradleInclude)) { | ||
| return appBuildGradle.replace( | ||
| reactNativeRawGradleInclude, | ||
| `${reactNativeRawGradleInclude}\n${codePushImplementation}` | ||
| ); | ||
| } | ||
| const reactNative71Include = `apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");`; | ||
| if (appBuildGradle.includes(reactNative71Include)) { | ||
| return appBuildGradle.replace( | ||
| reactNative71Include, | ||
| `${reactNative71Include}\n${codePushImplementation}` | ||
| ); | ||
| } | ||
| } | ||
| return appBuildGradle; | ||
| } | ||
| export const withAndroidBuildscriptDependency: ConfigPlugin<PluginConfigType> = (config) => { | ||
| return withAppBuildGradle(config, (config) => { | ||
| config.modResults.contents = applyImplementation(config.modResults.contents) | ||
| return config | ||
| }) | ||
| } |
This file contains hidden or 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,11 @@ | ||
| import { withAndroidBuildscriptDependency } from './buildscriptDependency' | ||
| import { withAndroidMainApplicationDependency } from './mainApplicationDependency' | ||
| import { withAndroidSettingsDependency } from './settingsDependency' | ||
| import { withAndroidStringsDependency } from './stringsDependency' | ||
|
|
||
| export { | ||
| withAndroidBuildscriptDependency, | ||
| withAndroidSettingsDependency, | ||
| withAndroidStringsDependency, | ||
| withAndroidMainApplicationDependency, | ||
| } |
This file contains hidden or 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,59 @@ | ||
| import { ConfigPlugin, withMainApplication } from 'expo/config-plugins' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| /** | ||
| * Update `<project>/build.gradle` by adding the codepush.gradle file | ||
| * as an additional build task definition underneath react.gradle | ||
| */ | ||
|
|
||
| function applyImplementation( | ||
| mainApplication: string, | ||
| find: string, | ||
| add: string, | ||
| replace?: boolean | ||
| ) { | ||
| // Make sure the project does not have the settings already | ||
| if (!mainApplication.includes(add)) { | ||
| if (replace) return mainApplication.replace(find, add) | ||
| else return mainApplication.replace(find, `${find}\n${add}`) | ||
| } | ||
|
|
||
| return mainApplication | ||
| } | ||
|
|
||
| export const withAndroidMainApplicationDependency: ConfigPlugin<PluginConfigType> = (config) => { | ||
| return withMainApplication(config, (config) => { | ||
| config.modResults.contents = applyImplementation( | ||
| config.modResults.contents, | ||
| 'import expo.modules.ReactNativeHostWrapper;', | ||
| `\nimport com.microsoft.codepush.react.CodePush;` | ||
| ) | ||
| if ( | ||
| config.modResults.contents.includes("new DefaultReactNativeHost(this) {") | ||
| ) { | ||
| config.modResults.contents = applyImplementation( | ||
| config.modResults.contents, | ||
| `new DefaultReactNativeHost(this) {`, | ||
| ` | ||
| @Override | ||
| protected String getJSBundleFile() { | ||
| return CodePush.getJSBundleFile(); | ||
| }\n` | ||
| ); | ||
| } else if ( | ||
| config.modResults.contents.includes(" new ReactNativeHost(this) {") | ||
| ) { | ||
| config.modResults.contents = applyImplementation( | ||
| config.modResults.contents, | ||
| `new ReactNativeHost(this) {`, | ||
| ` | ||
| @Override | ||
| protected String getJSBundleFile() { | ||
| return CodePush.getJSBundleFile(); | ||
| }\n` | ||
| ); | ||
| } | ||
| return config; | ||
| }) | ||
| } |
This file contains hidden or 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,25 @@ | ||
| import { ConfigPlugin, withSettingsGradle } from 'expo/config-plugins' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| /** | ||
| * Update `<project>/settings.gradle` by adding react-native-code-push | ||
| */ | ||
|
|
||
| function applySettings(gradleSettings: string) { | ||
| const codePushSettings = `\ninclude ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(["node", "--print", "require.resolve('react-native-code-push/package.json')"].execute(null, rootDir).text.trim(), "../android/app")` | ||
|
|
||
| // Make sure the project does not have the settings already | ||
| if (!gradleSettings.includes(`include ':react-native-code-push'`)) { | ||
| return gradleSettings + codePushSettings | ||
| } | ||
|
|
||
| return gradleSettings | ||
| } | ||
|
|
||
| export const withAndroidSettingsDependency: ConfigPlugin<PluginConfigType> = (config) => { | ||
| return withSettingsGradle(config, (config) => { | ||
| config.modResults.contents = applySettings(config.modResults.contents) | ||
| return config | ||
| }) | ||
| } |
This file contains hidden or 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,28 @@ | ||
| import { AndroidConfig, ConfigPlugin, withStringsXml } from 'expo/config-plugins' | ||
| import { ResourceXML } from 'expo/config-plugins/build/android/Resources' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| /** | ||
| * Update `<project>/app/src/main/res/values/strings.xml` by adding react-native-code-push deployment key | ||
| */ | ||
|
|
||
| function setStrings(strings: ResourceXML, name: string, value: string) { | ||
| // Helper to add string.xml JSON items or overwrite existing items with the same name. | ||
| return AndroidConfig.Strings.setStringItem( | ||
| [ | ||
| // XML represented as JSON | ||
| // <string moduleConfig="true" name="">value</string> | ||
| { $: { name }, _: value }, | ||
| ], | ||
| strings | ||
| ) | ||
| } | ||
|
|
||
| export const withAndroidStringsDependency: ConfigPlugin<PluginConfigType> = (config, props) => { | ||
| return withStringsXml(config, (config) => { | ||
| config.modResults = setStrings(config.modResults, 'CodePushDeploymentKey', props.android.CodePushDeploymentKey) | ||
| if (props.android.CodePushPublicKey) config.modResults = setStrings(config.modResults, 'CodePushPublicKey', props.android.CodePushPublicKey) | ||
| return config | ||
| }) | ||
| } |
This file contains hidden or 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,36 @@ | ||
| import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins' | ||
deggertsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import { | ||
| withAndroidBuildscriptDependency, | ||
| withAndroidMainApplicationDependency, | ||
| withAndroidSettingsDependency, | ||
| withAndroidStringsDependency, | ||
| } from './android' | ||
| import { withIosAppDelegateDependency, withIosBuildscriptDependency } from './ios' | ||
| import { PluginConfigType } from './pluginConfig' | ||
|
|
||
| /** | ||
| * A config plugin for configuring `react-native-code-push` | ||
| */ | ||
| const withRnCodepush: ConfigPlugin<PluginConfigType> = (config, props) => { | ||
| config = withAndroidBuildscriptDependency(config, props) | ||
| config = withAndroidSettingsDependency(config, props) | ||
| config = withAndroidStringsDependency(config, props) | ||
| config = withAndroidMainApplicationDependency(config, props) | ||
| // plugins order matter: the later one would run first | ||
| config = withIosBuildscriptDependency(config, props) | ||
| config = withIosAppDelegateDependency(config, props) | ||
|
|
||
| return config | ||
| } | ||
|
|
||
| let pkg: { name: string; version?: string } = { | ||
| name: "react-native-code-push", | ||
| // UNVERSIONED... | ||
| }; | ||
| try { | ||
| const codePushPkg = require("react-native-code-push/package.json"); | ||
| pkg = codePushPkg; | ||
| } catch {} | ||
|
|
||
| export default createRunOncePlugin(withRnCodepush, pkg.name, pkg.version); | ||
This file contains hidden or 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,34 @@ | ||
| import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| // Use these imports in SDK 46 and lower | ||
| // import { ConfigPlugin, InfoPlist, withInfoPlist } from '@expo/config-plugins'; | ||
| // import { ExpoConfig } from '@expo/config-types'; | ||
|
|
||
| function applyImplementation(appDelegate: string, find: string, add: string, replace?: boolean) { | ||
| // Make sure the project does not have the settings already | ||
| if (!appDelegate.includes(add)) { | ||
| if (replace) return appDelegate.replace(find, add) | ||
| else return appDelegate.replace(find, `${find}\n${add}`) | ||
| } | ||
|
|
||
| return appDelegate | ||
| } | ||
|
|
||
| export const withIosAppDelegateDependency: ConfigPlugin<PluginConfigType> = (config, props) => { | ||
| return withAppDelegate(config, (config) => { | ||
| config.modResults.contents = applyImplementation( | ||
| config.modResults.contents, | ||
| `#import "AppDelegate.h"`, | ||
| `#import <CodePush/CodePush.h>` | ||
| ) | ||
| config.modResults.contents = applyImplementation( | ||
| config.modResults.contents, | ||
| `return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];`, | ||
| `return [CodePush bundleURL];`, | ||
| true | ||
| ) | ||
| return config | ||
| }) | ||
| } |
This file contains hidden or 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,12 @@ | ||
| import { ConfigPlugin, withInfoPlist } from '@expo/config-plugins' | ||
|
|
||
| import { PluginConfigType } from '../pluginConfig' | ||
|
|
||
| // Pass `<string>` to specify that this plugin requires a string property. | ||
| export const withIosBuildscriptDependency: ConfigPlugin<PluginConfigType> = (config, props) => { | ||
| if (!props.ios.CodePushDeploymentKey) return config | ||
| return withInfoPlist(config, (config) => { | ||
| config.modResults.CodePushDeploymentKey = props.ios.CodePushDeploymentKey | ||
| return config | ||
| }) | ||
| } |
This file contains hidden or 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,4 @@ | ||
| import { withIosAppDelegateDependency } from './appDelegateDependency' | ||
| import { withIosBuildscriptDependency } from './buildscriptDependency' | ||
|
|
||
| export { withIosBuildscriptDependency, withIosAppDelegateDependency } |
This file contains hidden or 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,12 @@ | ||
| /** | ||
| * Configuration for `react-native-code-push` | ||
| */ | ||
| export interface PluginConfigType { | ||
| ios: { | ||
| CodePushDeploymentKey: string | ||
| } | ||
| android: { | ||
| CodePushDeploymentKey: string | ||
| CodePushPublicKey?: string | ||
| } | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "extends": "expo-module-scripts/tsconfig.plugin", | ||
| "compilerOptions": { | ||
| "outDir": "build", | ||
| "rootDir": "src" | ||
| }, | ||
| "include": ["./src"], | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.