From 0d29b470f4f0cd655beabc480939b28290427c1b Mon Sep 17 00:00:00 2001 From: Ashish Date: Tue, 24 May 2022 19:22:16 +0530 Subject: [PATCH 1/3] added react-native-flyy to config-plugin --- packages/react-native-flyy/.eslintrc.js | 2 + packages/react-native-flyy/README.md | 29 +++ packages/react-native-flyy/app.plugin.js | 1 + packages/react-native-flyy/package.json | 50 +++++ .../src/withReactNativeFlyy.ts | 186 ++++++++++++++++++ packages/react-native-flyy/tsconfig.json | 9 + 6 files changed, 277 insertions(+) create mode 100644 packages/react-native-flyy/.eslintrc.js create mode 100644 packages/react-native-flyy/README.md create mode 100644 packages/react-native-flyy/app.plugin.js create mode 100644 packages/react-native-flyy/package.json create mode 100644 packages/react-native-flyy/src/withReactNativeFlyy.ts create mode 100644 packages/react-native-flyy/tsconfig.json diff --git a/packages/react-native-flyy/.eslintrc.js b/packages/react-native-flyy/.eslintrc.js new file mode 100644 index 00000000..27201978 --- /dev/null +++ b/packages/react-native-flyy/.eslintrc.js @@ -0,0 +1,2 @@ +// @generated by expo-module-scripts +module.exports = require('expo-module-scripts/eslintrc.base.js'); diff --git a/packages/react-native-flyy/README.md b/packages/react-native-flyy/README.md new file mode 100644 index 00000000..c433f5d7 --- /dev/null +++ b/packages/react-native-flyy/README.md @@ -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). diff --git a/packages/react-native-flyy/app.plugin.js b/packages/react-native-flyy/app.plugin.js new file mode 100644 index 00000000..82a1dab3 --- /dev/null +++ b/packages/react-native-flyy/app.plugin.js @@ -0,0 +1 @@ +module.exports = require("./build/withReactNativeFlyy"); \ No newline at end of file diff --git a/packages/react-native-flyy/package.json b/packages/react-native-flyy/package.json new file mode 100644 index 00000000..c4408e8e --- /dev/null +++ b/packages/react-native-flyy/package.json @@ -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" + }, + "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" +} diff --git a/packages/react-native-flyy/src/withReactNativeFlyy.ts b/packages/react-native-flyy/src/withReactNativeFlyy.ts new file mode 100644 index 00000000..6230a289 --- /dev/null +++ b/packages/react-native-flyy/src/withReactNativeFlyy.ts @@ -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 = ( + 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); + \ No newline at end of file diff --git a/packages/react-native-flyy/tsconfig.json b/packages/react-native-flyy/tsconfig.json new file mode 100644 index 00000000..81cc93b0 --- /dev/null +++ b/packages/react-native-flyy/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "expo-module-scripts/tsconfig.plugin", + "compilerOptions": { + "outDir": "build", + "rootDir": "src" + }, + "include": ["./src"], + "exclude": ["**/__mocks__/*", "**/__tests__/*"] + } \ No newline at end of file From 5f815d426d9fa0b7c4914da14edda2508be778cc Mon Sep 17 00:00:00 2001 From: Ashish Date: Wed, 25 May 2022 10:19:58 +0530 Subject: [PATCH 2/3] changed README.md --- packages/react-native-flyy/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/react-native-flyy/README.md b/packages/react-native-flyy/README.md index c433f5d7..5e468daf 100644 --- a/packages/react-native-flyy/README.md +++ b/packages/react-native-flyy/README.md @@ -11,10 +11,6 @@ Config plugin to auto configure Flyy SDK on prebuild 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 ``` From 8419a09a6d9cbbe7a3e9e14d8cc51374c10a0f26 Mon Sep 17 00:00:00 2001 From: ashish1066 <100261068+ashish1066@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:03:27 +0530 Subject: [PATCH 3/3] Update packages/react-native-flyy/package.json Co-authored-by: Evan Bacon --- packages/react-native-flyy/package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/react-native-flyy/package.json b/packages/react-native-flyy/package.json index c4408e8e..56323b90 100644 --- a/packages/react-native-flyy/package.json +++ b/packages/react-native-flyy/package.json @@ -17,10 +17,7 @@ "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" + "expo-module": "expo-module" }, "keywords": [ "react",