Add custom repositories + arrow
This commit is contained in:
parent
3155a2bbe8
commit
6f691fcd75
15
config.toml
15
config.toml
@ -16,6 +16,15 @@ display = "Java Version"
|
|||||||
default = "1.4.10"
|
default = "1.4.10"
|
||||||
display = "Kotlin Version"
|
display = "Kotlin Version"
|
||||||
|
|
||||||
|
[repositories]
|
||||||
|
|
||||||
|
[repositories.jcenter]
|
||||||
|
url = "https://jcenter.bintray.com"
|
||||||
|
default = true # TODO: find where this is needed
|
||||||
|
|
||||||
|
[repositories.arrow]
|
||||||
|
url = "https://dl.bintray.com/arrow-kt/arrow-kt/"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[dependencies.http4k]
|
[dependencies.http4k]
|
||||||
@ -166,3 +175,9 @@ groupId = "org.jetbrains.kotlinx"
|
|||||||
artifactId = "kotlinx-serialization-runtime"
|
artifactId = "kotlinx-serialization-runtime"
|
||||||
version = "1.0-M1-1.4.0-rc"
|
version = "1.0-M1-1.4.0-rc"
|
||||||
category = "serialization"
|
category = "serialization"
|
||||||
|
|
||||||
|
[dependencies.Arrow-core]
|
||||||
|
groupId = "io.arrow-kt"
|
||||||
|
artifactId = "arrow-core"
|
||||||
|
version = "0.10.5"
|
||||||
|
repository = "arrow"
|
||||||
|
|||||||
@ -3,34 +3,47 @@ package starter
|
|||||||
import com.electronwill.nightconfig.core.file.FileConfig
|
import com.electronwill.nightconfig.core.file.FileConfig
|
||||||
import com.electronwill.nightconfig.core.Config as NightConfig
|
import com.electronwill.nightconfig.core.Config as NightConfig
|
||||||
|
|
||||||
data class StarterConfig(val dependencies: List<Dependency>, val inputs: List<Input>)
|
data class StarterConfig(
|
||||||
|
val dependencies: List<Dependency>,
|
||||||
|
val inputs: List<Input>,
|
||||||
|
val repositories: List<Repository>,
|
||||||
|
)
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
private fun FileConfig.configMap(key: String) = this.get<NightConfig>(key).valueMap() as Map<String, NightConfig>
|
||||||
|
|
||||||
fun load(): StarterConfig {
|
fun load(): StarterConfig {
|
||||||
val cfg = FileConfig.of("config.toml")
|
val cfg = FileConfig.of("config.toml")
|
||||||
cfg.load()
|
cfg.load()
|
||||||
val dependenciesNode: NightConfig = cfg["dependencies"]
|
|
||||||
@Suppress("UNCHECKED_CAST") val dependenciesMap = dependenciesNode.valueMap() as Map<String, NightConfig>
|
|
||||||
val dependencies = dependenciesMap.map { (name, values) ->
|
|
||||||
Dependency(
|
|
||||||
name,
|
|
||||||
values["groupId"],
|
|
||||||
values["artifactId"],
|
|
||||||
values["version"],
|
|
||||||
values.getOrElse("default", false),
|
|
||||||
values.getEnumOrElse("category", Category.Other),
|
|
||||||
values.getEnumOrElse("scope", Scope.Compile),
|
|
||||||
values["logger"],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val inputsNode: NightConfig = cfg["inputs"]
|
val dependencies = cfg.configMap("dependencies")
|
||||||
@Suppress("UNCHECKED_CAST") val inputMap = inputsNode.valueMap() as Map<String, NightConfig>
|
.map { (name, values) ->
|
||||||
val inputs = inputMap.map { (name, values) ->
|
Dependency(
|
||||||
Input(name, values["display"], values["default"])
|
name,
|
||||||
}
|
values["groupId"],
|
||||||
|
values["artifactId"],
|
||||||
|
values["version"],
|
||||||
|
values.getOrElse("default", false),
|
||||||
|
values.getEnumOrElse("category", Category.Other),
|
||||||
|
values.getEnumOrElse("scope", Scope.Compile),
|
||||||
|
values["logger"],
|
||||||
|
values["repository"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return StarterConfig(dependencies, inputs)
|
val inputs = cfg.configMap("inputs")
|
||||||
|
.map { (name, values) ->
|
||||||
|
Input(name, values["display"], values["default"])
|
||||||
|
}
|
||||||
|
|
||||||
|
val repositories = cfg.configMap("repositories")
|
||||||
|
.map { (name, values) ->
|
||||||
|
Repository(name, values["url"], values.getOrElse("default", false))
|
||||||
|
}
|
||||||
|
|
||||||
|
return StarterConfig(dependencies, inputs, repositories)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,11 @@ data class Dependency(
|
|||||||
val category: Category,
|
val category: Category,
|
||||||
val scope: Scope,
|
val scope: Scope,
|
||||||
val logger: String?,
|
val logger: String?,
|
||||||
|
val repository: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class Repository(val name: String, val url: String, val default: Boolean)
|
||||||
|
|
||||||
data class Input(val name: String, val display: String, val value: String? = null)
|
data class Input(val name: String, val display: String, val value: String? = null)
|
||||||
|
|
||||||
data class Project(
|
data class Project(
|
||||||
@ -26,4 +29,5 @@ data class Project(
|
|||||||
val basePackage: String,
|
val basePackage: String,
|
||||||
val inputs: List<Input>,
|
val inputs: List<Input>,
|
||||||
val dependencies: List<Dependency>,
|
val dependencies: List<Dependency>,
|
||||||
|
val repositories: List<Repository>,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -40,7 +40,10 @@ class Server(
|
|||||||
return@post
|
return@post
|
||||||
}
|
}
|
||||||
|
|
||||||
val project = Project(projectName, basePackage, inputs, deps)
|
val repositories = conf.repositories
|
||||||
|
.filter { repo -> repo.default || repo.name in deps.mapNotNull { it.repository } }
|
||||||
|
|
||||||
|
val project = Project(projectName, basePackage, inputs, deps, repositories)
|
||||||
|
|
||||||
ctx.contentType("application/zip")
|
ctx.contentType("application/zip")
|
||||||
ctx.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
ctx.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class PomTemplate(private val engine: PebbleEngine) : Template {
|
|||||||
override fun render(project: Project): String {
|
override fun render(project: Project): String {
|
||||||
val args: MutableMap<String, Any?> = mutableMapOf(
|
val args: MutableMap<String, Any?> = mutableMapOf(
|
||||||
"dependencies" to project.dependencies.sortedBy { it.scope },
|
"dependencies" to project.dependencies.sortedBy { it.scope },
|
||||||
|
"repositories" to project.repositories,
|
||||||
"kotlinxSerialization" to project.dependencies.any { it.name == "Kotlinx-serialization" },
|
"kotlinxSerialization" to project.dependencies.any { it.name == "Kotlinx-serialization" },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
{% for repo in repositories %}
|
||||||
<id>jcenter</id>
|
<repository>
|
||||||
<name>jcenter</name>
|
<id>{{ repo.name }}</id>
|
||||||
<url>https://jcenter.bintray.com</url>
|
<url>{{ repo.url }}</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
{% endfor %}
|
||||||
|
</repositories>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user