Compare commits

...

3 Commits

Author SHA1 Message Date
7aa30ef46c temporal state 2021-03-02 02:43:30 +06:00
aa1756724a add and web target 2021-03-01 22:42:15 +06:00
741ee98e35 Merge pull request #2 from InsanusMokrassar/rewrite_on_multiplatform
rewrite on multiplatform
2021-03-01 21:20:34 +06:00
16 changed files with 375 additions and 5 deletions

View File

@@ -17,8 +17,6 @@ jobs:
run: echo "version=` cat gradle.properties | grep ^version= | grep -o [\\.0-9]* `" >> $GITHUB_ENV
- name: Build
run: ./gradlew packageUberJarForCurrentOS
env:
additional_version: ""
- name: Create Release
id: create_release
uses: actions/create-release@v1

View File

@@ -15,6 +15,7 @@ allprojects {
mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle"
mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle"
mppJsProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJsProject.gradle"
mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle"
defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle"

View File

@@ -1,4 +1,4 @@
project.version = "$version" + System.getenv("additional_version")
project.version = "$version" + (System.getenv("additional_version") != null ? System.getenv("additional_version") : "")
project.group = "$group"
// apply from: "$publishGradlePath"

View File

@@ -1,4 +1,4 @@
project.version = "$version" + System.getenv("additional_version")
project.version = "$version" + (System.getenv("additional_version") != null ? System.getenv("additional_version") : "")
project.group = "$group"
// apply from: "$publishGradlePath"

34
mppJsProject.gradle Normal file
View File

@@ -0,0 +1,34 @@
project.version = "$version" + (System.getenv("additional_version") != null ? System.getenv("additional_version") : "")
project.group = "$group"
// apply from: "$publishGradlePath"
kotlin {
js (IR) {
browser {
binaries.executable()
}
nodejs()
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialisation_core_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jsTest {
dependencies {
implementation kotlin('test-js')
implementation kotlin('test-junit')
}
}
}
}

View File

@@ -9,7 +9,8 @@ rootProject.name = 'kmppscriptbuilder'
String[] includes = [
":core",
":desktop"
":desktop",
":web"
]

17
web/build.gradle Normal file
View File

@@ -0,0 +1,17 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppJsProjectPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
implementation project(":kmppscriptbuilder.core")
implementation "dev.inmo:micro_utils.common:$micro_utils_version"
}
}
}
}

View File

@@ -0,0 +1,15 @@
package dev.inmo.kmppscriptbuilder.web
import dev.inmo.kmppscriptbuilder.web.views.MavenProjectInfoView
import dev.inmo.kmppscriptbuilder.web.views.ProjectTypeView
import kotlinx.browser.document
fun main() {
document.addEventListener(
"DOMContentLoaded",
{
val projectTypeView = ProjectTypeView()
val mavenInfoTypeView = MavenProjectInfoView()
}
)
}

View File

@@ -0,0 +1,13 @@
package dev.inmo.kmppscriptbuilder.web.utils
import org.w3c.dom.HTMLElement
var HTMLElement.ukActive: Boolean
get() = classList.contains("uk-active")
set(value) {
if (value) {
classList.add("uk-active")
} else {
classList.remove("uk-active")
}
}

View File

@@ -0,0 +1,35 @@
package dev.inmo.kmppscriptbuilder.web.views
import dev.inmo.kmppscriptbuilder.core.models.Developer
import org.w3c.dom.*
class DevelopersView(rootElement: HTMLElement) : ListView<Developer>(rootElement, "Add developer", "Remove developer") {
private val HTMLElement.usernameElement: HTMLInputElement
get() = children[0] as HTMLInputElement
private val HTMLElement.nameElement: HTMLInputElement
get() = children[1] as HTMLInputElement
private val HTMLElement.emailElement: HTMLInputElement
get() = children[2] as HTMLInputElement
var developers: List<Developer>
get() = elements.values.map {
Developer(it.usernameElement.value, it.nameElement.value, it.emailElement.value)
}
set(value) {
data = value
}
override fun createPlainObject(): Developer = Developer("", "", "")
override fun HTMLElement.placeElement(value: Developer) {
createTextField("Developer ID", "Developer username").value = value.id
createTextField("Developer name", "").value = value.name
createTextField("Developer E-Mail", "").value = value.eMail
}
override fun HTMLElement.updateElement(from: Developer, to: Developer) {
usernameElement.value = to.id
nameElement.value = to.name
emailElement.value = to.eMail
}
}

View File

@@ -0,0 +1,62 @@
package dev.inmo.kmppscriptbuilder.web.views
import dev.inmo.micro_utils.common.calculateDiff
import kotlinx.browser.document
import kotlinx.dom.appendElement
import org.w3c.dom.HTMLElement
abstract class ListView<T>(
private val rootElement: HTMLElement,
addButtonText: String = "Add",
private val removeButtonText: String = "Remove"
) : View {
protected val elements = mutableMapOf<T, HTMLElement>()
protected var data: List<T> = emptyList()
set(value) {
val old = field
field = value
val diff = old.calculateDiff(value)
diff.removed.forEach {
rootElement.removeChild(elements[it.value] ?: return@forEach)
}
diff.added.forEach {
val element = instantiateElement()
element.placeElement(it.value)
elements[it.value] = element
element.addRemoveButton(it.value)
}
diff.replaced.forEach { (old, new) ->
val element = elements[old.value] ?.also { it.updateElement(old.value, new.value) }
if (element == null) {
val newElement = instantiateElement()
newElement.placeElement(new.value)
elements[new.value] = newElement
}
}
}
init {
rootElement.createButton(addButtonText).apply {
onclick = {
data += createPlainObject()
Unit
}
}
}
protected abstract fun createPlainObject(): T
protected abstract fun HTMLElement.placeElement(value: T)
protected abstract fun HTMLElement.updateElement(from: T, to: T)
private fun HTMLElement.addRemoveButton(value: T) {
createButton(removeButtonText).onclick = {
data = data.filter {
it != value
}
Unit
}
}
private fun instantiateElement() = rootElement.appendElement("div") {
classList.add("uk-padding-small")
} as HTMLElement
}

View File

@@ -0,0 +1,44 @@
package dev.inmo.kmppscriptbuilder.web.views
import dev.inmo.kmppscriptbuilder.core.models.MavenConfig
import dev.inmo.kmppscriptbuilder.core.models.SonatypeRepository
import kotlinx.browser.document
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLInputElement
class MavenProjectInfoView : View {
private val nameElement = document.getElementById("projectNameInput") as HTMLInputElement
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 includeMavenCentralElement = document.getElementById("includeMavenCentralTargetRepoToggle") as HTMLInputElement
private val developersView = DevelopersView(document.getElementById("developersListDiv") as HTMLElement)
var mavenConfig: MavenConfig
get() = MavenConfig(
nameElement.value,
descriptionElement.value,
urlElement.value,
vcsUrlElement.value,
includeGpgElement.checked,
developersView.developers,// TODO:: Add developers
// TODO:: Add repositories
if (includeMavenCentralElement.checked) {
listOf(SonatypeRepository)
} else {
emptyList()
}
)
set(value) {
nameElement.value = value.name
descriptionElement.value = value.description
urlElement.value = value.url
vcsUrlElement.value = value.vcsUrl
includeGpgElement.checked = value.includeGpgSigning
developersView.developers = value.developers
// TODO:: Add repositories
val reposWithoutSonatype = value.repositories.filter { it != SonatypeRepository }
includeMavenCentralElement.checked = value.repositories.size != reposWithoutSonatype.size
}
}

View File

@@ -0,0 +1,33 @@
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
class ProjectTypeView : View {
private val mppProjectTypeElement = document.getElementById("mppProjectType") as HTMLElement
private val jvmProjectTypeElement = document.getElementById("jvmProjectType") as HTMLElement
var projectType: ProjectType
get() = if (jvmProjectTypeElement.ukActive) {
JVMProjectType
} else {
MultiplatformProjectType
}
set(value) {
mppProjectTypeElement.ukActive = value == MultiplatformProjectType
jvmProjectTypeElement.ukActive = value == JVMProjectType
}
init {
mppProjectTypeElement.onclick = {
projectType = MultiplatformProjectType
Unit
}
jvmProjectTypeElement.onclick = {
projectType = JVMProjectType
Unit
}
}
}

View File

@@ -0,0 +1,3 @@
package dev.inmo.kmppscriptbuilder.web.views
interface View

View File

@@ -0,0 +1,30 @@
package dev.inmo.kmppscriptbuilder.web.views
import kotlinx.dom.appendElement
import org.w3c.dom.*
import kotlin.random.Random
fun HTMLElement.createTextField(
label: String,
placeholder: String
): HTMLInputElement {
val uuid = "r" + Random.nextLong()
return appendElement("div") {
classList.add("uk-margin", "uk-width-1-1")
appendElement("label") {
classList.add("uk-form-label")
setAttribute("for", uuid)
innerText = label
}
}.appendElement("input") {
id = uuid
classList.add("uk-input", "uk-width-expand")
setAttribute("type", "text")
setAttribute("placeholder", placeholder)
} as HTMLInputElement
}
fun HTMLElement.createButton(text: String): HTMLButtonElement = appendElement("button") {
classList.add("uk-button", "uk-button-primary")
innerHTML = text
} as HTMLButtonElement

View File

@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kotlin Publication Scripts Builder</title>
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.6.17/dist/css/uikit.min.css" />
</head>
<body>
<div uk-sticky="sel-target: .uk-navbar-container; cls-active: uk-navbar-sticky; bottom: #transparent-sticky-navbar">
<nav class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<div class="uk-padding-small uk-text-lead">Kotlin Publication Scripts Builder</div>
</div>
<div class="uk-navbar-right">
<ul class="uk-navbar-nav">
<li uk-tooltip="title: Open file"><a href="#"><span uk-icon="icon: pull"></span></a></li><!--Open file-->
<li uk-tooltip="title: Save file"><a href="#"><span uk-icon="icon: push"></span></a></li><!--Save file-->
</ul>
</div>
</nav>
</div>
<form class="uk-padding-small">
<fieldset class="uk-fieldset">
<legend class="uk-legend">Project type</legend>
<div class="uk-padding-small">
<ul class="uk-subnav uk-subnav-pill">
<li id="mppProjectType" class="uk-active"><a href="#">Multiplatform</a></li>
<li id="jvmProjectType"><a href="#">JVM</a></li>
</ul>
</div>
<legend class="uk-legend">Licenses</legend>
<div class="uk-padding-small">
<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>
<div class="uk-padding-small">
<div class="uk-margin uk-width-1-1">
<label class="uk-form-label" for="projectNameInput">Public project name</label>
<input id="projectNameInput" class="uk-input uk-width-expand" type="text" placeholder="${project.name}">
</div>
<div class="uk-margin uk-width-1-1">
<label class="uk-form-label" for="projectDescriptionInput">Public project description</label>
<input id="projectDescriptionInput" class="uk-input uk-width-expand" type="text" placeholder="${project.name}">
</div>
<div class="uk-margin uk-width-1-1">
<label class="uk-form-label" for="projectUrlInput">Public project URL</label>
<input id="projectUrlInput" class="uk-input uk-width-expand" type="text" placeholder="Type url to github or other source with readme">
</div>
<div class="uk-margin uk-width-1-1">
<label class="uk-form-label" for="projectVCSUrlInput">Public project VCS URL (with .git)</label>
<input id="projectVCSUrlInput" class="uk-input uk-width-expand" type="text" placeholder="Type url to github .git file">
</div>
<div class="uk-margin">
<label><input id="includeGpgSignToggle" class="uk-checkbox" type="checkbox" checked> Include GPG Signing</label>
</div>
<div class="uk-margin">
<label><input id="includeMavenCentralTargetRepoToggle" class="uk-checkbox" type="checkbox"> Include publication to MavenCentral</label>
</div>
</div>
<legend class="uk-legend">Developers info</legend>
<div id="developersListDiv" class="uk-padding-small">
</div>
<legend class="uk-legend">Repositories info</legend>
<div class="uk-padding-small">
<button class="uk-button uk-button-primary">Add repository</button>
</div>
</fieldset>
</form>
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/uikit@3.6.17/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/uikit@3.6.17/dist/js/uikit-icons.min.js"></script>
<!-- Internal JS -->
<script src="kmppscriptbuilder.web.js"></script>
</body>
</html>