Skip to content

Commit 812286e

Browse files
authored
Merge pull request #53 from talsec/add-expo
Add expo
2 parents 83b0d0a + e59b04f commit 812286e

File tree

8 files changed

+257
-25
lines changed

8 files changed

+257
-25
lines changed

.npmignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
config.json
2+
config.example.json
3+
*.zip
4+
*.tgz
5+
6+
plugin/src
7+
8+
# OSX
9+
#
10+
.DS_Store
11+
12+
# XDE
13+
.expo/
14+
15+
# VSCode
16+
.vscode/
17+
jsconfig.json
18+
19+
# Xcode
20+
#
21+
build/
22+
*.pbxuser
23+
!default.pbxuser
24+
*.mode1v3
25+
!default.mode1v3
26+
*.mode2v3
27+
!default.mode2v3
28+
*.perspectivev3
29+
!default.perspectivev3
30+
xcuserdata
31+
*.xccheckout
32+
*.moved-aside
33+
DerivedData
34+
*.hmap
35+
*.ipa
36+
*.xcuserstate
37+
project.xcworkspace
38+
39+
# Android/IJ
40+
#
41+
.classpath
42+
.cxx
43+
.gradle
44+
.idea
45+
.project
46+
.settings
47+
local.properties
48+
android.iml
49+
50+
# Cocoapods
51+
#
52+
example/ios/Pods
53+
example/ios/Podfile.lock
54+
55+
# Ruby
56+
example/vendor/
57+
58+
# node.js
59+
#
60+
node_modules/
61+
npm-debug.log
62+
yarn-debug.log
63+
yarn-error.log
64+
65+
# BUCK
66+
buck-out/
67+
\.buckd/
68+
android/app/libs
69+
android/keystores/debug.keystore
70+
71+
# Expo
72+
.expo/
73+
74+
# Turborepo
75+
.turbo/
76+
77+
# generated by bob
78+
lib/
79+
80+
# exclude development files
81+
scripts/
82+
tsconfig.build.json
83+
tsconfig.json
84+
lefthook.yml
85+
ejs-config.example.json
86+
deploy.sh
87+
babel.config.js
88+
CONTRIBUTING.md
89+
CODE_OF_CONDUCT.md
90+
ci-template.ejs
91+
example/node_modules
92+
example.yarn.lock
93+
example/ios/build
94+
example/ios/Pods
95+
example/ios/podfile.lock
96+
lib/typescript/example
97+
ios/build
98+
android/build
99+
android/gradle
100+
android/gradlew
101+
android/gradlew.bat
102+
android/local.properties
103+
example/android/build
104+
example/android/app/build
105+
example/android/local.properties
106+
**/__tests__/
107+
**/__fixtures__/*
108+
**/__mocks__/*
109+
**/.*

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,25 @@ And you're done 🎉!
319319
If you encounter any other issues, you can see the list of solved issues [here](https://github.com/talsec/Free-RASP-ReactNative/issues?q=is%3Aissue+is%3Aclosed), or open up a [new one](https://github.com/talsec/Free-RASP-ReactNative/issues?q=is%3Aissue+is%3Aopen).
320320

321321
# Using Expo SDK
322-
freeRASP for React Native is bare React Native plugin. When installing freeRASP into a project that uses Expo SDK, there may be extra configuration needed:
322+
freeRASP for React Native is bare React Native plugin. When installing freeRASP into a project that uses Expo SDK, there may be extra configuration needed. We provide plugin config that sets the dependencies automatically. It is recommended to use the plugin config. However, manual setup is also possible.
323+
324+
## Plugin config setup
325+
Add the plugin config into your `app.json` and specify the `minSdkVersion` (use at least 23):
326+
```json
327+
"plugins": [
328+
[
329+
"freerasp-react-native/app.plugin.js",
330+
{
331+
"android": {
332+
"minSdkVersion": "23"
333+
}
334+
}
335+
]
336+
],
337+
```
338+
323339

340+
## Manual setup
324341
### 1. Increase minSdkVersion
325342

326343
This can be done in two ways:

app.plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./plugin/build');

index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,16 @@
77
"types": "lib/typescript/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",
10-
"files": [
11-
"src",
12-
"lib",
13-
"android",
14-
"ios",
15-
"cpp",
16-
"example",
17-
"*.podspec",
18-
"!lib/typescript/example",
19-
"!ios/build",
20-
"!android/build",
21-
"!android/gradle",
22-
"!android/gradlew",
23-
"!android/gradlew.bat",
24-
"!android/local.properties",
25-
"!**/__tests__",
26-
"!**/__fixtures__",
27-
"!**/__mocks__",
28-
"!**/.*"
29-
],
3010
"scripts": {
3111
"typecheck": "tsc --noEmit",
3212
"lint": "eslint \"**/*.{js,ts,tsx}\"",
3313
"prepack": "bob build",
3414
"release": "release-it",
3515
"example": "yarn --cwd example",
3616
"bootstrap": "yarn example && yarn install && yarn example pods",
37-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
17+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
18+
"build:plugin": "tsc --build plugin"
19+
3820
},
3921
"keywords": [
4022
"react-native",
@@ -65,12 +47,15 @@
6547
"devDependencies": {
6648
"@react-native-community/eslint-config": "^3.0.2",
6749
"@release-it/conventional-changelog": "^5.0.0",
50+
"@tsconfig/node-lts": "^20.1.1",
6851
"@types/react": "17.0.21",
6952
"@types/react-native": "0.70.0",
7053
"del-cli": "^5.0.0",
7154
"eslint": "^8.4.1",
7255
"eslint-config-prettier": "^8.5.0",
7356
"eslint-plugin-prettier": "^4.0.0",
57+
"expo": "^50.0.8",
58+
"expo-module-scripts": "^3.4.1",
7459
"pod-install": "^0.1.0",
7560
"prettier": "^2.0.5",
7661
"react": "18.1.0",
@@ -83,9 +68,15 @@
8368
"@types/react": "17.0.21"
8469
},
8570
"peerDependencies": {
86-
"react": "^18.1.0",
71+
"expo": ">=47.0.0",
72+
"react": "*",
8773
"react-native": "*"
8874
},
75+
"peerDependenciesMeta": {
76+
"expo": {
77+
"optional": true
78+
}
79+
},
8980
"engines": {
9081
"node": ">= 16.0.0"
9182
},
@@ -110,7 +101,7 @@
110101
},
111102
"plugins": {
112103
"@release-it/conventional-changelog": {
113-
"preset": "angular"
104+
"preset": "react"
114105
}
115106
}
116107
},

plugin/src/index.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
AndroidConfig,
3+
ConfigPlugin,
4+
WarningAggregator,
5+
createRunOncePlugin,
6+
withProjectBuildGradle,
7+
} from '@expo/config-plugins';
8+
9+
// @ts-ignore
10+
import { PluginConfigType } from './pluginConfig';
11+
12+
const { createBuildGradlePropsConfigPlugin } = AndroidConfig.BuildProperties;
13+
14+
const urlNexus =
15+
'https://nexus3-public.monetplus.cz/repository/ahead-talsec-free-rasp';
16+
const urlJitpack = 'https://www.jitpack.io';
17+
18+
export const setBuildscriptDependency = (buildGradle: string) => {
19+
// This enables users in bare workflow to comment out the line to prevent freerasp from adding it back.
20+
21+
const mavenNexus = buildGradle.includes(urlNexus)
22+
? ''
23+
: `maven { url "${urlNexus}" }`;
24+
const mavenJitpack = buildGradle.includes(urlNexus)
25+
? ''
26+
: `maven { url "${urlJitpack}" }`;
27+
28+
// It's ok to have multiple allprojects.repositories, so we create a new one since it's cheaper than tokenizing
29+
// the existing block to find the correct place to insert our dependency.
30+
const combinedGradleMaven = `
31+
allprojects {
32+
repositories {
33+
${mavenNexus}
34+
${mavenJitpack}
35+
}
36+
}
37+
`;
38+
39+
return buildGradle + `\n${combinedGradleMaven}\n`;
40+
};
41+
42+
/**
43+
* Update `<project>/build.gradle` by adding nexus dependency to buildscript
44+
*/
45+
export const withBuildscriptDependency: ConfigPlugin = (config) => {
46+
return withProjectBuildGradle(config, (config) => {
47+
if (config.modResults.language === 'groovy') {
48+
config.modResults.contents = setBuildscriptDependency(
49+
config.modResults.contents
50+
);
51+
} else {
52+
WarningAggregator.addWarningAndroid(
53+
'freerasp-react-native',
54+
`Cannot automatically configure project build.gradle, because it's not groovy`
55+
);
56+
}
57+
return config;
58+
});
59+
};
60+
61+
export const withAndroidMinSdkVersion =
62+
createBuildGradlePropsConfigPlugin<PluginConfigType>(
63+
[
64+
{
65+
propName: 'android.minSdkVersion',
66+
propValueGetter: (config) => config.android?.minSdkVersion?.toString(),
67+
},
68+
],
69+
'withAndroidMinSdkVersion'
70+
);
71+
72+
const withRnTalsecApp: ConfigPlugin<PluginConfigType> = (config, props) => {
73+
config = withBuildscriptDependency(config);
74+
config = withAndroidMinSdkVersion(config, props);
75+
return config;
76+
};
77+
78+
let pkg: { name: string; version?: string } = {
79+
name: 'freerasp-react-native',
80+
};
81+
try {
82+
const freeraspPkg = require('freerasp-react-native/package.json');
83+
pkg = freeraspPkg;
84+
} catch {}
85+
86+
export default createRunOncePlugin(withRnTalsecApp, pkg.name, pkg.version);

plugin/src/pluginConfig.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Interface representing base build properties configuration.
3+
*/
4+
export interface PluginConfigType {
5+
/**
6+
* Interface representing available configuration for Android native build properties.
7+
* @platform android
8+
*/
9+
android?: PluginConfigTypeAndroid;
10+
}
11+
12+
/**
13+
* Interface representing available configuration for Android native build properties.
14+
* @platform android
15+
*/
16+
export interface PluginConfigTypeAndroid {
17+
/**
18+
* Override the default `minSdkVersion` version number in **build.gradle**.
19+
* */
20+
minSdkVersion?: number;
21+
}

plugin/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "expo-module-scripts/tsconfig.plugin",
3+
"compilerOptions": {
4+
"outDir": "build",
5+
"rootDir": "src",
6+
},
7+
"include": ["./src"]
8+
}

0 commit comments

Comments
 (0)