Skip to content

Commit

Permalink
Create a simple main
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Oct 11, 2023
1 parent b9167c5 commit f75d531
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
plugins {
application
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlinx.serialization)
}

application {
mainClass = "com.ivy.quickcode.MainKt"
applicationName = "qc"
}

group = "com.ivy"
Expand All @@ -23,7 +25,7 @@ tasks.test {
}

kotlin {
jvmToolchain(8)
jvmToolchain(11)
}

dependencies {
Expand Down
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kotest = "5.7.2"
# Kotlin
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.6.0" }

# Arrow
arrowkt-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
Expand All @@ -26,7 +27,8 @@ kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-te
[bundles]
kotlin = [
"kotlin-stdlib",
"kotlin-coroutines-core"
"kotlin-coroutines-core",
"kotlinx-serialization-json"
]
testing = [
"mockk",
Expand All @@ -39,4 +41,5 @@ testing = [
]

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
4 changes: 4 additions & 0 deletions samples/hello.qc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello, {{name}}!
#if {{wishNiceDay}} #then
Have a nice day :)
#endif
4 changes: 4 additions & 0 deletions samples/hello_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Iliyan",
"wishNiceDay": true
}
38 changes: 37 additions & 1 deletion src/main/kotlin/com/ivy/quickcode/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
package com.ivy.quickcode

import com.ivy.quickcode.data.QCVariableValue
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.boolean
import kotlinx.serialization.json.booleanOrNull
import java.nio.file.Files
import java.nio.file.Paths

fun main(args: Array<String>) {
println("QuickCode compiler TODO...")
if (args.size != 2) {
println("Invalid arguments!")
return
}

val template = readFileContent(args[0])
val inputJson = readFileContent(args[1])
val rawInput: Map<String, JsonPrimitive> = Json.decodeFromString(inputJson)
val input = rawInput.map { (key, value) ->
key to when {
value.isString -> QCVariableValue.Str(value.content)
value.booleanOrNull != null -> QCVariableValue.Bool(value.boolean)
else -> error("Unsupported input type \"$key\"")
}
}.toMap()

println("Input:")
println(input)

val compiler = QuickCodeCompiler()
val result = compiler.execute(template, input)
println("----------------")
println("----------------")
println(result)
}

fun readFileContent(relativePath: String): String {
val path = Paths.get(relativePath)
return Files.readString(path)
}

0 comments on commit f75d531

Please sign in to comment.