diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/GpgSignMavenConfig.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/GpgSignMavenConfig.kt new file mode 100644 index 0000000..6c9591e --- /dev/null +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/GpgSignMavenConfig.kt @@ -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 +}""" +} diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/js_only/MavenTemplater.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/js_only/MavenTemplater.kt new file mode 100644 index 0000000..f8f845e --- /dev/null +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/js_only/MavenTemplater.kt @@ -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): 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() diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/jvm_only/MavenTemplater.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/jvm_only/MavenTemplater.kt index c6995fb..48f5d0a 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/jvm_only/MavenTemplater.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/jvm_only/MavenTemplater.kt @@ -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): 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() \ No newline at end of file +} +${gpgSigning.generateMavenConfig()} +""".trimIndent() diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/mpp/MavenTemplater.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/mpp/MavenTemplater.kt index 5504384..a07209f 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/mpp/MavenTemplater.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/mpp/MavenTemplater.kt @@ -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): 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() \ No newline at end of file +} + ${gpgSigning.generateMavenConfig()} +""".trimIndent() diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/Config.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/Config.kt index 5a644b7..f132586 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/Config.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/Config.kt @@ -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 { object MultiplatformProjectType : ProjectType() { override val name: String = "Multiplatform" -// override fun buildBintrayGradleConfig( -// bintrayConfig: BintrayConfig, -// licenses: List -// ): 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 -// ): 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 + ): String = mavenConfig.buildJsOnlyMavenConfig(licenses) +} + @Serializable data class Config( val licenses: List, diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt index f015c25..e33d91a 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt @@ -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, - val repositories: List = emptyList() + val repositories: List = emptyList(), + val gpgSigning: GpgSigning = GpgSigning.Disabled, + @Deprecated("Replaced with gpgSigning") + val includeGpgSigning: Boolean = false, ) @Serializable diff --git a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt index f8498ec..54f7fed 100644 --- a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt +++ b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt @@ -10,7 +10,7 @@ class MavenInfoView : VerticalView("Project information") { private var projectDescriptionProperty by mutableStateOf("") private var projectUrlProperty by mutableStateOf("") private var projectVcsUrlProperty by mutableStateOf("") - private var includeGpgSignProperty by mutableStateOf(true) + private var gpgSignProperty by mutableStateOf(GpgSigning.Disabled) private var publishToMavenCentralProperty by mutableStateOf(false) private val developersView = DevelopersView() private val repositoriesView = RepositoriesView() @@ -21,20 +21,24 @@ class MavenInfoView : VerticalView("Project information") { projectDescriptionProperty.ifBlank { defaultProjectDescription }, projectUrlProperty, projectVcsUrlProperty, - includeGpgSignProperty, developersView.developers, repositoriesView.repositories + if (publishToMavenCentralProperty) { listOf(SonatypeRepository) } else { emptyList() - } + }, + gpgSignProperty ) set(value) { projectNameProperty = value.name projectDescriptionProperty = value.description projectUrlProperty = value.url projectVcsUrlProperty = value.vcsUrl - includeGpgSignProperty = value.includeGpgSigning + gpgSignProperty = if (value.includeGpgSigning) { + GpgSigning.Enabled + } else { + value.gpgSigning + } publishToMavenCentralProperty = value.repositories.any { it == SonatypeRepository } developersView.developers = value.developers repositoriesView.repositories = value.repositories.filter { it != SonatypeRepository } @@ -59,11 +63,12 @@ class MavenInfoView : VerticalView("Project information") { "Public project VCS URL (with .git)" ) { projectVcsUrlProperty = it } - SwitchWithLabel( - "Include GPG Signing", - includeGpgSignProperty, - placeSwitchAtTheStart = true - ) { includeGpgSignProperty = it } + +// SwitchWithLabel( +// "Include GPG Signing", +// includeGpgSignProperty, +// placeSwitchAtTheStart = true +// ) { includeGpgSignProperty = it } SwitchWithLabel( "Include publication to MavenCentral", @@ -73,4 +78,4 @@ class MavenInfoView : VerticalView("Project information") { developersView.init() repositoriesView.init() } -} \ No newline at end of file +} diff --git a/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/MavenProjectInfoView.kt b/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/MavenProjectInfoView.kt index 2f6a51d..a9cc9c3 100644 --- a/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/MavenProjectInfoView.kt +++ b/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/MavenProjectInfoView.kt @@ -1,6 +1,7 @@ package dev.inmo.kmppscriptbuilder.web.views import dev.inmo.kmppscriptbuilder.core.models.* +import dev.inmo.kmppscriptbuilder.web.utils.ukActive import kotlinx.browser.document import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLInputElement @@ -10,23 +11,51 @@ class MavenProjectInfoView : View { private val descriptionElement = document.getElementById("projectDescriptionInput") as HTMLInputElement private val urlElement = document.getElementById("projectUrlInput") as HTMLInputElement private val vcsUrlElement = document.getElementById("projectVCSUrlInput") as HTMLInputElement - private val includeGpgElement = document.getElementById("includeGpgSignToggle") as HTMLInputElement + private val disableGpgSigningElement = document.getElementById("disableGpgSigning") as HTMLElement + private val optionalGpgSigningElement = document.getElementById("optionalGpgSigning") as HTMLElement + private val enableGpgSigningElement = document.getElementById("enableGpgSigning") as HTMLElement private val includeMavenCentralElement = document.getElementById("includeMavenCentralTargetRepoToggle") as HTMLInputElement private val developersView = DevelopersView(document.getElementById("developersListDiv") as HTMLElement) private val repositoriesView = RepositoriesView(document.getElementById("repositoriesListDiv") as HTMLElement) + private var gpgSignMode: GpgSigning = GpgSigning.Disabled + set(value) { + field = value + when (value) { + GpgSigning.Enabled -> { + enableGpgSigningElement.ukActive = true + disableGpgSigningElement.ukActive = false + optionalGpgSigningElement.ukActive = false + } + GpgSigning.Optional -> { + enableGpgSigningElement.ukActive = false + disableGpgSigningElement.ukActive = false + optionalGpgSigningElement.ukActive = true + } + GpgSigning.Disabled -> { + enableGpgSigningElement.ukActive = false + disableGpgSigningElement.ukActive = true + optionalGpgSigningElement.ukActive = false + } + } + } + var mavenConfig: MavenConfig get() = MavenConfig( nameElement.value.ifBlank { defaultProjectName }, descriptionElement.value.ifBlank { defaultProjectDescription }, urlElement.value, vcsUrlElement.value, - includeGpgElement.checked, developersView.developers, repositoriesView.repositories + if (includeMavenCentralElement.checked) { listOf(SonatypeRepository) } else { emptyList() + }, + when { + optionalGpgSigningElement.ukActive -> GpgSigning.Optional + enableGpgSigningElement.ukActive -> GpgSigning.Enabled + else -> GpgSigning.Disabled } ) set(value) { @@ -34,10 +63,20 @@ class MavenProjectInfoView : View { descriptionElement.value = value.description urlElement.value = value.url vcsUrlElement.value = value.vcsUrl - includeGpgElement.checked = value.includeGpgSigning + gpgSignMode = if (value.includeGpgSigning) { + GpgSigning.Enabled + } else { + value.gpgSigning + } developersView.developers = value.developers val reposWithoutSonatype = value.repositories.filter { it != SonatypeRepository } includeMavenCentralElement.checked = value.repositories.size != reposWithoutSonatype.size repositoriesView.repositories = reposWithoutSonatype } -} \ No newline at end of file + + init { + enableGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Enabled; Unit } + disableGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Disabled; Unit } + optionalGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Optional; Unit } + } +} diff --git a/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/ProjectTypeView.kt b/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/ProjectTypeView.kt index accaaa7..17397c4 100644 --- a/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/ProjectTypeView.kt +++ b/web/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/web/views/ProjectTypeView.kt @@ -8,16 +8,18 @@ import org.w3c.dom.HTMLElement class ProjectTypeView : View { private val mppProjectTypeElement = document.getElementById("mppProjectType") as HTMLElement private val jvmProjectTypeElement = document.getElementById("jvmProjectType") as HTMLElement + private val jsProjectTypeElement = document.getElementById("jsProjectType") as HTMLElement var projectType: ProjectType - get() = if (jvmProjectTypeElement.ukActive) { - JVMProjectType - } else { - MultiplatformProjectType + get() = when { + jvmProjectTypeElement.ukActive -> JVMProjectType + jsProjectTypeElement.ukActive -> JSProjectType + else -> MultiplatformProjectType } set(value) { mppProjectTypeElement.ukActive = value == MultiplatformProjectType jvmProjectTypeElement.ukActive = value == JVMProjectType + jsProjectTypeElement.ukActive = value == JSProjectType } init { @@ -29,5 +31,9 @@ class ProjectTypeView : View { projectType = JVMProjectType Unit } + jsProjectTypeElement.onclick = { + projectType = JSProjectType + Unit + } } -} \ No newline at end of file +} diff --git a/web/src/jsMain/resources/index.html b/web/src/jsMain/resources/index.html index cae9640..aac5b01 100644 --- a/web/src/jsMain/resources/index.html +++ b/web/src/jsMain/resources/index.html @@ -27,15 +27,11 @@ Licenses -
- - - - -
+
Project information @@ -58,7 +54,15 @@
- + + +
+ +
@@ -78,4 +82,4 @@ - \ No newline at end of file +