2020-09-30 20:43:02 +03:00
|
|
|
package ru.mipt.npm.gradle
|
|
|
|
|
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.kotlin.dsl.*
|
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
2020-11-25 12:16:09 +03:00
|
|
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
2020-09-30 20:43:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a separate target for node
|
|
|
|
*/
|
|
|
|
class KScienceNodePlugin : Plugin<Project> {
|
|
|
|
override fun apply(target: Project) = target.run {
|
|
|
|
//Apply multiplatform plugin is not applied, apply it
|
2020-11-25 12:16:09 +03:00
|
|
|
if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) {
|
|
|
|
logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
|
|
|
|
pluginManager.apply(KotlinMultiplatformPlugin::class)
|
|
|
|
}
|
|
|
|
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
|
|
|
|
logger.info("KScience plugin is not resolved. Adding it automatically")
|
|
|
|
pluginManager.apply(KScienceCommonPlugin::class)
|
2020-09-30 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
configure<KotlinMultiplatformExtension> {
|
|
|
|
js(name = "node", compiler = IR) {
|
|
|
|
nodejs()
|
|
|
|
}
|
|
|
|
sourceSets {
|
|
|
|
val commonMain by getting
|
|
|
|
val nodeMain by creating {
|
|
|
|
dependsOn(commonMain)
|
|
|
|
dependencies{
|
|
|
|
api("org.jetbrains.kotlinx:kotlinx-nodejs:${KScienceVersions.kotlinxNodeVersion}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val commonTest by getting
|
|
|
|
|
|
|
|
val nodeTest by creating {
|
|
|
|
dependsOn(nodeMain)
|
|
|
|
dependsOn(commonTest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|