diff --git a/build.gradle.kts b/build.gradle.kts index 5cd03a1..f1d6e8c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,93 +1,182 @@ +import java.nio.file.Files +import java.nio.file.Paths + buildscript { - apply(from = "common.gradle.kts") + apply(from = "common.gradle.kts") + apply(from = "version.gradle.kts") } plugins { - kotlin("multiplatform") - id("maven-publish") - application + kotlin("multiplatform") + id("maven-publish") + application } kotlin { - js { - compilerOptions { - target.set("es2015") - } - //useEsModules() - //useCommonJs() - - binaries.executable() - browser { - commonWebpackConfig { - outputFileName = "vst-chip-worklet-ui.js" - sourceMaps = true - } - - distribution { - outputDirectory.set(File("$projectDir/web/")) - } - } + js { + compilerOptions { + target.set("es2015") } - /* - @OptIn(ExperimentalWasmDsl::class) - wasmJs { - binaries.executable() - browser{ - distribution { - outputDirectory.set(File("$projectDir/web/")) + //useEsModules() + //useCommonJs() + + binaries.executable() + browser { + commonWebpackConfig { + outputFileName = "vst-chip-worklet-ui.js" + sourceMaps = true + } + + distribution { + outputDirectory.set(File("$projectDir/web/")) + } + } + } + /* + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + binaries.executable() + browser{ + distribution { + outputDirectory.set(File("$projectDir/web/")) + } + } + + mavenPublication { + groupId = group as String + pom { name = "${project.name}-wasm-js" } + } + } + */ + jvm { + withJava() + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":common")) + //base + implementation("nl.astraeus:kotlin-css-generator:1.0.10") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0") + implementation("nl.astraeus:vst-ui-base:1.1.2") + } + } + val jsMain by getting { + dependencies { + implementation("nl.astraeus:kotlin-komponent:1.2.4") + } + } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + /* val wasmJsMain by getting { + dependencies { + implementation("nl.astraeus:kotlin-komponent:1.2.4-SNAPSHOT") + implementation("nl.astraeus:vst-ui-base:1.0.1-SNAPSHOT") } - } + }*/ + val jvmMain by getting { + dependencies { + //base - mavenPublication { - groupId = group as String - pom { name = "${project.name}-wasm-js" } - } - } - */ - jvm{ - withJava() - } - - sourceSets { - val commonMain by getting { - dependencies { - implementation(project(":common")) - //base - api("nl.astraeus:kotlin-css-generator:1.0.9-SNAPSHOT") - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0") - } - } - val jsMain by getting { - dependencies { - implementation("nl.astraeus:kotlin-komponent:1.2.4-SNAPSHOT") - implementation("nl.astraeus:vst-ui-base:1.0.1-SNAPSHOT") - } - } - val jsTest by getting { - dependencies { - implementation(kotlin("test-js")) - } - } - /* val wasmJsMain by getting { - dependencies { - implementation("nl.astraeus:kotlin-komponent:1.2.4-SNAPSHOT") - implementation("nl.astraeus:vst-ui-base:1.0.1-SNAPSHOT") - } - }*/ - val jvmMain by getting { - dependencies { - //base - - implementation("io.undertow:undertow-core:2.3.14.Final") - implementation("io.undertow:undertow-websockets-jsr:2.3.14.Final") - implementation("org.jboss.xnio:xnio-nio:3.8.16.Final") - - implementation("org.xerial:sqlite-jdbc:3.46.0.0") - implementation("com.zaxxer:HikariCP:4.0.3") - implementation("nl.astraeus:simple-jdbc-stats:1.6.1") - - implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.11.0") - } - } + implementation("io.undertow:undertow-core:2.3.14.Final") + implementation("io.undertow:undertow-websockets-jsr:2.3.14.Final") + implementation("org.jboss.xnio:xnio-nio:3.8.16.Final") + + implementation("org.xerial:sqlite-jdbc:3.46.0.0") + implementation("com.zaxxer:HikariCP:4.0.3") + implementation("nl.astraeus:simple-jdbc-stats:1.6.1") + + implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.11.0") + } } + } +} + +application { + mainClass.set("nl.astraeus.vst.chip.MainKt") +} + +/* Hardcoded deploy configuration */ + +val deployDirectory = "vst-chip.midi-vst.com" + +tasks.register("unzipDistribution") { + mustRunAfter("removeSymbolicLink") + val zipDir = layout.projectDirectory.dir("build/distributions") + val zipFile = zipDir.file("${project.name}-${project.version}.zip") + + val outputDir = file("/home/rnentjes/www/${deployDirectory}") + + from(zipTree(zipFile)) + into(outputDir) +} + +tasks.register("createSymbolicLink") { + mustRunAfter("unzipDistribution") + doLast { + val targetDir = + Paths.get("/home/rnentjes/www/${deployDirectory}/${project.name}-${project.version}") // Directory to link to + val symlink = + Paths.get("/home/rnentjes/www/${deployDirectory}/${project.name}") // Path for the symbolic link + + if (!Files.exists(targetDir)) { + throw IllegalArgumentException("Target directory does not exist: $targetDir") + } + + if (Files.exists(symlink)) { + println("Symbolic link already exists: $symlink") + } else { + Files.createSymbolicLink(symlink, targetDir) + println("Symbolic link created: $symlink -> $targetDir") + } + } +} + +tasks.register("copyWeb") { + val webDir = layout.projectDirectory.dir("web") + val outputDir = file("/home/rnentjes/www/${deployDirectory}/web") + + from(webDir) + into(outputDir) +} + +tasks.named("build") { + dependsOn("generateVersionProperties") +} + +tasks.named("kotlinUpgradeYarnLock") { + mustRunAfter("clean") +} + +tasks.named("build") { + mustRunAfter("kotlinUpgradeYarnLock") +} + +tasks.named("build") { + mustRunAfter("kotlinUpgradeYarnLock") +} + +tasks.named("copyWeb") { + mustRunAfter("build") +} + +tasks.register("removeSymbolicLink") { + mustRunAfter("build") + doLast { + delete(layout.projectDirectory.file("/home/rnentjes/www/${deployDirectory}/${project.name}")) + } +} + +tasks.register("deploy") { + dependsOn("clean") + dependsOn("kotlinUpgradeYarnLock") + dependsOn("build") + dependsOn("copyWeb") + dependsOn("removeSymbolicLink") + dependsOn("unzipDistribution") + dependsOn("createSymbolicLink") } diff --git a/common.gradle.kts b/common.gradle.kts index e923fa6..0ea050f 100644 --- a/common.gradle.kts +++ b/common.gradle.kts @@ -1,9 +1,12 @@ group = "nl.astraeus" -version = "1.0.0-SNAPSHOT" +version = "0.1.0" allprojects { repositories { mavenLocal() mavenCentral() + maven { + url = uri("https://gitea.astraeus.nl:8443/api/packages/rnentjes/maven") + } } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index bdc9e38..57e87ec 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,36 +1,36 @@ @file:OptIn(ExperimentalKotlinGradlePluginApi::class) import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi -import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl buildscript { - apply(from = "../common.gradle.kts") + apply(from = "../common.gradle.kts") } plugins { - kotlin("multiplatform") + kotlin("multiplatform") } kotlin { - js { - compilerOptions { - target.set("es2015") - } - browser() + js { + compilerOptions { + target.set("es2015") } - @OptIn(ExperimentalWasmDsl::class) - wasmJs { browser() - mavenPublication { - groupId = group as String - pom { name = "${project.name}-wasm-js" } - } } - jvm() + /* @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser() + mavenPublication { + groupId = group as String + pom { name = "${project.name}-wasm-js" } + } + }*/ + jvm() - sourceSets { - val commonMain by getting - val jsMain by getting - val wasmJsMain by getting - } + sourceSets { + val commonMain by getting + val jsMain by getting + val jvmMain by getting + //val wasmJsMain by getting + } } diff --git a/settings.common.gradle.kts b/settings.common.gradle.kts index a098f32..c91fbbe 100644 --- a/settings.common.gradle.kts +++ b/settings.common.gradle.kts @@ -1,7 +1,8 @@ +import jdk.tools.jlink.resources.plugins + pluginManagement { plugins { - kotlin("multiplatform") version "2.0.20-RC" - id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" + kotlin("multiplatform") version "2.0.21" } repositories { gradlePluginPortal() diff --git a/src/jvmMain/kotlin/nl/astraeus/vst/chip/Main.kt b/src/jvmMain/kotlin/nl/astraeus/vst/chip/Main.kt index 7b42e14..07db578 100644 --- a/src/jvmMain/kotlin/nl/astraeus/vst/chip/Main.kt +++ b/src/jvmMain/kotlin/nl/astraeus/vst/chip/Main.kt @@ -1,15 +1,9 @@ package nl.astraeus.vst.chip -import com.zaxxer.hikari.HikariConfig -import io.undertow.Undertow -import io.undertow.UndertowOptions -import io.undertow.server.session.InMemorySessionManager -import io.undertow.server.session.SessionAttachmentHandler -import io.undertow.server.session.SessionCookieConfig -import nl.astraeus.vst.chip.db.Database +import nl.astraeus.vst.base.Settings +import nl.astraeus.vst.base.web.UndertowServer import nl.astraeus.vst.chip.logger.LogLevel import nl.astraeus.vst.chip.logger.Logger -import nl.astraeus.vst.chip.web.RequestHandler fun main() { Logger.level = LogLevel.DEBUG @@ -18,32 +12,44 @@ fun main() { e.printStackTrace() } - Class.forName("nl.astraeus.jdbc.Driver") + Settings.port = 9005 + Settings.jdbcStatsPort = 6005 - Database.initialize(HikariConfig().apply { - driverClassName = "nl.astraeus.jdbc.Driver" - jdbcUrl = "jdbc:stat:webServerPort=6002:jdbc:sqlite:data/chip.db" - username = "sa" - password = "" - maximumPoolSize = 25 - isAutoCommit = false + /* + Class.forName("nl.astraeus.jdbc.Driver") - validate() - }) + Database.initialize(HikariConfig().apply { + driverClassName = "nl.astraeus.jdbc.Driver" + jdbcUrl = "jdbc:stat:webServerPort=6002:jdbc:sqlite:data/chip.db" + username = "sa" + password = "" + maximumPoolSize = 25 + isAutoCommit = false - val sessionHandler = SessionAttachmentHandler( - InMemorySessionManager("vst-session-manager"), - SessionCookieConfig() + validate() + }) + + val sessionHandler = SessionAttachmentHandler( + InMemorySessionManager("vst-session-manager"), + SessionCookieConfig() + ) + sessionHandler.setNext(RequestHandler) + + val server = Undertow.builder() + .addHttpListener(Settings.port, "localhost") + .setIoThreads(4) + .setHandler(sessionHandler) + .setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 1000) + .build() + + println("Starting server at port ${Settings.port}...") + server?.start() + */ + + + + UndertowServer.start( + "Vst Chip", + "/vst-chip-worklet-ui.js" ) - sessionHandler.setNext(RequestHandler) - - val server = Undertow.builder() - .addHttpListener(Settings.port, "localhost") - .setIoThreads(4) - .setHandler(sessionHandler) - .setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 1000) - .build() - - println("Starting server at port ${Settings.port}...") - server?.start() } diff --git a/version.gradle.kts b/version.gradle.kts new file mode 100644 index 0000000..a5b8176 --- /dev/null +++ b/version.gradle.kts @@ -0,0 +1,20 @@ +import java.util.* + +tasks.register("generateVersionProperties") { + doLast { + val versionDir = layout.buildDirectory.dir("processedResources/jvm/main") + val versionFile = versionDir.get().file("version.properties").asFile + versionDir.get().asFile.mkdirs() + + val properties = Properties().apply { + setProperty("group", project.group.toString()) + setProperty("name", project.name.toString()) + setProperty("version", project.version.toString()) + setProperty("buildTime", Date().toString()) + } + + versionFile.writer().use { writer -> + properties.store(writer, "Version information") + } + } +} \ No newline at end of file