-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Chase22/migrate-to-kotlin-js
migrate-to-kotlin-js
- Loading branch information
Showing
48 changed files
with
3,751 additions
and
9,167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ node_modules | |
.gradle | ||
.idea | ||
|
||
build | ||
build | ||
|
||
.kotlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,117 @@ | ||
import de.chasenet.foxhole.DownloadJsonDataTask | ||
import de.chasenet.foxhole.GenerateIndexFileTask | ||
import groovy.json.JsonSlurper | ||
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile | ||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget | ||
|
||
plugins { | ||
base | ||
id("html-builder") | ||
kotlin("multiplatform") version "2.1.0" | ||
kotlin("plugin.serialization") version "2.1.0" | ||
} | ||
|
||
abstract class YarnExec : AbstractExecTask<YarnExec>(YarnExec::class.java) { | ||
@get:Input | ||
abstract val script: Property<String> | ||
val modules = arrayOf("mpf-calculator") | ||
|
||
init { | ||
group = "yarn" | ||
dependencies { | ||
commonMainImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") | ||
commonTestImplementation(kotlin("test")) | ||
} | ||
|
||
val htmlDir = | ||
provider { | ||
tasks.getByName<ProcessResources>("htmlGeneratorProcessResources").destinationDir | ||
} | ||
|
||
override fun exec() { | ||
commandLine("sh") | ||
workingDir(this.project.projectDir) | ||
args("-c", "yarn ${script.get()}") | ||
logging.captureStandardOutput(LogLevel.INFO) | ||
logging.captureStandardError(LogLevel.ERROR) | ||
super.exec() | ||
kotlin { | ||
modules.forEach { | ||
js(it, IR) { | ||
browser { | ||
binaries.executable() | ||
|
||
commonWebpackConfig { | ||
cssSupport { | ||
enabled = true | ||
} | ||
} | ||
|
||
webpackTask { | ||
sourceMaps = true | ||
mainOutputFileName = "$it.js" | ||
} | ||
|
||
runTask { | ||
sourceMaps = true | ||
mainOutputFileName = "$it.js" | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
jvm("htmlGenerator") | ||
sourceSets { | ||
this.getByName("htmlGeneratorMain") { | ||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.11.0") | ||
} | ||
} | ||
|
||
JsonSlurper().parse(file("package.json")) | ||
.uncheckedCast<Map<String, Any>>() | ||
.get("scripts") | ||
.uncheckedCast<Map<String, Any>>() | ||
.keys.forEach { | ||
task<YarnExec>("yarn_$it") { | ||
dependsOn("yarn_setup") | ||
script = it | ||
modules.forEach { module -> | ||
named("${module}Main") { | ||
resources.srcDirs( | ||
htmlDir, | ||
provider { | ||
downloadJsonData.outputFile | ||
.get() | ||
.asFile.parentFile | ||
}, | ||
) | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.10.1") | ||
} | ||
} | ||
} | ||
} | ||
|
||
task<YarnExec>("yarn_setup") { | ||
script = "" | ||
} | ||
tasks.withType<KotlinJsCompile>().configureEach { | ||
compilerOptions { | ||
target = "es2015" | ||
this.moduleKind = JsModuleKind.MODULE_ES | ||
} | ||
} | ||
|
||
val downloadJsonData = tasks.register<DownloadJsonDataTask>("downloadJsonData") | ||
|
||
val generateIndexFile = tasks.register<GenerateIndexFileTask>("generateIndexFile") { | ||
dependsOn(downloadJsonData) | ||
val downloadJsonData = | ||
task<DownloadJsonDataTask>("downloadJsonData") { | ||
outputFile = layout.buildDirectory.dir("json").map { it.file("foxhole.json") } | ||
} | ||
|
||
foxholeJsonDataFile.set(downloadJsonData.flatMap { it.outputFile }) | ||
val htmlGeneratorJar by tasks.existing | ||
val htmlGeneratorRuntimeClasspath by configurations.existing | ||
|
||
outputFile = layout.projectDirectory.dir("src/generated").file("index.html") | ||
val buildHtml = | ||
task<JavaExec>("buildHtml") { | ||
dependsOn(downloadJsonData) | ||
|
||
} | ||
outputs.dir(htmlDir) | ||
|
||
tasks.named("yarn_build") { | ||
dependsOn(generateIndexFile) | ||
} | ||
group = "build" | ||
|
||
tasks.named("yarn_start") { | ||
dependsOn(generateIndexFile) | ||
} | ||
classpath(htmlGeneratorJar, htmlGeneratorRuntimeClasspath) | ||
mainClass = "de.chasenet.foxhole.MainKt" | ||
|
||
tasks.build { | ||
dependsOn("yarn_build") | ||
} | ||
args( | ||
htmlDir.get().absolutePath, | ||
downloadJsonData.outputFile | ||
.get() | ||
.asFile.absolutePath, | ||
) | ||
} | ||
|
||
tasks.check { | ||
dependsOn("yarn_test-ci") | ||
kotlin.targets.withType<KotlinJsIrTarget>().configureEach { | ||
runTask.configure { | ||
dependsOn(buildHtml) | ||
} | ||
} | ||
|
||
tasks.clean { | ||
dependsOn("yarn_clean") | ||
tasks.withType<ProcessResources> { | ||
if (name == "htmlGeneratorProcessResources") return@withType | ||
dependsOn(buildHtml, downloadJsonData) | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Any?.uncheckedCast(): T = this as T |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.