Skip to content
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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-native-flyy/.eslintrc.js
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');
25 changes: 25 additions & 0 deletions packages/react-native-flyy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @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.

### 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).
1 change: 1 addition & 0 deletions packages/react-native-flyy/app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./build/withReactNativeFlyy");
50 changes: 50 additions & 0 deletions packages/react-native-flyy/package.json
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"
}
186 changes: 186 additions & 0 deletions packages/react-native-flyy/src/withReactNativeFlyy.ts
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);

9 changes: 9 additions & 0 deletions packages/react-native-flyy/tsconfig.json
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__/*"]
}