UNPKG

react-native-imglysdk

Version:

A React Native base module for PhotoEditor SDK and VideoEditor SDK. Integrate the video- and photo editor into your own HTML5, iOS or Android app - in minutes!

227 lines (195 loc) 6.69 kB
import * as Helpers from "./helpers"; /** An interface for customizations for the Android config plugin. */ export interface AndroidConfigurationObject { /** The version of the IMG.LY Android SDK. */ version?: string; /** The modules of the IMG.LY Android SDK. */ modules?: [string]; /** The `buildToolsVersion` of the Android application. */ buildToolsVersion?: string; /** The `minSdkVersion` of the Android application. */ minSdkVersion?: string; /** The `compileSdkVersion` of the Android application. */ compileSdkVersion?: string; /** The `targetSdkVersion` of the Android application. */ targetSdkVersion?: string; /** The Kotlin Gradle plugin version used. */ kotlinGradlePluginVersion?: string; /** The KSP version used. */ kspVersion?: string; } /** Tags for the config plugin. */ export enum ConfigurationTag { Modules = "MODULES", Repos = "REPOS", Maven = "MAVEN", SDKVersions = "SDK_VERSIONS", } /** The default `buildToolsVersion`. */ export const defaultBuildToolsVersion = "35.0.0"; /** The default `minSdkVersion`. */ export const defaultMinSdkVersion = "21"; /** The default `compileSdkVersion`. */ export const defaultCompileSdkVersion = "35"; /** The default `targetSdkVersion`. */ export const defaultTargetSdkVersion = "35"; /** Known Kotlin to KSP version mappings. */ export const kspVersionLookup: Record<string, string> = { "2.2.20": "2.2.20-2.0.3", "2.2.10": "2.2.10-2.0.2", "2.2.0": "2.2.0-2.0.2", "2.1.21": "2.1.21-2.0.2", "2.1.20": "2.1.20-2.0.1", "2.1.10": "2.1.10-1.0.31", "2.1.0": "2.1.0-1.0.29", "2.0.21": "2.0.21-1.0.28", "2.0.20": "2.0.20-1.0.25", "2.0.10": "2.0.10-1.0.24", "2.0.0": "2.0.0-1.0.24", "1.8.10": "1.8.10-1.0.9", "1.8.0": "1.8.0-1.0.9", }; /** * Returns the matching KSP version for the given Kotlin version if it is known. * @param kotlinVersion The Kotlin version. * @returns The matching KSP version if available. */ export function kspVersionForKotlinVersion( kotlinVersion?: string ): string | undefined { if (kotlinVersion == null) { return; } return kspVersionLookup[kotlinVersion]; } /** * Returns the replacement for a given `ConfigurationTag.` * @param tag The `ConfigurationTag`. * @param userInfo The configurations of the user. * @param content The original content. * @returns The replacement string. */ export function replacementForTag( tag: ConfigurationTag, configuration?: AndroidConfigurationObject, content?: string ): string { switch (tag) { case ConfigurationTag.Maven: return imgly_allprojects_block; case ConfigurationTag.Modules: return customizedModules(configuration); case ConfigurationTag.Repos: return imgly_repos_block(configuration); case ConfigurationTag.SDKVersions: if (content != null) { return Helpers.parseSDKVersions(content, configuration) ?? ""; } return ""; } } /** * Customizes the modules for the Android SDK. * @param userInfo The modules that should be included. * @returns The parsed string. */ function customizedModules(configuration?: AndroidConfigurationObject): string { if (configuration?.modules != null) { var modules = configuration.modules.flatMap( (module) => ` include '${module}'\n` ); var config = imgly_config_start.concat(...modules, imgly_config_end); return config; } else { return imgly_config_block; } } /** The modules for the android/app/build.gradle. */ export const imgly_config_regex = 'apply plugin: "com.android.application"'; /** The version of the native Android SDK that is needed for the plugins. */ const sdk_version = "10.9.0"; /** The Kotlin version that is needed for the plugins. */ const default_kotlin_version = "2.1.0"; /** The KSP version that is needed for the plugins. */ const default_ksp_version = "2.1.0-1.0.29"; /** The start for the imgly configuration block. */ const imgly_config_start = ` apply plugin: 'ly.img.android.sdk' apply plugin: 'kotlin-android' // Comment out the modules you don't need, to save size. imglyConfig { modules { `; /** The end for the imgly configuration block. */ const imgly_config_end = ` } } `; /** The modules for the android/app/build.gradle. */ const imgly_config_block = ` apply plugin: 'ly.img.android.sdk' apply plugin: 'kotlin-android' // Comment out the modules you don't need, to save size. IMGLY.configure { modules { include 'ui:text' include 'ui:focus' include 'ui:frame' include 'ui:brush' include 'ui:filter' include 'ui:sticker' include 'ui:overlay' include 'ui:transform' include 'ui:adjustment' include 'ui:text-design' include 'ui:video-trim' include 'ui:video-library' include 'ui:video-composition' include 'ui:audio-composition' include 'ui:giphy-sticker' // This module is big, remove the serializer if you don't need that feature. include 'backend:serializer' // Remove the asset packs you don't need, these are also big in size. include 'assets:font-basic' include 'assets:frame-basic' include 'assets:filter-basic' include 'assets:overlay-basic' include 'assets:sticker-shapes' include 'assets:sticker-emoticons' include 'assets:sticker-animated' include 'backend:sticker-animated' include 'backend:sticker-smart' include 'backend:background-removal' } } `; /** The repositories for all projects. */ const imgly_allprojects_block = ` allprojects { repositories { maven { url "https://artifactory.img.ly/artifactory/imgly" } } } `; /** The repositories for the android/build.gradle. */ function imgly_repos_block(configuration?: AndroidConfigurationObject): string { const kotlinVers = configuration?.kotlinGradlePluginVersion ?? default_kotlin_version const kspVers = configuration?.kspVersion ?? kspVersionForKotlinVersion(configuration?.kotlinGradlePluginVersion) ?? default_ksp_version; return `buildscript { repositories { maven { url "https://artifactory.img.ly/artifactory/imgly" } } dependencies { def kotlinVersion = findProperty('android.kotlinVersion') ?: "${kotlinVers}" def kspVersion = findProperty('android.kspVersion') ?: "${kspVers}" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$\{kotlinVersion}" classpath 'ly.img.android.sdk:plugin:${ configuration?.version ?? sdk_version }' classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:$\{kspVersion}" } } `; }