-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
128 lines (120 loc) · 4.77 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
plugins {
val kotlinVersion: String by System.getProperties()
kotlin("plugin.serialization") version kotlinVersion
kotlin("js") version kotlinVersion
}
version = "1.0.0-SNAPSHOT"
group = "me.rahimklaber"
repositories {
mavenCentral()
jcenter()
mavenLocal()
}
// Versions
val kotlinVersion: String by System.getProperties()
val kvisionVersion: String by System.getProperties()
val webDir = file("src/main/web")
kotlin {
js {
browser {
runTask {
outputFileName = "main.bundle.js"
sourceMaps = false
devServer = KotlinWebpackConfig.DevServer(
open = true,
port = 3000,
proxy = mutableMapOf(
"/kv/*" to "http://localhost:8080",
"/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
),
static = mutableListOf("$buildDir/processedResources/js/main")
)
}
webpackTask {
outputFileName = "main.bundle.js"
}
testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
sourceSets["main"].dependencies {
implementation("io.kvision:kvision:$kvisionVersion")
implementation("io.kvision:kvision-toast:$kvisionVersion")
implementation("io.kvision:kvision-bootstrap:$kvisionVersion")
implementation("io.kvision:kvision-bootstrap-css:$kvisionVersion")
implementation("io.kvision:kvision-routing-navigo-ng:$kvisionVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation(npm("stellar-sdk","8.2.5"))
// implementation(npm("stellar-base","5.3.2",generateExternals = false))
implementation(npm("node-polyfill-webpack-plugin","1.1.4"))
implementation(npm("@albedo-link/intent","^0.11.2"))
implementation(npm("ipfs-http-client","52.0.0",generateExternals = false))
}
sourceSets["test"].dependencies {
implementation(kotlin("test-js"))
implementation("io.kvision:kvision-testutils:$kvisionVersion")
}
sourceSets["main"].resources.srcDir(webDir)
}
fun getNodeJsBinaryExecutable(): String {
val nodeDir = NodeJsRootPlugin.apply(rootProject).nodeJsSetupTaskProvider.get().destination
val isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
val nodeBinDir = if (isWindows) nodeDir else nodeDir.resolve("bin")
val command = NodeJsRootPlugin.apply(rootProject).nodeCommand
val finalCommand = if (isWindows && command == "node") "node.exe" else command
return nodeBinDir.resolve(finalCommand).absolutePath
}
tasks {
create("generatePotFile", Exec::class) {
dependsOn("compileKotlinJs")
executable = getNodeJsBinaryExecutable()
args("${rootProject.buildDir}/js/node_modules/gettext-extract/bin/gettext-extract")
inputs.files(kotlin.sourceSets["main"].kotlin.files)
outputs.file("$projectDir/src/main/resources/i18n/messages.pot")
}
}
afterEvaluate {
tasks {
getByName("processResources", Copy::class) {
dependsOn("compileKotlinJs")
exclude("**/*.pot")
doLast("Convert PO to JSON") {
destinationDir.walkTopDown().filter {
it.isFile && it.extension == "po"
}.forEach {
exec {
executable = getNodeJsBinaryExecutable()
args(
"${rootProject.buildDir}/js/node_modules/gettext.js/bin/po2json",
it.absolutePath,
"${it.parent}/${it.nameWithoutExtension}.json"
)
println("Converted ${it.name} to ${it.nameWithoutExtension}.json")
}
it.delete()
}
}
}
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)
}
}
}