⁠
joseph burton: Add Fabric CLI based project creator support (#2654 )
- Add run_npm_package finalizer, which runs a package from npm or a git
repository in a plugin-maintained npm environment, and warns the user
about the code it will run
- Add generate_files and replace_in_file finalizers
- Add fabric_game_version property type
- Bump the template format version to 4, and point the templates
submodule to the v4 branch
- Add run_npm_package finalizer, which runs a package from npm or a git
repository in a plugin-maintained npm environment, and warns the user
about the code it will run
- Add generate_files and replace_in_file finalizers
- Add fabric_game_version property type
- Bump the template format version to 4, and point the templates
submodule to the v4 branch
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2026 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
- package com.demonwav.mcdev.creator.custom.finalizers
-
- import com.demonwav.mcdev.creator.custom.CreatorTemplateProcessor
- import com.demonwav.mcdev.creator.custom.TemplateFile
- import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
- import com.google.gson.Gson
- import com.intellij.ide.util.projectWizard.WizardContext
- import com.intellij.openapi.application.WriteAction
- import com.intellij.openapi.diagnostic.thisLogger
- import com.intellij.openapi.project.Project
-
- /**
- * Generates template files at this point of the finalization, instead of before any finalizer runs. This allows
- * overwriting files created by other finalizers, such as a project generated by an external tool.
- *
- * The `files` property has the same format as the template descriptor's `files`.
- */
- class GenerateFilesFinalizer : CreatorFinalizer {
-
- override fun validate(reporter: TemplateValidationReporter, properties: Map<String, Any>) {
- val files = properties["files"] as? List<*>
- if (files == null) {
- reporter.error("Missing list of 'files' to generate")
- return
- }
-
- for ((index, file) in files.withIndex()) {
- if (file !is Map<*, *>) {
- reporter.error("File #$index must be an object")
- continue
- }
-
- if (file["template"] !is String) {
- reporter.error("File #$index is missing its 'template'")
- }
- if (file["destination"] !is String) {
- reporter.error("File #$index is missing its 'destination'")
- }
- }
- }
-
- override suspend fun execute(
- context: WizardContext,
- project: Project,
- properties: Map<String, Any>,
- templateProperties: Map<String, Any?>
- ) {
- val template = context.getUserData(CreatorTemplateProcessor.LOADED_TEMPLATE_KEY)
- if (template == null) {
- thisLogger().error("No template available to generate files from")
- return
- }
-
- val gson = Gson()
- val files = (properties["files"] as List<*>)
- .map { gson.fromJson(gson.toJsonTree(it), TemplateFile::class.java) }
- val generatedFiles = CreatorTemplateProcessor.writeFiles(
- template,
- files,
- templateProperties,
- context.projectDirectory,
- )
-
- WriteAction.runAndWait<Throwable> {
- CreatorTemplateProcessor.reformatAndOpenFiles(project, generatedFiles)
- }
- }
- }