Compare commits
17 Commits
zip
...
ce92e1fae9
| Author | SHA1 | Date | |
|---|---|---|---|
| ce92e1fae9 | |||
| 724f1c87b1 | |||
| 82214d327a | |||
| 92430510b6 | |||
| 8a08520267 | |||
| 0d47b51f3f | |||
| cd628f48b7 | |||
| dc6377179c | |||
| 2c0a1e44ec | |||
| 6f691fcd75 | |||
| 3155a2bbe8 | |||
| 91a82c3736 | |||
| 8ea5207cde | |||
| deb086f4b9 | |||
| c7a199fb2f | |||
| 658ac10375 | |||
| 94269c7a87 |
+2
-1
@@ -38,4 +38,5 @@ node_modules/
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.yarn-integrity
|
.yarn-integrity
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
*.zip
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
FROM openjdk:14-alpine as jdkbuilder
|
||||||
|
RUN apk add --no-cache binutils
|
||||||
|
ENV MODULES java.base,java.xml,jdk.httpserver
|
||||||
|
RUN jlink --output /myjdk --module-path $JAVA_HOME/jmods --add-modules $MODULES --no-header-files --no-man-pages --strip-debug --compress=2
|
||||||
|
RUN strip -p --strip-unneeded /myjdk/lib/server/libjvm.so
|
||||||
|
|
||||||
|
FROM maven:3.6.3-jdk-14 as builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY pom.xml .
|
||||||
|
RUN mvn verify clean --fail-never
|
||||||
|
COPY src/main src/main
|
||||||
|
RUN mvn package
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
ENV APPLICATION_USER app
|
||||||
|
RUN adduser -D -g '' $APPLICATION_USER
|
||||||
|
RUN mkdir /app
|
||||||
|
RUN chown -R $APPLICATION_USER /app
|
||||||
|
USER $APPLICATION_USER
|
||||||
|
COPY --from=builder /app/target/kotlin-starter*.jar /app/app.jar
|
||||||
|
COPY --from=jdkbuilder /myjdk /myjdk
|
||||||
|
COPY config.toml /app/config.toml
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 7000
|
||||||
|
CMD ["/myjdk/bin/java", "-server", "-Xmx64m", "-XX:+UseG1GC", "-XX:+UseStringDeduplication", "-jar", "app.jar"]
|
||||||
+60
-9
@@ -16,32 +16,53 @@ 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"
|
||||||
|
|
||||||
|
[repositories.arrow]
|
||||||
|
url = "https://dl.bintray.com/arrow-kt/arrow-kt/"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[dependencies.http4k]
|
[dependencies.http4k]
|
||||||
groupId = "org.http4k"
|
groupId = "org.http4k"
|
||||||
artifactId = "http4k-core"
|
artifactId = "http4k-core"
|
||||||
version = "3.260.0"
|
version = "3.261.0"
|
||||||
category = "server"
|
category = "server"
|
||||||
default = true
|
default = true
|
||||||
|
|
||||||
[dependencies.http4k-server-jetty]
|
[dependencies.http4k-server-jetty]
|
||||||
groupId = "org.http4k"
|
groupId = "org.http4k"
|
||||||
artifactId = "http4k-server-jetty"
|
artifactId = "http4k-server-jetty"
|
||||||
version = "3.260.0"
|
version = "3.261.0"
|
||||||
category = "server"
|
category = "server"
|
||||||
default = true
|
default = true
|
||||||
|
logger = "org.eclipse.jetty"
|
||||||
|
|
||||||
[dependencies.http4k-server-apache]
|
[dependencies.http4k-server-apache]
|
||||||
groupId = "org.http4k"
|
groupId = "org.http4k"
|
||||||
artifactId = "http4k-server-apache"
|
artifactId = "http4k-server-apache"
|
||||||
version = "3.260.0"
|
version = "3.261.0"
|
||||||
category = "server"
|
category = "server"
|
||||||
|
|
||||||
[dependencies.http4k-client-apache]
|
[dependencies.http4k-client-apache]
|
||||||
groupId = "org.http4k"
|
groupId = "org.http4k"
|
||||||
artifactId = "http4k-server-apache"
|
artifactId = "http4k-client-apache"
|
||||||
version = "3.260.0"
|
version = "3.261.0"
|
||||||
|
category = "server"
|
||||||
|
|
||||||
|
[dependencies.http4k-format-jackson]
|
||||||
|
groupId = "org.http4k"
|
||||||
|
artifactId = "http4k-format-jackson"
|
||||||
|
version = "3.261.0"
|
||||||
|
category = "server"
|
||||||
|
|
||||||
|
[dependencies.http4k-contract]
|
||||||
|
groupId = "org.http4k"
|
||||||
|
artifactId = "http4k-contract"
|
||||||
|
version = "3.261.0"
|
||||||
category = "server"
|
category = "server"
|
||||||
|
|
||||||
[dependencies.javalin]
|
[dependencies.javalin]
|
||||||
@@ -49,12 +70,19 @@ groupId = "io.javalin"
|
|||||||
artifactId = "javalin"
|
artifactId = "javalin"
|
||||||
version = "3.10.1"
|
version = "3.10.1"
|
||||||
category = "server"
|
category = "server"
|
||||||
|
logger = "org.eclipse.jetty"
|
||||||
|
|
||||||
[dependencies.pebble]
|
[dependencies.pebble]
|
||||||
groupId = "io.pebbletemplates"
|
groupId = "io.pebbletemplates"
|
||||||
artifactId = "pebble"
|
artifactId = "pebble"
|
||||||
version = "3.1.4"
|
version = "3.1.4"
|
||||||
default = true
|
default = true
|
||||||
|
logger = "com.mitchellbosecke.pebble"
|
||||||
|
|
||||||
|
[dependencies.caffeine]
|
||||||
|
groupId = "com.github.ben-manes.caffeine"
|
||||||
|
artifactId = "caffeine"
|
||||||
|
version = "2.8.5"
|
||||||
|
|
||||||
[dependencies.logback]
|
[dependencies.logback]
|
||||||
groupId = "ch.qos.logback"
|
groupId = "ch.qos.logback"
|
||||||
@@ -79,18 +107,21 @@ groupId = "org.flywaydb"
|
|||||||
artifactId = "flyway-core"
|
artifactId = "flyway-core"
|
||||||
version = "6.5.4"
|
version = "6.5.4"
|
||||||
category = "database"
|
category = "database"
|
||||||
|
logger = "org.flywaydb.core"
|
||||||
|
|
||||||
[dependencies.HikariCP]
|
[dependencies.HikariCP]
|
||||||
groupId = "com.zaxxer"
|
groupId = "com.zaxxer"
|
||||||
artifactId = "HikariCP"
|
artifactId = "HikariCP"
|
||||||
version = "3.4.5"
|
version = "3.4.5"
|
||||||
category = "database"
|
category = "database"
|
||||||
|
logger = "com.zaxxer.hikari"
|
||||||
|
|
||||||
[dependencies.Ktorm]
|
[dependencies.Ktorm]
|
||||||
groupId = "me.liuwj.ktorm"
|
groupId = "me.liuwj.ktorm"
|
||||||
artifactId = "ktorm-core"
|
artifactId = "ktorm-core"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
category = "database"
|
category = "database"
|
||||||
|
logger = "me.liuwj.ktorm.database"
|
||||||
|
|
||||||
[dependencies.Ktorm-Mysql]
|
[dependencies.Ktorm-Mysql]
|
||||||
groupId = "me.liuwj.ktorm"
|
groupId = "me.liuwj.ktorm"
|
||||||
@@ -101,7 +132,7 @@ category = "database"
|
|||||||
[dependencies.junit]
|
[dependencies.junit]
|
||||||
groupId = "org.junit.jupiter"
|
groupId = "org.junit.jupiter"
|
||||||
artifactId = "junit-jupiter"
|
artifactId = "junit-jupiter"
|
||||||
version = "5.6.2"
|
version = "5.7.0"
|
||||||
scope = "test"
|
scope = "test"
|
||||||
category = "test"
|
category = "test"
|
||||||
default = true
|
default = true
|
||||||
@@ -109,7 +140,7 @@ default = true
|
|||||||
[dependencies.junit-params]
|
[dependencies.junit-params]
|
||||||
groupId = "org.junit.jupiter"
|
groupId = "org.junit.jupiter"
|
||||||
artifactId = "junit-jupiter-params"
|
artifactId = "junit-jupiter-params"
|
||||||
version = "5.6.2"
|
version = "5.7.0"
|
||||||
scope = "test"
|
scope = "test"
|
||||||
category = "test"
|
category = "test"
|
||||||
default = true
|
default = true
|
||||||
@@ -131,7 +162,7 @@ category = "test"
|
|||||||
[dependencies.assertJ]
|
[dependencies.assertJ]
|
||||||
groupId = "org.assertj"
|
groupId = "org.assertj"
|
||||||
artifactId = "assertj-core"
|
artifactId = "assertj-core"
|
||||||
version = "3.16.1"
|
version = "3.17.2"
|
||||||
scope = "test"
|
scope = "test"
|
||||||
category = "test"
|
category = "test"
|
||||||
default = true
|
default = true
|
||||||
@@ -141,10 +172,30 @@ groupId = "org.kodein.di"
|
|||||||
artifactId = "kodein-di-jvm"
|
artifactId = "kodein-di-jvm"
|
||||||
version = "7.0.0"
|
version = "7.0.0"
|
||||||
category = "injection"
|
category = "injection"
|
||||||
|
repository = "jcenter"
|
||||||
|
|
||||||
[dependencies.Koin]
|
[dependencies.Koin]
|
||||||
groupId = "org.koin"
|
groupId = "org.koin"
|
||||||
artifactId = "koin-core"
|
artifactId = "koin-core"
|
||||||
version = "2.1.6"
|
version = "2.1.6"
|
||||||
category = "injection"
|
category = "injection"
|
||||||
default = true
|
repository = "jcenter"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
[dependencies.Jackson]
|
||||||
|
groupId = "com.fasterxml.jackson.module"
|
||||||
|
artifactId = "jackson-module-kotlin"
|
||||||
|
version = "2.11.2"
|
||||||
|
category = "serialization"
|
||||||
|
|
||||||
|
[dependencies.Kotlinx-serialization]
|
||||||
|
groupId = "org.jetbrains.kotlinx"
|
||||||
|
artifactId = "kotlinx-serialization-runtime"
|
||||||
|
version = "1.0-M1-1.4.0-rc"
|
||||||
|
category = "serialization"
|
||||||
|
|
||||||
|
[dependencies.Arrow-core]
|
||||||
|
groupId = "io.arrow-kt"
|
||||||
|
artifactId = "arrow-core"
|
||||||
|
version = "0.10.5"
|
||||||
|
repository = "arrow"
|
||||||
|
|||||||
@@ -26,11 +26,6 @@
|
|||||||
<artifactId>pebble</artifactId>
|
<artifactId>pebble</artifactId>
|
||||||
<version>3.1.4</version>
|
<version>3.1.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>1.2.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.electronwill.night-config</groupId>
|
<groupId>com.electronwill.night-config</groupId>
|
||||||
<artifactId>toml</artifactId>
|
<artifactId>toml</artifactId>
|
||||||
@@ -42,9 +37,9 @@
|
|||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.javalin</groupId>
|
<groupId>org.http4k</groupId>
|
||||||
<artifactId>javalin</artifactId>
|
<artifactId>http4k-core</artifactId>
|
||||||
<version>3.10.1</version>
|
<version>3.260.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
@@ -74,13 +69,35 @@
|
|||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>true</minimizeJar>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<mainClass>starter.KotlinStarterKt</mainClass>
|
<mainClass>starter.KotlinStarterKt</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>com.electronwill.night-config:*</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/maven/**</exclude>
|
||||||
|
<exclude>META-INF/proguard/**</exclude>
|
||||||
|
<exclude>META-INF/*.kotlin_module</exclude>
|
||||||
|
<exclude>META-INF/DEPENDENCIES*</exclude>
|
||||||
|
<exclude>META-INF/NOTICE*</exclude>
|
||||||
|
<exclude>META-INF/LICENSE*</exclude>
|
||||||
|
<exclude>LICENSE*</exclude>
|
||||||
|
<exclude>META-INF/README*</exclude>
|
||||||
|
<exclude>META-INF/native-image/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -117,4 +134,4 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -3,33 +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),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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"])
|
||||||
|
}
|
||||||
|
|
||||||
|
return StarterConfig(dependencies, inputs, repositories)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ package starter
|
|||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import org.koin.dsl.bind
|
import org.koin.dsl.bind
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import starter.templates.MainTemplate
|
import starter.templates.*
|
||||||
import starter.templates.PomTemplate
|
|
||||||
import starter.templates.Template
|
|
||||||
|
|
||||||
val mainModule = module {
|
val mainModule = module {
|
||||||
single { Config().load() }
|
single { Config().load() }
|
||||||
@@ -18,6 +16,8 @@ val mainModule = module {
|
|||||||
val templateModule = module {
|
val templateModule = module {
|
||||||
single { PomTemplate(get()) } bind Template::class
|
single { PomTemplate(get()) } bind Template::class
|
||||||
single { MainTemplate(get()) } bind Template::class
|
single { MainTemplate(get()) } bind Template::class
|
||||||
|
single { LogbackTemplate(get()) } bind Template::class
|
||||||
|
single { GitignoreTemplate(get()) } bind Template::class
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package starter
|
package starter
|
||||||
|
|
||||||
enum class Category {
|
enum class Category {
|
||||||
Server, Injection, Database, Test, Other
|
Server, Injection, Database, Serialization, Test, Other
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Scope {
|
enum class Scope {
|
||||||
@@ -15,9 +15,13 @@ data class Dependency(
|
|||||||
val version: String,
|
val version: String,
|
||||||
val default: Boolean,
|
val default: Boolean,
|
||||||
val category: Category,
|
val category: Category,
|
||||||
val scope: Scope
|
val scope: Scope,
|
||||||
|
val logger: String?,
|
||||||
|
val repository: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class Repository(val name: String, val url: String)
|
||||||
|
|
||||||
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(
|
||||||
@@ -25,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>,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class PebbleModule {
|
|||||||
loader.suffix = ".twig"
|
loader.suffix = ".twig"
|
||||||
return PebbleEngine.Builder()
|
return PebbleEngine.Builder()
|
||||||
.loader(loader)
|
.loader(loader)
|
||||||
.cacheActive(false)
|
.cacheActive(true)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,21 +3,19 @@ package starter
|
|||||||
import starter.templates.Template
|
import starter.templates.Template
|
||||||
import starter.utils.ZipOutput
|
import starter.utils.ZipOutput
|
||||||
import starter.utils.sanitizeFilename
|
import starter.utils.sanitizeFilename
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
class ProjectZip(private val templates: List<Template>) {
|
class ProjectZip(private val templates: List<Template>) {
|
||||||
|
|
||||||
fun createZip(project: Project): String {
|
fun createZip(project: Project): ByteArrayOutputStream {
|
||||||
val name: String
|
val projectName = sanitizeFilename(project.name)
|
||||||
|
val zipOutput = ZipOutput()
|
||||||
ZipOutput(sanitizeFilename(project.name)).use {
|
zipOutput.use { zip ->
|
||||||
name = it.name
|
templates.filter { it.enabled(project) }.forEach { template ->
|
||||||
|
zip.write(projectName + "/" + template.path(project), template.render(project))
|
||||||
templates.forEach { template ->
|
|
||||||
it.write(template.path(project), template.render(project))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return zipOutput.outputStream
|
||||||
return name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,37 @@
|
|||||||
package starter
|
package starter
|
||||||
|
|
||||||
import io.javalin.Javalin
|
import org.http4k.core.HttpHandler
|
||||||
|
import org.http4k.core.Method
|
||||||
|
import org.http4k.core.Response
|
||||||
|
import org.http4k.core.Status
|
||||||
|
import org.http4k.core.body.form
|
||||||
|
import org.http4k.core.body.formAsMap
|
||||||
|
import org.http4k.routing.ResourceLoader
|
||||||
|
import org.http4k.routing.bind
|
||||||
|
import org.http4k.routing.routes
|
||||||
|
import org.http4k.routing.static
|
||||||
|
import org.http4k.server.SunHttp
|
||||||
|
import org.http4k.server.asServer
|
||||||
import starter.utils.sanitizeFilename
|
import starter.utils.sanitizeFilename
|
||||||
import java.io.File
|
import java.io.ByteArrayInputStream
|
||||||
|
|
||||||
class Server(
|
class Server(
|
||||||
private val views: Views,
|
private val views: Views,
|
||||||
private val conf: StarterConfig,
|
private val conf: StarterConfig,
|
||||||
private val projectZip: ProjectZip,
|
private val projectZip: ProjectZip,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
val app = Javalin.create {
|
val indexHandler: HttpHandler = {
|
||||||
it.addStaticFiles("/assets")
|
Response(Status.OK).body(views.index(conf.dependencies, conf.inputs)).header("Content-Type", "text/html")
|
||||||
}.start(7000)
|
|
||||||
|
|
||||||
app.get("/") { ctx ->
|
|
||||||
ctx.result(views.index(conf.dependencies, conf.inputs))
|
|
||||||
ctx.contentType("text/html")
|
|
||||||
}
|
}
|
||||||
|
val zipHandler: HttpHandler = { req ->
|
||||||
app.post("/") { ctx ->
|
|
||||||
val deps = conf.dependencies.filter {
|
val deps = conf.dependencies.filter {
|
||||||
ctx.formParam(it.name) != null
|
req.form(it.name) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
val inputKeys = conf.inputs.map { it.name }
|
val inputKeys = conf.inputs.map { it.name }
|
||||||
val inputs = ctx.formParamMap()
|
val inputs = req.formAsMap()
|
||||||
.filter { it.key in inputKeys }
|
.filter { it.key in inputKeys }
|
||||||
.map { (name, value) ->
|
.map { (name, value) ->
|
||||||
conf.inputs.find { it.name == name }!!.copy(value = value.first())
|
conf.inputs.find { it.name == name }!!.copy(value = value.first())
|
||||||
@@ -33,12 +39,30 @@ class Server(
|
|||||||
|
|
||||||
val projectName = inputs.find { it.name == "name" }!!.value!!
|
val projectName = inputs.find { it.name == "name" }!!.value!!
|
||||||
val basePackage = inputs.find { it.name == "basePackage" }!!.value!!
|
val basePackage = inputs.find { it.name == "basePackage" }!!.value!!
|
||||||
val project = Project(projectName, basePackage, inputs, deps)
|
|
||||||
|
|
||||||
ctx.contentType("application/zip")
|
if (basePackage.contains("/") || basePackage.contains("..")) {
|
||||||
ctx.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
Response(Status.BAD_REQUEST).body("Invalid Base Package")
|
||||||
val zipFile = projectZip.createZip(project)
|
} else {
|
||||||
ctx.result(File(zipFile).readBytes())
|
val repositories = conf.repositories
|
||||||
|
.filter { repo -> repo.name in deps.mapNotNull { it.repository } }
|
||||||
|
|
||||||
|
val project = Project(projectName, basePackage, inputs, deps, repositories)
|
||||||
|
val outputStream = projectZip.createZip(project)
|
||||||
|
|
||||||
|
Response(Status.OK).header("Content-Type", "application/zip")
|
||||||
|
.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
||||||
|
.body(ByteArrayInputStream(outputStream.toByteArray()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val app = routes(
|
||||||
|
"/" bind Method.GET to indexHandler,
|
||||||
|
"/" bind Method.POST to zipHandler,
|
||||||
|
static(ResourceLoader.Classpath("/assets"))
|
||||||
|
)
|
||||||
|
|
||||||
|
app.asServer(SunHttp(7000)).start()
|
||||||
|
println("Started on http://localhost:7000")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package starter.templates
|
||||||
|
|
||||||
|
import com.mitchellbosecke.pebble.PebbleEngine
|
||||||
|
import starter.Project
|
||||||
|
import starter.utils.render
|
||||||
|
|
||||||
|
class GitignoreTemplate(private val engine: PebbleEngine) : Template {
|
||||||
|
override fun path(project: Project) =
|
||||||
|
".gitignore"
|
||||||
|
|
||||||
|
override fun render(project: Project) =
|
||||||
|
engine.render("starter/gitignore/index")
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package starter.templates
|
||||||
|
|
||||||
|
import com.mitchellbosecke.pebble.PebbleEngine
|
||||||
|
import starter.Project
|
||||||
|
import starter.utils.prettyPrintXml
|
||||||
|
import starter.utils.render
|
||||||
|
|
||||||
|
class LogbackTemplate(private val engine: PebbleEngine) : Template {
|
||||||
|
override fun path(project: Project) = "src/main/resources/logback.xml"
|
||||||
|
|
||||||
|
override fun enabled(project: Project) = project.dependencies.any { it.name == "logback" }
|
||||||
|
|
||||||
|
override fun render(project: Project): String {
|
||||||
|
val args = mapOf(
|
||||||
|
"loggers" to project.dependencies.mapNotNull { it.logger }.toSet()
|
||||||
|
)
|
||||||
|
val rendered = engine.render("starter/logback/index", args)
|
||||||
|
return prettyPrintXml(rendered)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,8 @@ import starter.utils.render
|
|||||||
|
|
||||||
class MainTemplate(private val engine: PebbleEngine) : Template {
|
class MainTemplate(private val engine: PebbleEngine) : Template {
|
||||||
override fun path(project: Project) =
|
override fun path(project: Project) =
|
||||||
project.basePackage.replace('.', '/') + "/" + project.name.toLowerCase().capitalize() + ".kt"
|
"src/main/kotlin/" + project.basePackage.replace('.', '/') + "/" + project.name.toLowerCase().capitalize() + ".kt"
|
||||||
|
|
||||||
override fun render(project: Project) =
|
override fun render(project: Project) =
|
||||||
engine.render("starter/main/main", mapOf("basePackage" to project.basePackage))
|
engine.render("starter/main/index", mapOf("basePackage" to project.basePackage))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,15 @@ 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" },
|
||||||
)
|
)
|
||||||
|
|
||||||
project.inputs.forEach {
|
project.inputs.forEach {
|
||||||
args[it.name] = it.value
|
args[it.name] = it.value
|
||||||
}
|
}
|
||||||
|
|
||||||
val rendered = engine.render("starter/pom/pom", args)
|
val rendered = engine.render("starter/pom/index", args)
|
||||||
return prettyPrintXml(rendered)
|
return prettyPrintXml(rendered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ import starter.Project
|
|||||||
|
|
||||||
interface Template {
|
interface Template {
|
||||||
fun path(project: Project): String
|
fun path(project: Project): String
|
||||||
|
fun enabled(project: Project): Boolean = true
|
||||||
fun render(project: Project): String
|
fun render(project: Project): String
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,21 @@ package starter.utils
|
|||||||
|
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||||
import java.io.File
|
import java.io.ByteArrayOutputStream
|
||||||
import java.nio.file.Paths
|
|
||||||
|
|
||||||
class ZipOutput(name: String) : AutoCloseable {
|
class ZipOutput : AutoCloseable {
|
||||||
private val baseDir = File(".").canonicalFile
|
val outputStream = ByteArrayOutputStream()
|
||||||
private val zipPath = Paths.get(baseDir.path, "$name.zip")
|
private val zipOutputStream = ZipArchiveOutputStream(outputStream)
|
||||||
private val zipFile = zipPath.toAbsolutePath().normalize().toFile().apply {
|
|
||||||
createNewFile()
|
|
||||||
}
|
|
||||||
private val outputStream = ZipArchiveOutputStream(zipFile.outputStream())
|
|
||||||
val name: String
|
|
||||||
get() = zipFile.name
|
|
||||||
|
|
||||||
fun write(path: String, content: String) {
|
fun write(path: String, content: String) {
|
||||||
val entry = ZipArchiveEntry(path)
|
val entry = ZipArchiveEntry(path)
|
||||||
outputStream.putArchiveEntry(entry)
|
zipOutputStream.putArchiveEntry(entry)
|
||||||
outputStream.write(content.toByteArray())
|
zipOutputStream.write(content.toByteArray())
|
||||||
outputStream.closeArchiveEntry()
|
zipOutputStream.closeArchiveEntry()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
outputStream.finish()
|
zipOutputStream.finish()
|
||||||
outputStream.close()
|
zipOutputStream.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
target/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
<root level="DEBUG">
|
<root level="DEBUG">
|
||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="com.mitchellbosecke.pebble" level="INFO"/>
|
{% for logger in loggers %}
|
||||||
<logger name="org.eclipse.jetty" level="INFO"/>
|
<logger name="{{ logger }}" level="INFO"/>
|
||||||
|
{% endfor %}
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
{% for dep in dependencies %}
|
{% for dep in dependencies %}
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>{{ dep.groupId }}</groupId>
|
<groupId>{{ dep.groupId }}</groupId>
|
||||||
@@ -9,4 +14,4 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</dependency>
|
</dependency>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
{% if repositories is not empty %}
|
||||||
<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>
|
||||||
|
{% endif %}
|
||||||
|
|||||||
@@ -20,5 +20,19 @@
|
|||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<jvmTarget>${java.version}</jvmTarget>
|
<jvmTarget>${java.version}</jvmTarget>
|
||||||
|
{% if kotlinxSerialization %}
|
||||||
|
<compilerPlugins>
|
||||||
|
<plugin>kotlinx-serialization</plugin>
|
||||||
|
</compilerPlugins>
|
||||||
|
{% endif %}
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
{% if kotlinxSerialization %}
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-serialization</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
{% endif %}
|
||||||
|
</plugin>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<minimizeJar>true</minimizeJar>
|
<minimizeJar>true</minimizeJar>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer
|
||||||
@@ -19,4 +20,4 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
Reference in New Issue
Block a user