add support of JS publish scripts

This commit is contained in:
InsanusMokrassar 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,21 +1,21 @@
package dev.inmo.kmppscriptbuilder.core.export.jvm_only package dev.inmo.kmppscriptbuilder.core.export.jvm_only
import dev.inmo.kmppscriptbuilder.core.export.generateMavenConfig
import dev.inmo.kmppscriptbuilder.core.models.* import dev.inmo.kmppscriptbuilder.core.models.*
fun MavenConfig.buildJvmOnlyMavenConfig(licenses: List<License>): String = """ fun MavenConfig.buildJvmOnlyMavenConfig(licenses: List<License>): String = """
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
task javadocJar(type: Jar) { task javadocJar(type: Jar) {
from javadoc from javadoc
classifier = 'javadoc' classifier = 'javadoc'
} }
task sourcesJar(type: Jar) { task sourcesJar(type: Jar) {
from sourceSets.main.allSource from sourceSets.main.allSource
classifier = 'sources' classifier = 'sources'
} }
publishing { publishing {
publications { publications {
maven(MavenPublication) { maven(MavenPublication) {
from components.java from components.java
@ -59,11 +59,6 @@ fun MavenConfig.buildJvmOnlyMavenConfig(licenses: List<License>): String = """
} }
} }
} }
} }
${if (includeGpgSigning) """ ${gpgSigning.generateMavenConfig()}
signing {
useGpgCmd()
sign publishing.publications
}
""" else ""}
""".trimIndent() """.trimIndent()

View File

@ -1,15 +1,16 @@
package dev.inmo.kmppscriptbuilder.core.export.mpp package dev.inmo.kmppscriptbuilder.core.export.mpp
import dev.inmo.kmppscriptbuilder.core.export.generateMavenConfig
import dev.inmo.kmppscriptbuilder.core.models.* import dev.inmo.kmppscriptbuilder.core.models.*
fun MavenConfig.buildMultiplatformMavenConfig(licenses: List<License>): String = """ fun MavenConfig.buildMultiplatformMavenConfig(licenses: List<License>): String = """
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing { task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all { publications.all {
artifact javadocsJar artifact javadocsJar
@ -46,11 +47,6 @@ fun MavenConfig.buildMultiplatformMavenConfig(licenses: List<License>): String =
${repositories.joinToString("\n ") { it.build(" ") }} ${repositories.joinToString("\n ") { it.build(" ") }}
} }
} }
} }
${if (includeGpgSigning) """ ${gpgSigning.generateMavenConfig()}
signing {
useGpgCmd()
sign publishing.publications
}
""" else ""}
""".trimIndent() """.trimIndent()

View File

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

View File

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

View File

@ -10,7 +10,7 @@ class MavenInfoView : VerticalView("Project information") {
private var projectDescriptionProperty by mutableStateOf("") private var projectDescriptionProperty by mutableStateOf("")
private var projectUrlProperty by mutableStateOf("") private var projectUrlProperty by mutableStateOf("")
private var projectVcsUrlProperty by mutableStateOf("") private var projectVcsUrlProperty by mutableStateOf("")
private var includeGpgSignProperty by mutableStateOf(true) private var gpgSignProperty by mutableStateOf<GpgSigning>(GpgSigning.Disabled)
private var publishToMavenCentralProperty by mutableStateOf(false) private var publishToMavenCentralProperty by mutableStateOf(false)
private val developersView = DevelopersView() private val developersView = DevelopersView()
private val repositoriesView = RepositoriesView() private val repositoriesView = RepositoriesView()
@ -21,20 +21,24 @@ class MavenInfoView : VerticalView("Project information") {
projectDescriptionProperty.ifBlank { defaultProjectDescription }, projectDescriptionProperty.ifBlank { defaultProjectDescription },
projectUrlProperty, projectUrlProperty,
projectVcsUrlProperty, projectVcsUrlProperty,
includeGpgSignProperty,
developersView.developers, developersView.developers,
repositoriesView.repositories + if (publishToMavenCentralProperty) { repositoriesView.repositories + if (publishToMavenCentralProperty) {
listOf(SonatypeRepository) listOf(SonatypeRepository)
} else { } else {
emptyList() emptyList()
} },
gpgSignProperty
) )
set(value) { set(value) {
projectNameProperty = value.name projectNameProperty = value.name
projectDescriptionProperty = value.description projectDescriptionProperty = value.description
projectUrlProperty = value.url projectUrlProperty = value.url
projectVcsUrlProperty = value.vcsUrl projectVcsUrlProperty = value.vcsUrl
includeGpgSignProperty = value.includeGpgSigning gpgSignProperty = if (value.includeGpgSigning) {
GpgSigning.Enabled
} else {
value.gpgSigning
}
publishToMavenCentralProperty = value.repositories.any { it == SonatypeRepository } publishToMavenCentralProperty = value.repositories.any { it == SonatypeRepository }
developersView.developers = value.developers developersView.developers = value.developers
repositoriesView.repositories = value.repositories.filter { it != SonatypeRepository } repositoriesView.repositories = value.repositories.filter { it != SonatypeRepository }
@ -59,11 +63,12 @@ class MavenInfoView : VerticalView("Project information") {
"Public project VCS URL (with .git)" "Public project VCS URL (with .git)"
) { projectVcsUrlProperty = it } ) { projectVcsUrlProperty = it }
SwitchWithLabel(
"Include GPG Signing", // SwitchWithLabel(
includeGpgSignProperty, // "Include GPG Signing",
placeSwitchAtTheStart = true // includeGpgSignProperty,
) { includeGpgSignProperty = it } // placeSwitchAtTheStart = true
// ) { includeGpgSignProperty = it }
SwitchWithLabel( SwitchWithLabel(
"Include publication to MavenCentral", "Include publication to MavenCentral",

View File

@ -1,6 +1,7 @@
package dev.inmo.kmppscriptbuilder.web.views package dev.inmo.kmppscriptbuilder.web.views
import dev.inmo.kmppscriptbuilder.core.models.* import dev.inmo.kmppscriptbuilder.core.models.*
import dev.inmo.kmppscriptbuilder.web.utils.ukActive
import kotlinx.browser.document import kotlinx.browser.document
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLInputElement
@ -10,23 +11,51 @@ class MavenProjectInfoView : View {
private val descriptionElement = document.getElementById("projectDescriptionInput") as HTMLInputElement private val descriptionElement = document.getElementById("projectDescriptionInput") as HTMLInputElement
private val urlElement = document.getElementById("projectUrlInput") as HTMLInputElement private val urlElement = document.getElementById("projectUrlInput") as HTMLInputElement
private val vcsUrlElement = document.getElementById("projectVCSUrlInput") 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 includeMavenCentralElement = document.getElementById("includeMavenCentralTargetRepoToggle") as HTMLInputElement
private val developersView = DevelopersView(document.getElementById("developersListDiv") as HTMLElement) private val developersView = DevelopersView(document.getElementById("developersListDiv") as HTMLElement)
private val repositoriesView = RepositoriesView(document.getElementById("repositoriesListDiv") 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 var mavenConfig: MavenConfig
get() = MavenConfig( get() = MavenConfig(
nameElement.value.ifBlank { defaultProjectName }, nameElement.value.ifBlank { defaultProjectName },
descriptionElement.value.ifBlank { defaultProjectDescription }, descriptionElement.value.ifBlank { defaultProjectDescription },
urlElement.value, urlElement.value,
vcsUrlElement.value, vcsUrlElement.value,
includeGpgElement.checked,
developersView.developers, developersView.developers,
repositoriesView.repositories + if (includeMavenCentralElement.checked) { repositoriesView.repositories + if (includeMavenCentralElement.checked) {
listOf(SonatypeRepository) listOf(SonatypeRepository)
} else { } else {
emptyList() emptyList()
},
when {
optionalGpgSigningElement.ukActive -> GpgSigning.Optional
enableGpgSigningElement.ukActive -> GpgSigning.Enabled
else -> GpgSigning.Disabled
} }
) )
set(value) { set(value) {
@ -34,10 +63,20 @@ class MavenProjectInfoView : View {
descriptionElement.value = value.description descriptionElement.value = value.description
urlElement.value = value.url urlElement.value = value.url
vcsUrlElement.value = value.vcsUrl vcsUrlElement.value = value.vcsUrl
includeGpgElement.checked = value.includeGpgSigning gpgSignMode = if (value.includeGpgSigning) {
GpgSigning.Enabled
} else {
value.gpgSigning
}
developersView.developers = value.developers developersView.developers = value.developers
val reposWithoutSonatype = value.repositories.filter { it != SonatypeRepository } val reposWithoutSonatype = value.repositories.filter { it != SonatypeRepository }
includeMavenCentralElement.checked = value.repositories.size != reposWithoutSonatype.size includeMavenCentralElement.checked = value.repositories.size != reposWithoutSonatype.size
repositoriesView.repositories = reposWithoutSonatype repositoriesView.repositories = reposWithoutSonatype
} }
init {
enableGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Enabled; Unit }
disableGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Disabled; Unit }
optionalGpgSigningElement.onclick = { gpgSignMode = GpgSigning.Optional; Unit }
}
} }

View File

@ -8,16 +8,18 @@ import org.w3c.dom.HTMLElement
class ProjectTypeView : View { class ProjectTypeView : View {
private val mppProjectTypeElement = document.getElementById("mppProjectType") as HTMLElement private val mppProjectTypeElement = document.getElementById("mppProjectType") as HTMLElement
private val jvmProjectTypeElement = document.getElementById("jvmProjectType") as HTMLElement private val jvmProjectTypeElement = document.getElementById("jvmProjectType") as HTMLElement
private val jsProjectTypeElement = document.getElementById("jsProjectType") as HTMLElement
var projectType: ProjectType var projectType: ProjectType
get() = if (jvmProjectTypeElement.ukActive) { get() = when {
JVMProjectType jvmProjectTypeElement.ukActive -> JVMProjectType
} else { jsProjectTypeElement.ukActive -> JSProjectType
MultiplatformProjectType else -> MultiplatformProjectType
} }
set(value) { set(value) {
mppProjectTypeElement.ukActive = value == MultiplatformProjectType mppProjectTypeElement.ukActive = value == MultiplatformProjectType
jvmProjectTypeElement.ukActive = value == JVMProjectType jvmProjectTypeElement.ukActive = value == JVMProjectType
jsProjectTypeElement.ukActive = value == JSProjectType
} }
init { init {
@ -29,5 +31,9 @@ class ProjectTypeView : View {
projectType = JVMProjectType projectType = JVMProjectType
Unit Unit
} }
jsProjectTypeElement.onclick = {
projectType = JSProjectType
Unit
}
} }
} }

View File

@ -27,15 +27,11 @@
<ul class="uk-subnav uk-subnav-pill"> <ul class="uk-subnav uk-subnav-pill">
<li id="mppProjectType" class="uk-active"><a href="#">Multiplatform</a></li> <li id="mppProjectType" class="uk-active"><a href="#">Multiplatform</a></li>
<li id="jvmProjectType"><a href="#">JVM</a></li> <li id="jvmProjectType"><a href="#">JVM</a></li>
<li id="jsProjectType"><a href="#">JS</a></li>
</ul> </ul>
</div> </div>
<legend class="uk-legend">Licenses</legend> <legend class="uk-legend">Licenses</legend>
<div id="licensesListDiv" class="uk-padding-small"> <div id="licensesListDiv" class="uk-padding-small"></div>
<!-- <div class="uk-margin uk-width-1-1">-->
<!-- <input id="searchFilterInput" class="uk-input uk-width-expand" type="text" placeholder="License search filter">-->
<!-- </div>-->
<!-- <button class="uk-button uk-button-primary">Add empty license</button>-->
</div>
<legend class="uk-legend">Project information</legend> <legend class="uk-legend">Project information</legend>
@ -58,7 +54,15 @@
</div> </div>
<div class="uk-margin"> <div class="uk-margin">
<label><input id="includeGpgSignToggle" class="uk-checkbox" type="checkbox" checked> Include GPG Signing</label> <label>GPG Signing</label>
<div class="uk-padding-small">
<ul class="uk-subnav uk-subnav-pill">
<li id="disableGpgSigning" class="uk-active" uk-tooltip="title: Signing will not be added"><a href="#">Disabled</a></li>
<li id="optionalGpgSigning" uk-tooltip="title: Signing will be added, but disabled in case of absence 'signatory.keyId'"><a href="#">Optional</a></li>
<li id="enableGpgSigning" uk-tooltip="title: Signing will be always enabled"><a href="#">Enabled</a></li>
</ul>
</div>
</div> </div>
<div class="uk-margin"> <div class="uk-margin">
<label><input id="includeMavenCentralTargetRepoToggle" class="uk-checkbox" type="checkbox"> Include publication to MavenCentral</label> <label><input id="includeMavenCentralTargetRepoToggle" class="uk-checkbox" type="checkbox"> Include publication to MavenCentral</label>