package expo.modules.plugin.configuration import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.json.Json import kotlinx.serialization.modules.SerializersModule @Serializable data class ExpoAutolinkingConfig( val modules: List = emptyList(), val extraDependencies: List = emptyList(), val coreFeatures: List = emptyList(), val configuration: Configuration = Configuration() ) { /** * Returns all gradle projects from all modules. */ val allProjects: List get() = modules.flatMap { it.projects } /** * Returns all plugins from all modules. */ val allPlugins: List get() = modules.flatMap { it.plugins } /** * Returns all AAR projects from all modules. */ val allAarProjects: List get() = modules.flatMap { it.projects }.flatMap { it.aarProjects } fun toJson(): String { return Json.encodeToString(serializer(), this) } companion object { private val jsonDecoder by lazy { val module = SerializersModule { polymorphicDefaultDeserializer(MavenCredentials::class) { MavenCredentialsSerializer } } Json { // We don't want to fail on a unknown key ignoreUnknownKeys = true serializersModule = module } } /** * Decodes the `ExpoAutolinkingConfig` from given string. */ fun decodeFromString(input: String): ExpoAutolinkingConfig { return jsonDecoder.decodeFromString(input) } } } @Serializable data class Configuration( val buildFromSource: List = emptyList() ) { val buildFromSourceRegex by lazy { buildFromSource.map { it.toRegex() } } } /** * Object representing a maven repository */ @Serializable data class MavenRepo( val url: String, val credentials: MavenCredentials? = null, val authentication: String? = null ) /** * Object representing a module. */ @Serializable data class ExpoModule( val packageName: String, val packageVersion: String, val projects: List = emptyList(), val plugins: List = emptyList(), ) @Serializable data class Publication( val groupId: String, val artifactId: String, val version: String, val repository: String ) /** * Object representing a gradle project. */ @Serializable data class GradleProject( val name: String, val sourceDir: String, val publication: Publication? = null, val aarProjects: List = emptyList(), val modules: List = emptyList(), val shouldUsePublicationScriptPath: String? = null, @Transient val configuration: GradleProjectConfiguration = GradleProjectConfiguration() ) { /** * Returns whether the publication was defined and should be used. */ val usePublication: Boolean get() = publication != null && configuration.shouldUsePublication } data class GradleProjectConfiguration( var shouldUsePublication: Boolean = false ) /** * Object representing a gradle plugin */ @Serializable data class GradlePlugin( val id: String, val group: String, val sourceDir: String, val applyToRootProject: Boolean = true ) /** * Object representing an gradle project containing AAR file */ @Serializable data class GradleAarProject( val name: String, val aarFilePath: String, val projectDir: String )