-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react-native-flyy): Added to config-plugin #80
Open
ashish1066
wants to merge
3
commits into
expo:main
Choose a base branch
from
ashish1066:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
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 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,2 @@ | ||
// @generated by expo-module-scripts | ||
module.exports = require('expo-module-scripts/eslintrc.base.js'); |
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,29 @@ | ||
# @config-plugins/react-native-flyy | ||
|
||
Config plugin to auto configure Flyy SDK on prebuild | ||
|
||
# API documentation | ||
|
||
- [Documentation for the master branch](https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/sdk/@config-plugins/react-native-flyy.md) | ||
- [Documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/@config-plugins/react-native-flyy/) | ||
|
||
# Installation in managed Expo projects | ||
|
||
For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release. | ||
|
||
# Installation in bare React Native projects | ||
|
||
For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing. | ||
|
||
### Add the package to your npm dependencies | ||
|
||
``` | ||
npm install @config-plugins/react-native-flyy | ||
``` | ||
|
||
|
||
|
||
|
||
# Contributing | ||
|
||
Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing). |
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 @@ | ||
module.exports = require("./build/withReactNativeFlyy"); |
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,50 @@ | ||
{ | ||
"name": "@config-plugins/react-native-flyy", | ||
"version": "2.0.0", | ||
"description": "Config plugin to auto configure Flyy SDK on prebuild", | ||
"main": "build/withReactNativeFlyy.js", | ||
"types": "build/withReactNativeFlyy.d.ts", | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/expo/config-plugins.git", | ||
"directory": "packages/react-native-flyy" | ||
}, | ||
"scripts": { | ||
"build": "expo-module build", | ||
"clean": "expo-module clean", | ||
"lint": "expo-module lint", | ||
"test": "expo-module test", | ||
"prepare": "expo-module prepare", | ||
"prepublishOnly": "expo-module prepublishOnly", | ||
"expo-module": "expo-module", | ||
"start": "expo start --dev-client", | ||
"android": "expo run:android", | ||
"ios": "expo run:ios" | ||
ashish1066 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"keywords": [ | ||
"react", | ||
"expo", | ||
"config-plugins", | ||
"prebuild", | ||
"react-native-flyy" | ||
], | ||
"jest": { | ||
"preset": "expo-module-scripts" | ||
}, | ||
"dependencies": { | ||
"@expo/config-plugins": "~4.1.4", | ||
"expo": "~45.0.0", | ||
"expo-splash-screen": "~0.15.1", | ||
"expo-status-bar": "~1.3.0", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-native": "0.68.2", | ||
"react-native-web": "0.17.7" | ||
}, | ||
"devDependencies": { | ||
"expo-module-scripts": "^2.0.0", | ||
"@babel/core": "^7.12.9" | ||
}, | ||
"upstreamPackage": "react-native-flyy" | ||
} |
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,186 @@ | ||
import { | ||
AndroidConfig, | ||
createRunOncePlugin, | ||
IOSConfig, | ||
withXcodeProject, | ||
withAppBuildGradle, | ||
withProjectBuildGradle, | ||
withPlugins, | ||
ConfigPlugin, | ||
withGradleProperties, | ||
} from "@expo/config-plugins"; | ||
import { mergeContents, MergeResults, createGeneratedHeaderComment, removeGeneratedContents, } from "@expo/config-plugins/build/utils/generateCode"; | ||
|
||
const gradleMaven = [ | ||
`allprojects { | ||
repositories { | ||
jcenter() | ||
maven { | ||
url 'https://jitpack.io' | ||
credentials { username authToken } | ||
} | ||
} | ||
}`, | ||
].join("\n"); | ||
|
||
const gradleClasspathFirebase = [ | ||
`buildscript { | ||
dependencies { | ||
classpath 'com.google.gms:google-services:4.3.10' | ||
} | ||
}`, | ||
].join("\n"); | ||
|
||
|
||
//Add authToken Property in gradle.properties | ||
|
||
const modifyGradlePropertyFlyy: ConfigPlugin = (config) => { | ||
return withGradleProperties(config, (config) => { | ||
config.modResults.push({ | ||
type: 'property', | ||
key: 'authToken', | ||
value: "jp_9lured1djkqj83p7vaqhes4img", | ||
}) | ||
return config; | ||
}); | ||
}; | ||
|
||
//Add apply-plugin for firebase | ||
|
||
const addApplyPlugin = (src: string) => { | ||
const newSrc = []; | ||
newSrc.push("apply plugin: \"com.google.gms.google-services\" "); | ||
return mergeContents({ | ||
tag: "apply-plugin-google-services", | ||
src, | ||
newSrc: newSrc.join("\n"), | ||
anchor: /apply plugin/, | ||
// Inside the dependencies block. | ||
offset: 1, | ||
comment: "//", | ||
}); | ||
}; | ||
|
||
const withGradlePluginApply: ConfigPlugin = (config) => { | ||
return withAppBuildGradle(config, (config) => { | ||
if (config.modResults.language === "groovy") { | ||
config.modResults.contents = addApplyPlugin( | ||
config.modResults.contents | ||
).contents; | ||
} else { | ||
throw new Error( | ||
"Cannot add Play Services maven gradle because the project build.gradle is not groovy" | ||
); | ||
} | ||
return config; | ||
}); | ||
}; | ||
|
||
//Add ClassPath for Firebase | ||
function addFirebaseClasspath(src: string): MergeResults { | ||
return appendContents({ | ||
tag: "google-services-classpath", | ||
src, | ||
newSrc: gradleClasspathFirebase, | ||
comment: "//", | ||
}); | ||
} | ||
|
||
const withGradleFirebaseClasspath: ConfigPlugin = (config) => { | ||
return withProjectBuildGradle(config, (config) => { | ||
if (config.modResults.language === "groovy") { | ||
config.modResults.contents = addFirebaseClasspath( | ||
config.modResults.contents | ||
).contents; | ||
} else { | ||
throw new Error( | ||
"Cannot add Play Services maven gradle because the project build.gradle is not groovy" | ||
); | ||
} | ||
return config; | ||
}); | ||
}; | ||
|
||
|
||
//Add Flyy required Maven() | ||
|
||
function addGardleMaven(src: string): MergeResults { | ||
return appendContents({ | ||
tag: "flyy-maven-jitpack", | ||
src, | ||
newSrc: gradleMaven, | ||
comment: "//", | ||
}); | ||
} | ||
|
||
const withGradleFlyy: ConfigPlugin = (config) => { | ||
return withProjectBuildGradle(config, (config) => { | ||
if (config.modResults.language === "groovy") { | ||
config.modResults.contents = addGardleMaven( | ||
config.modResults.contents | ||
).contents; | ||
} else { | ||
throw new Error( | ||
"Cannot add Play Services maven gradle because the project build.gradle is not groovy" | ||
); | ||
} | ||
return config; | ||
}); | ||
}; | ||
|
||
function appendContents({ | ||
src, | ||
newSrc, | ||
tag, | ||
comment, | ||
}: { | ||
src: string; | ||
newSrc: string; | ||
tag: string; | ||
comment: string; | ||
}): MergeResults { | ||
const header = createGeneratedHeaderComment(newSrc, tag, comment); | ||
if (!src.includes(header)) { | ||
// Ensure the old generated contents are removed. | ||
const sanitizedTarget = removeGeneratedContents(src, tag); | ||
const contentsToAdd = [ | ||
// @something | ||
header, | ||
// contents | ||
newSrc, | ||
// @end | ||
`${comment} @generated end ${tag}`, | ||
].join("\n"); | ||
|
||
return { | ||
contents: sanitizedTarget ?? src + contentsToAdd, | ||
didMerge: true, | ||
didClear: !!sanitizedTarget, | ||
}; | ||
} | ||
return { contents: src, didClear: false, didMerge: false }; | ||
} | ||
|
||
const withFlyyPlugin: ConfigPlugin<void> = ( | ||
config, | ||
_props | ||
) => withPlugins(config, [ | ||
modifyGradlePropertyFlyy, | ||
withGradleFlyy, | ||
withGradleFirebaseClasspath, | ||
withGradlePluginApply | ||
]); | ||
|
||
const pkg = { | ||
// Prevent this plugin from being run more than once. | ||
// This pattern enables users to safely migrate off of this | ||
// out-of-tree `@config-plugins/react-native-flyy` to a future | ||
// upstream plugin in `react-native-flyy` | ||
name: "react-native-flyy", | ||
// Indicates that this plugin is dangerously linked to a module, | ||
// and might not work with the latest version of that module. | ||
version: "2.0.0", | ||
}; | ||
|
||
export default createRunOncePlugin(withFlyyPlugin, pkg.name, pkg.version); | ||
|
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,9 @@ | ||
{ | ||
"extends": "expo-module-scripts/tsconfig.plugin", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"rootDir": "src" | ||
}, | ||
"include": ["./src"], | ||
"exclude": ["**/__mocks__/*", "**/__tests__/*"] | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-native-unimodules is deprecated since SDK 43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-native-unimodules instruction removed from README