You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2020/03/28 16:49:06 UTC
[isis] 03/03: ISIS-2324 prepare switch to build.gradle.kts
This is an automated email from the ASF dual-hosted git repository.
joergrade pushed a commit to branch ISIS-2324-Merge-kroviz
in repository https://gitbox.apache.org/repos/asf/isis.git
commit dc5dfe05c6706168cb13c76ad28304aa605e2c87
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Sat Mar 28 17:48:30 2020 +0100
ISIS-2324 prepare switch to build.gradle.kts
---
incubator/clients/kroviz/build.gradle | 19 ++-
incubator/clients/kroviz/build.gradle.kts | 211 ++++++++++++++++++++++++++++++
2 files changed, 228 insertions(+), 2 deletions(-)
diff --git a/incubator/clients/kroviz/build.gradle b/incubator/clients/kroviz/build.gradle
index 0a1fbdf..5db2658 100644
--- a/incubator/clients/kroviz/build.gradle
+++ b/incubator/clients/kroviz/build.gradle
@@ -3,10 +3,20 @@ buildscript {
ext.production = (findProperty('prod') ?: 'false') == 'true'
repositories {
+ mavenCentral()
+ jcenter()
maven { url = 'https://dl.bintray.com/kotlin/kotlin-eap' }
- maven { url = 'https://plugins.gradle.org/m2/' }
maven { url = 'https://kotlin.bintray.com/kotlinx' }
- mavenCentral()
+ maven { url = 'https://dl.bintray.com/kotlin/kotlin-js-wrappers' }
+ maven {
+ url = uri("https://dl.bintray.com/gbaldeck/kotlin")
+ metadataSources {
+ mavenPom()
+ artifact()
+ }
+ }
+ maven { url = 'https://dl.bintray.com/rjaros/kotlin' }
+ mavenLocal()
}
dependencies {
@@ -117,6 +127,11 @@ task copyResourcesForDce() {
include "css/**"
include "img/**"
include "js/**"
+ if (kvmodule == "kvision") {
+ into("kvision/$kvisionVersion")
+ } else {
+ into("kvision-$kvmodule/$kvisionVersion")
+ }
}
}
}
diff --git a/incubator/clients/kroviz/build.gradle.kts b/incubator/clients/kroviz/build.gradle.kts
new file mode 100644
index 0000000..f05f8ed
--- /dev/null
+++ b/incubator/clients/kroviz/build.gradle.kts
@@ -0,0 +1,211 @@
+import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
+import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
+import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
+import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce
+
+buildscript {
+ extra.set("production", (findProperty("prod") ?: findProperty("production") ?: "false") == "true")
+}
+
+plugins {
+ val kotlinVersion: String by System.getProperties()
+ id("kotlinx-serialization") version kotlinVersion
+ kotlin("js") version kotlinVersion
+}
+
+version = "2.0.0-M3-SNAPSHOT"
+group = "org.apache.isis.incubator"
+
+repositories {
+ mavenCentral()
+ jcenter()
+ maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
+ maven { url = uri("https://kotlin.bintray.com/kotlinx") }
+ maven { url = uri("https://dl.bintray.com/kotlin/kotlin-js-wrappers") }
+ maven {
+ url = uri("https://dl.bintray.com/gbaldeck/kotlin")
+ metadataSources {
+ mavenPom()
+ artifact()
+ }
+ }
+ maven { url = uri("https://dl.bintray.com/rjaros/kotlin") }
+ mavenLocal()
+}
+
+// Versions
+val kotlinVersion: String by System.getProperties()
+val kvisionVersion: String by System.getProperties()
+
+// Custom Properties
+val webDir = file("src/main/web")
+val isProductionBuild = project.extra.get("production") as Boolean
+
+kotlin {
+ target {
+ compilations.all {
+ kotlinOptions {
+ moduleKind = "umd"
+ sourceMap = !isProductionBuild
+ if (!isProductionBuild) {
+ sourceMapEmbedSources = "always"
+ }
+ }
+ }
+ browser {
+ runTask {
+ outputFileName = "main.bundle.js"
+ devServer = KotlinWebpackConfig.DevServer(
+ open = false,
+ port = 3000,
+ proxy = mapOf(
+ "/kv/*" to "http://localhost:8080",
+ "/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
+ ),
+ contentBase = listOf("$buildDir/processedResources/Js/main")
+ )
+ }
+ testTask {
+ useKarma {
+ useChromeHeadless()
+ }
+ }
+ }
+ }
+ sourceSets["main"].dependencies {
+ implementation(kotlin("stdlib-js"))
+ implementation(npm("po2json"))
+ implementation(npm("grunt"))
+ implementation(npm("grunt-pot"))
+
+ implementation("pl.treksoft:kvision:$kvisionVersion")
+ implementation("pl.treksoft:kvision-i18n:$kvisionVersion")
+ }
+ sourceSets["test"].dependencies {
+ implementation(kotlin("test-js"))
+ implementation("pl.treksoft:kvision-testutils:$kvisionVersion:tests")
+ }
+ sourceSets["main"].resources.srcDir(webDir)
+}
+
+fun getNodeJsBinaryExecutable(): String {
+ val nodeDir = NodeJsRootPlugin.apply(project).nodeJsSetupTask.destination
+ val isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
+ val nodeBinDir = if (isWindows) nodeDir else nodeDir.resolve("bin")
+ val command = NodeJsRootPlugin.apply(project).nodeCommand
+ val finalCommand = if (isWindows && command == "node") "node.exe" else command
+ return nodeBinDir.resolve(finalCommand).absolutePath
+}
+
+tasks {
+ withType<KotlinJsDce> {
+ doLast {
+ copy {
+ file("$buildDir/tmp/expandedArchives/").listFiles()?.forEach {
+ if (it.isDirectory && it.name.startsWith("kvision")) {
+ from(it) {
+ include("css/**")
+ include("img/**")
+ include("js/**")
+ }
+ }
+ }
+ into(file("${buildDir.path}/js/packages/${project.name}/kotlin-dce"))
+ }
+ }
+ }
+ create("generateGruntfile") {
+ outputs.file("$buildDir/js/Gruntfile.js")
+ doLast {
+ file("$buildDir/js/Gruntfile.js").run {
+ writeText(
+ """
+ module.exports = function (grunt) {
+ grunt.initConfig({
+ pot: {
+ options: {
+ text_domain: "messages",
+ dest: "../../src/main/resources/i18n/",
+ keywords: ["tr", "ntr:1,2", "gettext", "ngettext:1,2"],
+ encoding: "UTF-8"
+ },
+ files: {
+ src: ["../../src/main/kotlin/**/*.kt"],
+ expand: true,
+ },
+ }
+ });
+ grunt.loadNpmTasks("grunt-pot");
+ };
+ """.trimIndent()
+ )
+ }
+ }
+ }
+ create("generatePotFile", Exec::class) {
+ dependsOn("kotlinNpmInstall", "generateGruntfile")
+ workingDir = file("$buildDir/js")
+ executable = getNodeJsBinaryExecutable()
+ args("$buildDir/js/node_modules/grunt/bin/grunt", "pot")
+ inputs.files(kotlin.sourceSets["main"].kotlin.files)
+ outputs.file("$projectDir/src/main/resources/i18n/messages.pot")
+ }
+}
+afterEvaluate {
+ tasks {
+ getByName("processResources", Copy::class) {
+ dependsOn("kotlinNpmInstall")
+ exclude("**/*.pot")
+ doLast("Convert PO to JSON") {
+ destinationDir.walkTopDown().filter {
+ it.isFile && it.extension == "po"
+ }.forEach {
+ exec {
+ executable = getNodeJsBinaryExecutable()
+ args(
+ "$buildDir/js/node_modules/po2json/bin/po2json",
+ it.absolutePath,
+ "${it.parent}/${it.nameWithoutExtension}.json",
+ "-f",
+ "jed1.x"
+ )
+ println("Converted ${it.name} to ${it.nameWithoutExtension}.json")
+ }
+ it.delete()
+ }
+ copy {
+ file("$buildDir/tmp/expandedArchives/").listFiles()?.forEach {
+ if (it.isDirectory && it.name.startsWith("kvision")) {
+ val kvmodule = it.name.split("-$kvisionVersion").first()
+ from(it) {
+ include("css/**")
+ include("img/**")
+ include("js/**")
+ if (kvmodule == "kvision") {
+ into("kvision/$kvisionVersion")
+ } else {
+ into("kvision-$kvmodule/$kvisionVersion")
+ }
+ }
+ }
+ }
+ into(file(buildDir.path + "/js/packages_imported"))
+ }
+ }
+ }
+ create("zip", Zip::class) {
+ dependsOn("browserProductionWebpack")
+ group = "package"
+ destinationDirectory.set(file("$buildDir/libs"))
+ val distribution =
+ project.tasks.getByName("browserProductionWebpack", KotlinWebpack::class).destinationDirectory!!
+ from(distribution) {
+ include("*.*")
+ }
+ from(webDir)
+ duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+ inputs.files(distribution, webDir)
+ outputs.file(archiveFile)
+ }
+ }
+}