Skip to content

Commit c73408f

Browse files
committed
feat(expo): add support for expo projects
1 parent 83b0d0a commit c73408f

File tree

5 files changed

+121
-3
lines changed

5 files changed

+121
-3
lines changed

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');

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@
6767
"@release-it/conventional-changelog": "^5.0.0",
6868
"@types/react": "17.0.21",
6969
"@types/react-native": "0.70.0",
70+
"@tsconfig/node-lts": "^20.1.1",
7071
"del-cli": "^5.0.0",
7172
"eslint": "^8.4.1",
7273
"eslint-config-prettier": "^8.5.0",
7374
"eslint-plugin-prettier": "^4.0.0",
75+
"expo": "^50.0.8",
7476
"pod-install": "^0.1.0",
7577
"prettier": "^2.0.5",
7678
"react": "18.1.0",
@@ -83,8 +85,14 @@
8385
"@types/react": "17.0.21"
8486
},
8587
"peerDependencies": {
86-
"react": "^18.1.0",
87-
"react-native": "*"
88+
"react": "*",
89+
"react-native": "*",
90+
"expo": ">=47.0.0"
91+
},
92+
"peerDependenciesMeta": {
93+
"expo": {
94+
"optional": true
95+
}
8896
},
8997
"engines": {
9098
"node": ">= 16.0.0"
@@ -110,7 +118,7 @@
110118
},
111119
"plugins": {
112120
"@release-it/conventional-changelog": {
113-
"preset": "angular"
121+
"preset": "react"
114122
}
115123
}
116124
},

plugin/src/index.ts

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

0 commit comments

Comments
 (0)