Added distribution task to JS plugins

This commit is contained in:
Alexander Nozik 2019-07-24 15:03:12 +03:00
parent 361cbaec55
commit ebbd33aa75
6 changed files with 142 additions and 76 deletions

View File

@ -9,7 +9,6 @@ open class ScientifikExtension {
var vcs: String? = null
var bintrayRepo: String? = null
var kdoc: Boolean = true
internal var native = false
var serialization = false
var atomicfu = false
var io = false

View File

@ -3,11 +3,10 @@ package scientifik
import Scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
open class ScientifikJSPlugin : Plugin<Project> {
override fun apply(project: Project) {
@ -19,39 +18,55 @@ open class ScientifikJSPlugin : Plugin<Project> {
plugins.apply("kotlinx-atomicfu")
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
repositories.applyRepos()
configure<KotlinJsProjectExtension> {
target {
browser()
}
sourceSets["main"].apply {
languageSettings.apply {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
languageSettings.applySettings()
dependencies {
api(kotlin("stdlib-jdk8"))
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}")
}
if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}")
afterEvaluate {
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}")
}
if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}")
}
}
}
}
}
tasks.apply {
val browserWebpack by getting(KotlinWebpack::class) {
afterEvaluate {
val destination = listOf(archiveBaseName, archiveAppendix, archiveVersion, archiveClassifier)
.filter { it != null && it.isNotBlank() }
.joinToString("-")
destinationDirectory = destinationDirectory?.resolve(destination)
}
archiveFileName = "main.bundle.js"
}
afterEvaluate {
val installJsDist by creating(Copy::class) {
group = "distribution"
dependsOn(browserWebpack)
from(fileTree("src/main/web"))
into(browserWebpack.destinationDirectory!!)
}
findByName("assemble")?.dependsOn(installJsDist)
}
}
}
}

View File

@ -3,7 +3,9 @@ package scientifik
import Scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -16,13 +18,7 @@ open class ScientifikJVMPlugin : Plugin<Project> {
plugins.apply("kotlinx-serialization")
plugins.apply("kotlinx-atomicfu")
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
repositories.applyRepos()
tasks.withType<KotlinCompile> {
kotlinOptions {
@ -32,22 +28,20 @@ open class ScientifikJVMPlugin : Plugin<Project> {
configure<KotlinJvmProjectExtension> {
sourceSets["main"].apply {
languageSettings.apply {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
languageSettings.applySettings()
dependencies {
api(kotlin("stdlib-jdk8"))
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
}
if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}")
afterEvaluate {
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
}
if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}")
}
}
}
}

View File

@ -3,8 +3,10 @@ package scientifik
import Scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
open class ScientifikMPPlugin : Plugin<Project> {
override fun apply(project: Project) {
@ -14,13 +16,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
project.plugins.apply("kotlinx-serialization")
project.plugins.apply("kotlinx-atomicfu")
project.repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
project.repositories.applyRepos()
project.configure<KotlinMultiplatformExtension> {
jvm {
@ -35,10 +31,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
browser {}
}
if (extension.native) {
linuxX64()
mingwX64()
}
sourceSets.invoke {
val commonMain by getting {
@ -100,32 +92,38 @@ open class ScientifikMPPlugin : Plugin<Project> {
implementation(kotlin("test-js"))
}
}
project.afterEvaluate {
if (extension.native) {
val native by creating {
dependsOn(commonMain)
}
mingwX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
linuxX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
}
}
}
targets.all {
sourceSets.all {
languageSettings.apply {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
languageSettings.applySettings()
}
}
}
project.tasks.apply {
val jsBrowserWebpack by getting(KotlinWebpack::class) {
archiveClassifier = "js"
project.afterEvaluate {
val destination = listOf(archiveBaseName, archiveAppendix, archiveVersion, archiveClassifier)
.filter { it != null && it.isNotBlank() }
.joinToString("-")
destinationDirectory = destinationDirectory?.resolve(destination)
}
archiveFileName = "main.bundle.js"
}
project.afterEvaluate {
val installJsDist by creating(Copy::class) {
group = "distribution"
dependsOn(jsBrowserWebpack)
from(project.fileTree("src/jsMain/web"))
into(jsBrowserWebpack.destinationDirectory!!)
}
findByName("assemble")?.dependsOn(installJsDist)
}
}
}
}

View File

@ -0,0 +1,40 @@
package scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class ScientifikNativePlugin : Plugin<Project> {
override fun apply(target: Project) {
target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
target.configure<KotlinMultiplatformExtension> {
linuxX64()
mingwX64()
sourceSets.apply {
val commonMain by getting {}
val native by creating {
dependsOn(commonMain)
dependencies {
//TODO add stdlib here
target.afterEvaluate {
//TODO add optional libraries here
}
}
}
mingwX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
linuxX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
}
}
}
}
}

View File

@ -0,0 +1,20 @@
package scientifik
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
internal fun LanguageSettingsBuilder.applySettings(): Unit {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedType")
}
internal fun RepositoryHandler.applyRepos(): Unit{
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/scientifik")
maven("https://dl.bintray.com/mipt-npm/dev")
}