Skip to content

Commit

Permalink
Merge pull request #7 from rjaros/main
Browse files Browse the repository at this point in the history
Upgrade to KVision 3.17.2
  • Loading branch information
JakubNeukirch authored Dec 7, 2020
2 parents aa89ef8 + dc8e693 commit 3dc89fa
Show file tree
Hide file tree
Showing 64 changed files with 1,634 additions and 476 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# kvision-project-wizard
KVision plugin for project creation.
# KVision Project Wizard
KVision IntellJ IDEA plugin for new project creation.
Supported project types:
* Fullstack KTOR
* Fullstack Spring-Boot
* Frontend-only
* Frontend project
* Ktor fullstack project
* Spring Boot fullstack project
* Javalin fullstack project
* Jooby fullstack project
* Micronaut fullstack project
* Vert.x fullstack project

## Contribution
If you want to contribute, You can add support for other backend frameworks like javalin, jooby, vertx and others. To do so You must:
* inherit by `TreeGenerator`
* add case to KVisionModuleBuilder.createGenerator()
* add enum to KVisionModuleBuilder.supportedBackendLibraries
You can contribute new project types:
* create new `TreeGenerator` subclass
* add new case to `KVisionModuleBuilder.createGenerator()`
* add new value to `KVisionModuleBuilder.supportedProjectTypes`
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.jetbrains.intellij' version '0.5.0'
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
id 'org.jetbrains.intellij' version '0.6.5'
id 'org.jetbrains.kotlin.jvm' version '1.4.20'
id 'idea'
}

Expand All @@ -23,7 +23,7 @@ dependencies {

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.1'
version '2020.3'
plugins = ['gradle', 'java', 'org.jetbrains.kotlin']
}
patchPluginXml {
Expand Down
65 changes: 41 additions & 24 deletions src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.stonks.kvizard

import com.intellij.ide.fileTemplates.FileTemplateManager
import com.intellij.ide.util.projectWizard.ModuleBuilder
import com.intellij.ide.util.projectWizard.ModuleWizardStep
import com.intellij.ide.util.projectWizard.WizardContext
Expand All @@ -15,29 +14,38 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.file.PsiDirectoryFactory
import tech.stonks.kvizard.generator.FrontendTreeGenerator
import tech.stonks.kvizard.generator.JavalinTreeGenerator
import tech.stonks.kvizard.generator.JoobyTreeGenerator
import tech.stonks.kvizard.generator.KtorTreeGenerator
import tech.stonks.kvizard.generator.MicronautTreeGenerator
import tech.stonks.kvizard.generator.SpringTreeGenerator
import tech.stonks.kvizard.generator.TreeGenerator
import tech.stonks.kvizard.generator.VertxTreeGenerator
import tech.stonks.kvizard.step.library_choice.LibraryChoiceStep
import tech.stonks.kvizard.utils.*
import tech.stonks.kvizard.utils.KVisionDialogUtil
import tech.stonks.kvizard.utils.RunConfigurationUtil
import tech.stonks.kvizard.utils.backgroundTask
import tech.stonks.kvizard.utils.runGradle
import java.io.File

class KVisionModuleBuilder : ModuleBuilder() {

companion object {
/**
* Here add libraries that were newly supported
*/
val supportedBackendLibraries = arrayOf(
KVisionBackendLibrary.KTOR,
KVisionBackendLibrary.SPRING_BOOT,
KVisionBackendLibrary.FRONTEND_ONLY
val supportedProjectTypes = arrayOf(
KVisionProjectType.FRONTEND_ONLY,
KVisionProjectType.KTOR,
KVisionProjectType.SPRING_BOOT,
KVisionProjectType.JAVALIN,
KVisionProjectType.JOOBY,
KVisionProjectType.MICRONAUT,
KVisionProjectType.VERTX
)
}

var backendLibrary: KVisionBackendLibrary = KVisionBackendLibrary.KTOR
var projectType: KVisionProjectType = KVisionProjectType.FRONTEND_ONLY
var groupId: String = "com.example"
var artifactId: String = "project"
var compilerBackend: CompilerBackend = CompilerBackend.LEGACY

override fun setupRootModel(modifiableRootModel: ModifiableRootModel) {
val root = createAndGetRoot() ?: return
Expand All @@ -56,26 +64,37 @@ class KVisionModuleBuilder : ModuleBuilder() {
val generator: TreeGenerator = createGenerator()
modifiableRootModel.project.backgroundTask("Setting up project") {
try {
generator.generate(root, artifactId, groupId)
generator.generate(root, artifactId, groupId, compilerBackend)
} catch (ex: Exception) {

}
runGradleTasks(modifiableRootModel.project)
RunConfigurationUtil.createConfiguration(modifiableRootModel.project)
installGradleWrapper(modifiableRootModel.project)
if (projectType == KVisionProjectType.FRONTEND_ONLY) {
RunConfigurationUtil.createFrontendConfiguration(modifiableRootModel.project)
} else {
runCompileMetadata(modifiableRootModel.project)
RunConfigurationUtil.createFullstackConfiguration(modifiableRootModel.project)
}
KVisionDialogUtil.showNewsDialog()
}
}

private fun runGradleTasks(project: Project) {
private fun runCompileMetadata(project: Project) {
project.runGradle("compileKotlinMetadata")
}

private fun installGradleWrapper(project: Project) {
project.runGradle("wrapper --gradle-version 6.7.1 --distribution-type all")
}

private fun createGenerator(): TreeGenerator {
return when (backendLibrary) {
KVisionBackendLibrary.KTOR -> KtorTreeGenerator()
KVisionBackendLibrary.FRONTEND_ONLY -> FrontendTreeGenerator()
KVisionBackendLibrary.SPRING_BOOT -> SpringTreeGenerator()
else -> throw IllegalStateException("${backendLibrary.name} is not supported yet.")
return when (projectType) {
KVisionProjectType.FRONTEND_ONLY -> FrontendTreeGenerator()
KVisionProjectType.KTOR -> KtorTreeGenerator()
KVisionProjectType.SPRING_BOOT -> SpringTreeGenerator()
KVisionProjectType.JAVALIN -> JavalinTreeGenerator()
KVisionProjectType.JOOBY -> JoobyTreeGenerator()
KVisionProjectType.MICRONAUT -> MicronautTreeGenerator()
KVisionProjectType.VERTX -> VertxTreeGenerator()
}
}

Expand All @@ -88,9 +107,7 @@ class KVisionModuleBuilder : ModuleBuilder() {
return KVisionModuleType()
}

override fun getCustomOptionsStep(context: WizardContext?, parentDisposable: Disposable?): ModuleWizardStep? {
override fun getCustomOptionsStep(context: WizardContext?, parentDisposable: Disposable?): ModuleWizardStep {
return LibraryChoiceStep(this)
}


}
}
23 changes: 17 additions & 6 deletions src/main/kotlin/tech/stonks/kvizard/KVisionModuleType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import javax.swing.Icon

class KVisionModuleType : ModuleType<KVisionModuleBuilder>("KVISION_WIZARD") {

private val _icon: Icon by lazy { IconLoader.getIcon("/images/logo16.png") }
private val _icon: Icon by lazy { IconLoader.getIcon("/images/logo16.png", KVisionModuleType::class.java) }

override fun createModuleBuilder(): KVisionModuleBuilder {
return KVisionModuleBuilder()
}

override fun getName(): String {
return "KVision Project"
return "KVision"
}

override fun getDescription(): String {
return "KVision Project wizard. It is a fullstack kotlin framework"
return "A new project with KVision - an object oriented web framework for Kotlin/JS"
}

override fun getNodeIcon(isOpened: Boolean): Icon {
Expand All @@ -29,6 +29,17 @@ class KVisionModuleType : ModuleType<KVisionModuleBuilder>("KVISION_WIZARD") {
}
}

enum class KVisionBackendLibrary {
KTOR, FRONTEND_ONLY, JAVALIN, JOOBY, MICRONAUT, SPRING_BOOT, VERTX;
}
enum class KVisionProjectType(val displayName: String) {
FRONTEND_ONLY("Frontend project"),
KTOR("Ktor fullstack project"),
SPRING_BOOT("Spring Boot fullstack project"),
JAVALIN("Javalin fullstack project"),
JOOBY("Jooby fullstack project"),
MICRONAUT("Micronaut fullstack project"),
VERTX("Vert.x fullstack project");
}

enum class CompilerBackend(val displayName: String) {
LEGACY("Legacy"),
IR("IR (experimental)")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tech.stonks.kvizard.generator

class JavalinTreeGenerator : TreeGenerator(
"javalin",
false,
backendFiles = arrayOf("Main.kt", "Service.kt"),
backendResourcesFiles = arrayOf("application.conf", "logback.xml"),
backendResourcesAssetsFiles = arrayOf(".placeholder")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.stonks.kvizard.generator

class JoobyTreeGenerator : TreeGenerator(
"jooby",
false,
backendFiles = arrayOf("Main.kt", "Service.kt"),
backendResourcesFiles = arrayOf("application.conf", "logback.xml")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.stonks.kvizard.generator

class MicronautTreeGenerator : TreeGenerator(
"micronaut",
false,
backendFiles = arrayOf("Main.kt", "Service.kt"),
backendResourcesFiles = arrayOf("application.yml", "logback.xml")
)
Loading

0 comments on commit 3dc89fa

Please sign in to comment.