|
| 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); |
0 commit comments