diff --git a/build.gradle b/build.gradle index 65c348a..cd73bde 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { version '2020.2.1' + plugins = ['gradle'] } patchPluginXml { changeNotes """ diff --git a/src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt b/src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt index 53781c1..9d5f718 100644 --- a/src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt +++ b/src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt @@ -1,24 +1,26 @@ package tech.stonks.kvizard +import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.ide.util.projectWizard.ModuleBuilder import com.intellij.ide.util.projectWizard.ModuleWizardStep import com.intellij.ide.util.projectWizard.WizardContext import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.module.ModuleType +import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiManager import com.intellij.psi.impl.file.PsiDirectoryFactory -import tech.stonks.kvizard.data.VersionApi -import tech.stonks.kvizard.data.model.* +import org.jetbrains.plugins.gradle.action.GradleExecuteTaskAction import tech.stonks.kvizard.generator.FrontendTreeGenerator import tech.stonks.kvizard.generator.KtorTreeGenerator import tech.stonks.kvizard.generator.TreeGenerator import tech.stonks.kvizard.step.library_choice.LibraryChoiceStep -import tech.stonks.kvizard.utils.* +import tech.stonks.kvizard.utils.backgroundTask +import tech.stonks.kvizard.utils.runGradle import java.io.File class KVisionModuleBuilder : ModuleBuilder() { @@ -28,8 +30,8 @@ class KVisionModuleBuilder : ModuleBuilder() { * Here add libraries that were newly supported */ val supportedBackendLibraries = arrayOf( - KVisionBackendLibrary.KTOR, - KVisionBackendLibrary.FRONTEND_ONLY + KVisionBackendLibrary.KTOR, + KVisionBackendLibrary.FRONTEND_ONLY ) } @@ -44,8 +46,8 @@ class KVisionModuleBuilder : ModuleBuilder() { ApplicationManager.getApplication().runWriteAction { val manager = PsiManager.getInstance(modifiableRootModel.project) manager.findFile(root)?.add( - PsiDirectoryFactory.getInstance(manager.project) - .createDirectory(root.createChildDirectory(null, "webpack")) + PsiDirectoryFactory.getInstance(manager.project) + .createDirectory(root.createChildDirectory(null, "webpack")) ) } } catch (ex: java.lang.Exception) { @@ -53,12 +55,21 @@ class KVisionModuleBuilder : ModuleBuilder() { } val generator: TreeGenerator = createGenerator() modifiableRootModel.project.backgroundTask("Setting up project") { - generator.generate(root, artifactId, groupId) + try { + generator.generate(root, artifactId, groupId) + } catch (ex: Exception) { + + } + runGradleTasks(modifiableRootModel.project) } } + private fun runGradleTasks(project: Project) { + project.runGradle("compileKotlinMetadata") + } + private fun createGenerator(): TreeGenerator { - return when(backendLibrary) { + return when (backendLibrary) { KVisionBackendLibrary.KTOR -> KtorTreeGenerator() KVisionBackendLibrary.FRONTEND_ONLY -> FrontendTreeGenerator() else -> throw IllegalStateException("${backendLibrary.name} is not supported yet.") diff --git a/src/main/kotlin/tech/stonks/kvizard/utils/file.kt b/src/main/kotlin/tech/stonks/kvizard/utils/file.kt index 2131a3d..ae2bddb 100644 --- a/src/main/kotlin/tech/stonks/kvizard/utils/file.kt +++ b/src/main/kotlin/tech/stonks/kvizard/utils/file.kt @@ -1,8 +1,10 @@ package tech.stonks.kvizard.utils +import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.ide.fileTemplates.FileTemplateManager import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile +import org.jetbrains.plugins.gradle.action.GradleExecuteTaskAction import java.io.File fun File.dir(name: String, body: File.() -> Unit = {}) { @@ -45,6 +47,10 @@ private fun getTemplateData(templateName: String, attributes: Map com.intellij.modules.platform + com.intellij.gradle