From b4a76c05d61c109608f606c2085c47628e3ae735 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 21 Sep 2021 17:01:32 +0200 Subject: [PATCH] feat: Improve file template handling, add Changelog action --- build.gradle.kts | 9 ++ gradle.properties | 2 +- .../shopware6/ui/NewChangelogDialog.form | 66 ++++++++++++++ .../shopware6/ui/NewChangelogDialog.java | 10 +++ .../shopware6/ui/NewComponentDialog.form | 53 ++++++++++++ .../shopware6/ui/NewComponentDialog.java | 10 +++ .../shopware6/action/generator/ActionUtil.kt | 20 ++--- .../action/generator/NewChangelogAction.kt | 49 +++++++++++ .../action/generator/NewComponentAction.kt | 81 ++++++++++------- .../action/generator/NewConfigXmlAction.kt | 11 +-- .../action/generator/ui/NewChangelogConfig.kt | 3 + .../generator/ui/NewChangelogDialogWrapper.kt | 42 +++++++++ .../action/generator/ui/NewComponentConfig.kt | 5 ++ .../generator/ui/NewComponentDialogWrapper.kt | 30 +++---- .../shopware6/templates/ShopwareTemplates.kt | 86 +++++++++++++++++++ src/main/resources/META-INF/plugin.xml | 10 ++- .../contribution/Shopware CHANGELOG.md.ft | 22 +++++ .../plugin/Shopware Plugin config.xml.ft} | 0 .../vue/Shopware Vue Component SCSS.scss.ft | 0 .../Shopware Vue Component Twig.html.twig.ft | 0 .../j2ee/vue/Shopware Vue Component.js.ft | 14 +++ .../fileTemplates/vue/component/index.js | 8 -- 22 files changed, 457 insertions(+), 74 deletions(-) create mode 100644 src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.form create mode 100644 src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.java create mode 100644 src/main/java/de/shyim/shopware6/ui/NewComponentDialog.form create mode 100644 src/main/java/de/shyim/shopware6/ui/NewComponentDialog.java create mode 100644 src/main/kotlin/de/shyim/shopware6/action/generator/NewChangelogAction.kt create mode 100644 src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogConfig.kt create mode 100644 src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogDialogWrapper.kt create mode 100644 src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentConfig.kt create mode 100644 src/main/kotlin/de/shyim/shopware6/templates/ShopwareTemplates.kt create mode 100644 src/main/resources/fileTemplates/j2ee/contribution/Shopware CHANGELOG.md.ft rename src/main/resources/fileTemplates/{config.xml => j2ee/plugin/Shopware Plugin config.xml.ft} (100%) create mode 100644 src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component SCSS.scss.ft create mode 100644 src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component Twig.html.twig.ft create mode 100644 src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component.js.ft delete mode 100644 src/main/resources/fileTemplates/vue/component/index.js diff --git a/build.gradle.kts b/build.gradle.kts index f93f337..ef5e823 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -119,4 +119,13 @@ tasks { // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) } + + processResources { + exclude("fileTemplates/j2ee/**") + from(fileTree("src/main/resources/fileTemplates/j2ee").files) { + eachFile { + relativePath = RelativePath(true, "fileTemplates", "j2ee", this.name) + } + } + } } diff --git a/gradle.properties b/gradle.properties index 09e0db6..5bdb351 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ platformDownloadSources = true # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 -platformPlugins = com.jetbrains.php:212.4746.100,JavaScriptLanguage +platformPlugins=com.jetbrains.php:212.4746.100,JavaScriptLanguage,Git4Idea # Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3 javaVersion = 11 diff --git a/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.form b/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.form new file mode 100644 index 0000000..befa88b --- /dev/null +++ b/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.form @@ -0,0 +1,66 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.java b/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.java new file mode 100644 index 0000000..1a6aaa9 --- /dev/null +++ b/src/main/java/de/shyim/shopware6/ui/NewChangelogDialog.java @@ -0,0 +1,10 @@ +package de.shyim.shopware6.ui; + +import javax.swing.*; + +public class NewChangelogDialog { + public JTextField titleField; + public JTextField ticketField; + public JTextField flagField; + public JPanel panel; +} diff --git a/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.form b/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.form new file mode 100644 index 0000000..931f81c --- /dev/null +++ b/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.form @@ -0,0 +1,53 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.java b/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.java new file mode 100644 index 0000000..b902dc3 --- /dev/null +++ b/src/main/java/de/shyim/shopware6/ui/NewComponentDialog.java @@ -0,0 +1,10 @@ +package de.shyim.shopware6.ui; + +import javax.swing.*; + +public class NewComponentDialog { + public JTextField componentName; + public JCheckBox createSCSSFile; + public JCheckBox createTwigFileCheckBox; + public JPanel panel; +} diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/ActionUtil.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/ActionUtil.kt index 99f5772..3bf0c52 100644 --- a/src/main/kotlin/de/shyim/shopware6/action/generator/ActionUtil.kt +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/ActionUtil.kt @@ -6,12 +6,10 @@ import com.intellij.openapi.actionSystem.LangDataKeys import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.fileTypes.LanguageFileType import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.io.StreamUtil; +import com.intellij.openapi.ui.Messages import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiFileFactory import com.intellij.psi.codeStyle.CodeStyleManager -import java.io.IOException class ActionUtil { @@ -25,7 +23,13 @@ class ActionUtil { return directories[0] ?: return null } - fun buildFile(event: AnActionEvent, project: Project, templatePath: String, fileName: String?, fileType: LanguageFileType) { + fun buildFile( + event: AnActionEvent, + project: Project, + content: String, + fileName: String?, + fileType: LanguageFileType + ) { val dataContext = event.dataContext val view = LangDataKeys.IDE_VIEW.getData(dataContext) ?: return val initialBaseDir = this.getViewDirectory(dataContext) ?: return @@ -34,13 +38,7 @@ class ActionUtil { Messages.showInfoMessage("File exists", "Error") return } - val content: String - content = try { - StreamUtil.readText(ActionUtil::class.java.getResourceAsStream(templatePath), "UTF-8") - } catch (e: IOException) { - e.printStackTrace() - return - } + val factory = PsiFileFactory.getInstance(project) val file = factory.createFileFromText(fileName, fileType, content) ApplicationManager.getApplication().runWriteAction { diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/NewChangelogAction.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/NewChangelogAction.kt new file mode 100644 index 0000000..4994a66 --- /dev/null +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/NewChangelogAction.kt @@ -0,0 +1,49 @@ +package de.shyim.shopware6.action.generator + +import com.intellij.icons.AllIcons +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.fileTypes.PlainTextFileType +import com.intellij.openapi.project.DumbAwareAction +import de.shyim.shopware6.action.generator.ui.NewChangelogDialogWrapper +import de.shyim.shopware6.templates.ShopwareTemplates +import git4idea.branch.GitBranchUtil +import org.apache.commons.lang.StringUtils +import java.text.SimpleDateFormat +import java.util.* + +class NewChangelogAction: DumbAwareAction("Create a Changelog", "Create a new Changelog file", AllIcons.FileTypes.Text) { + override fun actionPerformed(e: AnActionEvent) { + if (e.project == null) { + return + } + + val currentBranch = GitBranchUtil.getCurrentRepository(e.project!!)?.currentBranch + var defaultTitle = "" + var defaultTicket = "" + + if (currentBranch != null && currentBranch.name.startsWith("next-")) { + val branchParts = currentBranch.name.split("/") + + if (branchParts.count() == 2) { + defaultTicket = branchParts[0].uppercase() + defaultTitle = StringUtils.capitalize(branchParts[1]) + } + } + + val dialog = NewChangelogDialogWrapper(defaultTitle, defaultTicket) + val dialogResult = dialog.showAndGetConfig() ?: return + + val date = Date() + val modifiedDate: String = SimpleDateFormat("yyyy-MM-dd").format(date) + + val fileName = modifiedDate + "-" + dialogResult.title.lowercase() + ".md" + + ActionUtil.buildFile( + e, + e.project!!, + ShopwareTemplates.applyChangelogTemplate(e.project!!, dialogResult), + fileName, + PlainTextFileType.INSTANCE + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/NewComponentAction.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/NewComponentAction.kt index 19b8766..eff42f7 100644 --- a/src/main/kotlin/de/shyim/shopware6/action/generator/NewComponentAction.kt +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/NewComponentAction.kt @@ -2,18 +2,17 @@ package de.shyim.shopware6.action.generator import com.intellij.icons.AllIcons import com.intellij.ide.highlighter.HtmlFileType -import com.intellij.ide.util.DirectoryChooser -import com.intellij.lang.javascript.JavaScriptFileType; +import com.intellij.lang.javascript.JavaScriptFileType import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.LangDataKeys import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.ui.Messages -import com.intellij.openapi.util.io.StreamUtil import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiFileFactory import com.intellij.psi.codeStyle.CodeStyleManager import de.shyim.shopware6.action.generator.ui.NewComponentDialogWrapper -import java.io.IOException +import de.shyim.shopware6.templates.ShopwareTemplates class NewComponentAction: DumbAwareAction("Create a component", "Create a new Vue component", AllIcons.FileTypes.JavaScript) { override fun actionPerformed(e: AnActionEvent) { @@ -22,24 +21,20 @@ class NewComponentAction: DumbAwareAction("Create a component", "Create a new Vu } val dialog = NewComponentDialogWrapper() - val componentName = dialog.showAndGetName() - - if (componentName == "") { - return - } + val config = dialog.showAndGetName() ?: return // Create folder val folder = ActionUtil.getViewDirectory(e.dataContext) ?: return - if (folder.findSubdirectory(componentName) != null) { + if (folder.findSubdirectory(config.name) != null) { Messages.showInfoMessage("Component already exists", "Error") return } var componentFolder: PsiDirectory? = null ApplicationManager.getApplication().runWriteAction { - componentFolder = folder.createSubdirectory(componentName) + componentFolder = folder.createSubdirectory(config.name) } if (componentFolder == null) { @@ -47,16 +42,11 @@ class NewComponentAction: DumbAwareAction("Create a component", "Create a new Vu } // Create index.js - - var content: String - content = try { - StreamUtil.readText(ActionUtil::class.java.getResourceAsStream("/fileTemplates/vue/component/index.js"), "UTF-8") - } catch (e: IOException) { - e.printStackTrace() - return - } - - content = content.replace("#COMPONENT-NAME#", componentName) + val content = ShopwareTemplates.applyShopwareAdminVueComponent( + e.project!!, + ShopwareTemplates.SHOPWARE_ADMIN_VUE_COMPONENT, + config + ) val factory = PsiFileFactory.getInstance(e.project) val file = factory.createFileFromText("index.js", JavaScriptFileType.INSTANCE, content) @@ -66,22 +56,49 @@ class NewComponentAction: DumbAwareAction("Create a component", "Create a new Vu componentFolder!!.add(file) } - // Create html file + if (config.generateTwig) { + // Create html file + + val htmlFile = factory.createFileFromText( + "${config.name}.html.twig", + HtmlFileType.INSTANCE, + ShopwareTemplates.applyShopwareAdminVueComponent( + e.project!!, + ShopwareTemplates.SHOPWARE_ADMIN_VUE_COMPONENT_TWIG, + config + ) + ) + + ApplicationManager.getApplication().runWriteAction { + CodeStyleManager.getInstance(e.project!!).reformat(htmlFile) + componentFolder!!.add(htmlFile) + } + } - val htmlFile = factory.createFileFromText("$componentName.html.twig", HtmlFileType.INSTANCE, "") - ApplicationManager.getApplication().runWriteAction { - CodeStyleManager.getInstance(e.project!!).reformat(htmlFile) - componentFolder!!.add(htmlFile) - } + if (config.generateCss) { + // Create css file - // Create css file + val cssFile = factory.createFileFromText( + "${config.name}.scss", + HtmlFileType.INSTANCE, + ShopwareTemplates.applyShopwareAdminVueComponent( + e.project!!, + ShopwareTemplates.SHOPWARE_ADMIN_VUE_COMPONENT_SCSS, + config + ) + ) - val cssFile = factory.createFileFromText("$componentName.scss", HtmlFileType.INSTANCE, "") + ApplicationManager.getApplication().runWriteAction { + CodeStyleManager.getInstance(e.project!!).reformat(cssFile) + componentFolder!!.add(cssFile) + } + } - ApplicationManager.getApplication().runWriteAction { - CodeStyleManager.getInstance(e.project!!).reformat(cssFile) - componentFolder!!.add(cssFile) + val view = LangDataKeys.IDE_VIEW.getData(e.dataContext) ?: return + val psiFile = componentFolder!!.findFile("index.js") + if (psiFile != null) { + view.selectElement(psiFile) } } } \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/NewConfigXmlAction.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/NewConfigXmlAction.kt index 4ac4168..c812e79 100644 --- a/src/main/kotlin/de/shyim/shopware6/action/generator/NewConfigXmlAction.kt +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/NewConfigXmlAction.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project +import de.shyim.shopware6.templates.ShopwareTemplates class NewConfigXmlAction() : DumbAwareAction("Create a config.xml", "Create a new config.xml", AllIcons.FileTypes.Xml) { @@ -17,11 +18,11 @@ class NewConfigXmlAction() : DumbAwareAction("Create a config.xml", "Create a ne } ActionUtil.buildFile( - e, - project, - "/fileTemplates/config.xml", - "config.xml", - XmlFileType.INSTANCE + e, + project, + ShopwareTemplates.applyShopwarePluginConfig(project), + "config.xml", + XmlFileType.INSTANCE ); } diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogConfig.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogConfig.kt new file mode 100644 index 0000000..e0380f5 --- /dev/null +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogConfig.kt @@ -0,0 +1,3 @@ +package de.shyim.shopware6.action.generator.ui + +class NewChangelogConfig(var title: String, var ticket: String, var flag: String) \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogDialogWrapper.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogDialogWrapper.kt new file mode 100644 index 0000000..52ea489 --- /dev/null +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewChangelogDialogWrapper.kt @@ -0,0 +1,42 @@ +package de.shyim.shopware6.action.generator.ui + +import com.intellij.openapi.ui.DialogWrapper +import de.shyim.shopware6.ui.NewChangelogDialog +import javax.swing.JComponent + +class NewChangelogDialogWrapper(defaultTitle: String, defaultTicket: String) : DialogWrapper(true) { + private var dialog: NewChangelogDialog + + init { + this.dialog = NewChangelogDialog() + this.dialog.ticketField.text = defaultTicket + this.dialog.titleField.text = defaultTitle + } + + override fun createCenterPanel(): JComponent { + return dialog.panel + } + + override fun getPreferredFocusedComponent(): JComponent? { + return dialog.titleField + } + + init { + title = "Create a new Changelog" + init() + } + + fun showAndGetConfig(): NewChangelogConfig? { + showAndGet() + + if (!isOK) { + return null + } + + return NewChangelogConfig( + this.dialog.titleField.getText(), + this.dialog.ticketField.getText(), + this.dialog.flagField.getText() + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentConfig.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentConfig.kt new file mode 100644 index 0000000..1c211a5 --- /dev/null +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentConfig.kt @@ -0,0 +1,5 @@ +package de.shyim.shopware6.action.generator.ui + +class NewComponentConfig(var name: String, var generateCss: Boolean, public var generateTwig: Boolean) { + +} \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentDialogWrapper.kt b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentDialogWrapper.kt index 836149c..5c485ed 100644 --- a/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentDialogWrapper.kt +++ b/src/main/kotlin/de/shyim/shopware6/action/generator/ui/NewComponentDialogWrapper.kt @@ -1,30 +1,23 @@ package de.shyim.shopware6.action.generator.ui import com.intellij.openapi.ui.DialogWrapper -import java.awt.BorderLayout -import java.awt.event.WindowAdapter -import java.awt.event.WindowEvent +import de.shyim.shopware6.ui.NewComponentDialog import javax.swing.JComponent -import javax.swing.JPanel -import javax.swing.JTextField class NewComponentDialogWrapper : DialogWrapper(true) { - private var textField: JTextField + private var dialog: NewComponentDialog init { - textField = JTextField() + this.dialog = NewComponentDialog() } override fun createCenterPanel(): JComponent { - val dialogPanel = JPanel(BorderLayout()) - dialogPanel.add(textField, BorderLayout.CENTER) - - return dialogPanel + return dialog.panel } override fun getPreferredFocusedComponent(): JComponent? { - return textField + return dialog.componentName } init { @@ -32,10 +25,17 @@ class NewComponentDialogWrapper : DialogWrapper(true) { init() } - fun showAndGetName(): String - { + fun showAndGetName(): NewComponentConfig? { show(); - return textField.getText() + if (!isOK) { + return null + } + + return NewComponentConfig( + dialog.componentName.getText(), + dialog.createSCSSFile.isSelected(), + dialog.createTwigFileCheckBox.isSelected + ) } } \ No newline at end of file diff --git a/src/main/kotlin/de/shyim/shopware6/templates/ShopwareTemplates.kt b/src/main/kotlin/de/shyim/shopware6/templates/ShopwareTemplates.kt new file mode 100644 index 0000000..cb1e358 --- /dev/null +++ b/src/main/kotlin/de/shyim/shopware6/templates/ShopwareTemplates.kt @@ -0,0 +1,86 @@ +package de.shyim.shopware6.templates + +import com.intellij.ide.fileTemplates.FileTemplateDescriptor +import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor +import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptorFactory +import com.intellij.ide.fileTemplates.FileTemplateManager +import com.intellij.openapi.project.Project +import de.shyim.shopware6.action.generator.ui.NewChangelogConfig +import de.shyim.shopware6.action.generator.ui.NewComponentConfig +import icons.ShopwareToolBoxIcons + +class ShopwareTemplates: FileTemplateGroupDescriptorFactory { + override fun getFileTemplatesDescriptor(): FileTemplateGroupDescriptor { + val group = FileTemplateGroupDescriptor("Shopware", ShopwareToolBoxIcons.SHOPWARE) + + FileTemplateGroupDescriptor("Contribution", ShopwareToolBoxIcons.SHOPWARE).let { pluginGroup -> + group.addTemplate(pluginGroup) + pluginGroup.addTemplate(FileTemplateDescriptor(SHOPWARE_CONTRIBUTION_CHANGELOG_TEMPLATE)) + } + + FileTemplateGroupDescriptor("Administration", ShopwareToolBoxIcons.SHOPWARE).let { pluginGroup -> + group.addTemplate(pluginGroup) + pluginGroup.addTemplate(FileTemplateDescriptor(SHOPWARE_ADMIN_VUE_COMPONENT)) + pluginGroup.addTemplate(FileTemplateDescriptor(SHOPWARE_ADMIN_VUE_COMPONENT_SCSS)) + pluginGroup.addTemplate(FileTemplateDescriptor(SHOPWARE_ADMIN_VUE_COMPONENT_TWIG)) + } + + FileTemplateGroupDescriptor("Plugin", ShopwareToolBoxIcons.SHOPWARE).let { pluginGroup -> + group.addTemplate(pluginGroup) + pluginGroup.addTemplate(FileTemplateDescriptor(SHOPWARE_PLUGIN_CONFIG_TEMPLATE)) + } + + return group + } + + companion object { + const val SHOPWARE_ADMIN_VUE_COMPONENT = "Shopware Vue Component.js" + const val SHOPWARE_ADMIN_VUE_COMPONENT_SCSS = "Shopware Vue Component SCSS.scss" + const val SHOPWARE_ADMIN_VUE_COMPONENT_TWIG = "Shopware Vue Component Twig.html.twig" + const val SHOPWARE_CONTRIBUTION_CHANGELOG_TEMPLATE = "Shopware CHANGELOG.md" + const val SHOPWARE_PLUGIN_CONFIG_TEMPLATE = "Shopware Plugin config.xml" + + protected fun Project.applyTemplate( + templateName: String, + properties: Map? = null + ): String { + val manager = FileTemplateManager.getInstance(this) + val template = manager.getJ2eeTemplate(templateName) + + val allProperties = manager.defaultProperties + properties?.let { prop -> allProperties.putAll(prop) } + + return template.getText(allProperties) + } + + fun applyChangelogTemplate(project: Project, config: NewChangelogConfig): String { + val props = mapOf( + "TITLE" to config.title, + "TICKET" to config.ticket, + "FLAG" to config.flag, + ) + + return project.applyTemplate(SHOPWARE_CONTRIBUTION_CHANGELOG_TEMPLATE, props) + } + + fun applyShopwareAdminVueComponent(project: Project, name: String, config: NewComponentConfig): String { + val props = mapOf( + "NAME" to config.name, + "GENERATE_SCSS" to config.generateCss.toString(), + "GENERATE_TWIG" to config.generateTwig.toString(), + ) + + return project.applyTemplate(name, props) + } + + fun applyShopwarePluginConfig(project: Project): String { + return project.applyTemplate(SHOPWARE_PLUGIN_CONFIG_TEMPLATE) + } + } + + private fun template(fileName: String, displayName: String? = null) = CustomDescriptor(fileName, displayName) + + private class CustomDescriptor(fileName: String, val visibleName: String?) : FileTemplateDescriptor(fileName) { + override fun getDisplayName(): String = visibleName ?: fileName + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d726044..97c61cf 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -7,18 +7,25 @@ com.intellij.modules.platform com.jetbrains.php JavaScript + Git4Idea + + + + + + @@ -26,7 +33,6 @@ - - + diff --git a/src/main/resources/fileTemplates/j2ee/contribution/Shopware CHANGELOG.md.ft b/src/main/resources/fileTemplates/j2ee/contribution/Shopware CHANGELOG.md.ft new file mode 100644 index 0000000..b4bab04 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/contribution/Shopware CHANGELOG.md.ft @@ -0,0 +1,22 @@ +--- +title: ${TITLE} +issue: ${TICKET} +#if ("${FLAG}" != "") +flag: ${FLAG} +#end +--- +# Core +* +___ +# API +* +___ +# Administration +* +___ +# Storefront +* +___ +# Upgrade Information + +## Topic 1 \ No newline at end of file diff --git a/src/main/resources/fileTemplates/config.xml b/src/main/resources/fileTemplates/j2ee/plugin/Shopware Plugin config.xml.ft similarity index 100% rename from src/main/resources/fileTemplates/config.xml rename to src/main/resources/fileTemplates/j2ee/plugin/Shopware Plugin config.xml.ft diff --git a/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component SCSS.scss.ft b/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component SCSS.scss.ft new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component Twig.html.twig.ft b/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component Twig.html.twig.ft new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component.js.ft b/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component.js.ft new file mode 100644 index 0000000..7554d51 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/vue/Shopware Vue Component.js.ft @@ -0,0 +1,14 @@ +#if (${GENERATE_TWIG} == true) +import template from './${NAME}.html.twig'; +#end +#if (${GENERATE_SCSS} == true) +import './${NAME}.scss'; +#end + +const {Component} = Shopware; + +Component.register('${NAME}', { + #if (${GENERATE_TWIG} == true) + template + #end +}); \ No newline at end of file diff --git a/src/main/resources/fileTemplates/vue/component/index.js b/src/main/resources/fileTemplates/vue/component/index.js deleted file mode 100644 index 27f6de3..0000000 --- a/src/main/resources/fileTemplates/vue/component/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import template from './#COMPONENT-NAME#.html.twig'; -import './#COMPONENT-NAME#.scss'; - -const { Component } = Shopware; - -Component.register('#COMPONENT-NAME#', { - template, -}); \ No newline at end of file