add support of JS publish scripts

This commit is contained in:
2022-01-04 21:49:16 +06:00
parent c880d8e657
commit 9a95bddf08
10 changed files with 286 additions and 137 deletions

View File

@@ -0,0 +1,27 @@
package dev.inmo.kmppscriptbuilder.core.export
import dev.inmo.kmppscriptbuilder.core.models.GpgSigning
fun GpgSigning.generateMavenConfig() = when (this) {
GpgSigning.Disabled -> ""
GpgSigning.Optional ->
"""
if (project.hasProperty("signing.gnupg.keyName")) {
apply plugin: 'signing'
signing {
useGpgCmd()
sign publishing.publications
}
}"""
GpgSigning.Enabled ->
"""
apply plugin: 'signing'
signing {
useGpgCmd()
sign publishing.publications
}"""
}

View File

@@ -0,0 +1,67 @@
package dev.inmo.kmppscriptbuilder.core.export.js_only
import dev.inmo.kmppscriptbuilder.core.export.generateMavenConfig
import dev.inmo.kmppscriptbuilder.core.models.*
fun MavenConfig.buildJsOnlyMavenConfig(licenses: List<License>): String = """
apply plugin: 'maven-publish'
task javadocJar(type: Jar) {
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
kotlin.sourceSets.all {
from(kotlin)
}
classifier = 'sources'
}
publishing {
publications {
maven(MavenPublication) {
kotlin.js().components.forEach {
from(it)
}
artifact javadocJar
artifact sourcesJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = "$description"
name = "$name"
url = "$url"
scm {
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
url = "$vcsUrl"
}
developers {
${developers.joinToString("\n") { """
developer {
id = "${it.id}"
name = "${it.name}"
email = "${it.eMail}"
}
""" }}
}
licenses {
${licenses.joinToString("\n") { """
license {
name = "${it.title}"
url = "${it.url}"
}
""" }}
}
}
repositories {
${repositories.joinToString("\n ") { it.build(" ") }}
}
}
}
}
${gpgSigning.generateMavenConfig()}
""".trimIndent()

View File

@@ -1,69 +1,64 @@
package dev.inmo.kmppscriptbuilder.core.export.jvm_only
import dev.inmo.kmppscriptbuilder.core.export.generateMavenConfig
import dev.inmo.kmppscriptbuilder.core.models.*
fun MavenConfig.buildJvmOnlyMavenConfig(licenses: List<License>): String = """
apply plugin: 'maven-publish'
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
pom {
resolveStrategy = Closure.DELEGATE_FIRST
publishing {
publications {
maven(MavenPublication) {
from components.java
description = "$description"
name = "$name"
url = "$url"
artifact javadocJar
artifact sourcesJar
scm {
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
url = "$vcsUrl"
}
pom {
resolveStrategy = Closure.DELEGATE_FIRST
developers {
${developers.joinToString("\n") { """
developer {
id = "${it.id}"
name = "${it.name}"
email = "${it.eMail}"
}
""" }}
}
description = "$description"
name = "$name"
url = "$url"
licenses {
${licenses.joinToString("\n") { """
license {
name = "${it.title}"
url = "${it.url}"
}
""" }}
}
scm {
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
url = "$vcsUrl"
}
repositories {
${repositories.joinToString("\n ") { it.build(" ") }}
developers {
${developers.joinToString("\n") { """
developer {
id = "${it.id}"
name = "${it.name}"
email = "${it.eMail}"
}
""" }}
}
licenses {
${licenses.joinToString("\n") { """
license {
name = "${it.title}"
url = "${it.url}"
}
""" }}
}
}
repositories {
${repositories.joinToString("\n ") { it.build(" ") }}
}
}
}
${if (includeGpgSigning) """
signing {
useGpgCmd()
sign publishing.publications
}
""" else ""}
""".trimIndent()
}
${gpgSigning.generateMavenConfig()}
""".trimIndent()

View File

@@ -1,56 +1,52 @@
package dev.inmo.kmppscriptbuilder.core.export.mpp
import dev.inmo.kmppscriptbuilder.core.export.generateMavenConfig
import dev.inmo.kmppscriptbuilder.core.models.*
fun MavenConfig.buildMultiplatformMavenConfig(licenses: List<License>): String = """
apply plugin: 'maven-publish'
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
apply plugin: 'maven-publish'
publishing {
publications.all {
artifact javadocsJar
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
pom {
description = "$description"
name = "$name"
url = "$url"
publishing {
publications.all {
artifact javadocsJar
scm {
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
url = "$vcsUrl"
}
pom {
description = "$description"
name = "$name"
url = "$url"
developers {
${developers.joinToString("\n") { """
developer {
id = "${it.id}"
name = "${it.name}"
email = "${it.eMail}"
}
""" }}
}
licenses {
${licenses.joinToString("\n") { """
license {
name = "${it.title}"
url = "${it.url}"
}
""" }}
}
scm {
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
url = "$vcsUrl"
}
repositories {
${repositories.joinToString("\n ") { it.build(" ") }}
developers {
${developers.joinToString("\n") { """
developer {
id = "${it.id}"
name = "${it.name}"
email = "${it.eMail}"
}
""" }}
}
licenses {
${licenses.joinToString("\n") { """
license {
name = "${it.title}"
url = "${it.url}"
}
""" }}
}
}
repositories {
${repositories.joinToString("\n ") { it.build(" ") }}
}
}
${if (includeGpgSigning) """
signing {
useGpgCmd()
sign publishing.publications
}
""" else ""}
""".trimIndent()
}
${gpgSigning.generateMavenConfig()}
""".trimIndent()

View File

@@ -1,5 +1,6 @@
package dev.inmo.kmppscriptbuilder.core.models
import dev.inmo.kmppscriptbuilder.core.export.js_only.buildJsOnlyMavenConfig
import dev.inmo.kmppscriptbuilder.core.export.jvm_only.buildJvmOnlyMavenConfig
import dev.inmo.kmppscriptbuilder.core.export.mpp.buildMultiplatformMavenConfig
import kotlinx.serialization.*
@@ -32,12 +33,6 @@ object ProjectTypeSerializer : KSerializer<ProjectType> {
object MultiplatformProjectType : ProjectType() {
override val name: String = "Multiplatform"
// override fun buildBintrayGradleConfig(
// bintrayConfig: BintrayConfig,
// licenses: List<License>
// ): String = bintrayConfig.buildMultiplatformGradleConfig(
// licenses
// )
override fun buildMavenGradleConfig(
mavenConfig: MavenConfig,
@@ -49,12 +44,6 @@ object MultiplatformProjectType : ProjectType() {
object JVMProjectType : ProjectType() {
override val name: String = "JVM"
// override fun buildBintrayGradleConfig(
// bintrayConfig: BintrayConfig,
// licenses: List<License>
// ): String = bintrayConfig.buildJvmOnlyGradleConfig(
// licenses
// )
override fun buildMavenGradleConfig(
mavenConfig: MavenConfig,
@@ -64,6 +53,15 @@ object JVMProjectType : ProjectType() {
)
}
object JSProjectType : ProjectType() {
override val name: String = "JS"
override fun buildMavenGradleConfig(
mavenConfig: MavenConfig,
licenses: List<License>
): String = mavenConfig.buildJsOnlyMavenConfig(licenses)
}
@Serializable
data class Config(
val licenses: List<License>,

View File

@@ -5,15 +5,27 @@ import kotlinx.serialization.Serializable
const val defaultProjectName = "\${project.name}"
const val defaultProjectDescription = "\${project.name}"
@Serializable
sealed class GpgSigning {
@Serializable
object Disabled : GpgSigning()
@Serializable
object Optional : GpgSigning()
@Serializable
object Enabled : GpgSigning()
}
@Serializable
data class MavenConfig(
val name: String,
val description: String,
val url: String,
val vcsUrl: String,
val includeGpgSigning: Boolean = false,
val developers: List<Developer>,
val repositories: List<MavenPublishingRepository> = emptyList()
val repositories: List<MavenPublishingRepository> = emptyList(),
val gpgSigning: GpgSigning = GpgSigning.Disabled,
@Deprecated("Replaced with gpgSigning")
val includeGpgSigning: Boolean = false,
)
@Serializable