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,27 +18,18 @@ 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"))
afterEvaluate {
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
@ -54,5 +44,30 @@ open class ScientifikJSPlugin : Plugin<Project> {
}
}
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,14 +28,11 @@ 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"))
afterEvaluate {
if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
@ -53,6 +46,7 @@ open class ScientifikJVMPlugin : Plugin<Project> {
}
}
}
}
}
}

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,31 +92,37 @@ 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")
}