From ce504d15414835362f882854a4c3411cbea8b10a Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 18:28:11 +0100 Subject: [PATCH 1/8] Fixes #30 replaceAll not replace --- scripts/src/lib/template/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/src/lib/template/template.ts b/scripts/src/lib/template/template.ts index 0106b269..0639bcff 100644 --- a/scripts/src/lib/template/template.ts +++ b/scripts/src/lib/template/template.ts @@ -58,7 +58,7 @@ export async function generateTemplate(options: Options) { } export function nameToModId(name: string) { - return name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-za-z0-9-_]/, ""); + return name.toLowerCase().replaceAll(/\s+/g, '-').replaceAll(/[^a-za-z0-9-_]/g, ""); } async function computeConfig(options: Configuration): Promise { From 81979445c7136299dccec3df134c0fa41d12ffc8 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 18:54:22 +0100 Subject: [PATCH 2/8] Fixes #28 use unix as target platform and add -x to gradlew --- scripts/src/lib/Template.svelte | 6 +++--- scripts/src/lib/template/gradlewrapper.ts | 4 +++- scripts/src/lib/template/template.ts | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/src/lib/Template.svelte b/scripts/src/lib/Template.svelte index 64477562..1c1c2926 100644 --- a/scripts/src/lib/Template.svelte +++ b/scripts/src/lib/Template.svelte @@ -114,14 +114,14 @@ await generator.generateTemplate({ config, writer: { - write: async (path, content) => { - zip.file(path, content); + write: async (path, content, options) => { + zip.file(path, content, options); }, }, }); FileSaver.saveAs( - await zip.generateAsync({ type: "blob" }), + await zip.generateAsync({ type: "blob", platform: "UNIX" }), `${modid}-template-${config.minecraftVersion}.zip` ); diff --git a/scripts/src/lib/template/gradlewrapper.ts b/scripts/src/lib/template/gradlewrapper.ts index 45f071e2..c58e4d5e 100644 --- a/scripts/src/lib/template/gradlewrapper.ts +++ b/scripts/src/lib/template/gradlewrapper.ts @@ -9,7 +9,9 @@ import gitignore from './templates/git/gitignore?raw'; import workflow from './templates/git/workflow.yml?raw' export async function addGradleWrapper({ writer }: Options) { - await writer.write('gradlew', gradlew); + await writer.write('gradlew', gradlew, { + unixPermissions: "774" + }); await writer.write('gradlew.bat', gradlewBat); await writer.write('gradle/wrapper/gradle-wrapper.properties', gradleWrapperProperties); await writer.write('gradle/wrapper/gradle-wrapper.jar', decode64(gradleWrapperJar)); diff --git a/scripts/src/lib/template/template.ts b/scripts/src/lib/template/template.ts index 0639bcff..88c1c148 100644 --- a/scripts/src/lib/template/template.ts +++ b/scripts/src/lib/template/template.ts @@ -3,6 +3,7 @@ import { addGroovyGradle } from './gradlegroovy'; import { getApiVersionForMinecraft, getKotlinAdapterVersions, getLoaderVersions, getMinecraftYarnVersions } from '../Api'; import { addModJson } from './modjson'; import { addGitFiles } from './git'; +import type { JSZipFileOptions } from 'jszip'; export interface Options { /** @@ -45,7 +46,7 @@ export interface TemplateOptions { } export interface TemplateWriter { - write(path: string, content: string | ArrayBufferLike): Promise + write(path: string, content: string | ArrayBufferLike, options?: JSZipFileOptions): Promise } export async function generateTemplate(options: Options) { From 6613e7b0a8241474c79e8b73b627a8af5e19265e Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 19:00:12 +0100 Subject: [PATCH 3/8] Fixed #31 crude but effective rejection of empty modid --- scripts/src/lib/Template.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/src/lib/Template.svelte b/scripts/src/lib/Template.svelte index 1c1c2926..c529887b 100644 --- a/scripts/src/lib/Template.svelte +++ b/scripts/src/lib/Template.svelte @@ -92,7 +92,7 @@ } async function generate() { - if (modIdErrors != undefined) { + if (modIdErrors != undefined || modid === "") { return; } @@ -156,6 +156,10 @@ {/if} + + {#if modid === ""} +

The Modname can not be empty!

+ {/if} {#if customModId != undefined} From 241f1f35023825b26c4dfa6faced2623d8adcf20 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 19:18:31 +0100 Subject: [PATCH 4/8] Fixed #32 use common validation rules --- scripts/src/lib/Template.svelte | 68 +++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/scripts/src/lib/Template.svelte b/scripts/src/lib/Template.svelte index c529887b..87330076 100644 --- a/scripts/src/lib/Template.svelte +++ b/scripts/src/lib/Template.svelte @@ -39,34 +39,43 @@ $: supportsDataGen = minorMcVersion >= 17; $: supportsSplitSources = minorMcVersion >= 19; - $: modIdErrors = computeModIdErrors(customModId); + $: modIdErrors = computeModIdErrors(modid); + $: customIdErrors = computeCustomModIdErrors(customModId); - // Ported/adapted from Loader's MetadataVerifier - function computeModIdErrors(id: string | undefined) : string[] | undefined { - if (id == undefined) { - return undefined; - } - let errorList : string[] = []; + function sharedModIdChecks(id: string, isId: boolean): string[] | undefined { + let errorList : string[] = []; - if (id.length == 0) { - return ["Modid is empty!"]; - } else if (id.length == 1) { - errorList.push("Modid is only a single character! (It must be at least 2 characters long)!"); - } else if (id.length > 64) { - errorList.push("Modid has more than 64 characters!"); + const type = isId ? "Modid" : "Mod Name"; + if (id.length == 0) { + return [`${type} is empty!`]; + } else if (id.length == 1) { + errorList.push(`${type} is only a single character! (It must be at least 2 characters long)!`); + } else if (id.length > 64) { + errorList.push(`${type} has more than 64 characters!`); + } + + return errorList.length === 0 ? undefined : errorList; + } + + // Ported/adapted from Loader's MetadataVerifier + function computeCustomModIdErrors(id: string | undefined): string[] | undefined { + if (id === undefined) { + return undefined; } + let errorList = sharedModIdChecks(id, true) ?? []; + const first = id.charAt(0); if (first < 'a' || first > 'z') { errorList.push("Modid starts with an invalid character '" + first + "' (it must belowercase a-z)"); } - var invalidChars: string[] | null = null; + let invalidChars: string[] | null = null; - for (var i = 1; i < id.length; i++) { - var c = id.charAt(i); + for (let i = 1; i < id.length; i++) { + let c = id.charAt(i); if (c == '-' || c == '_' || ('0' <= c && c <= '9') || ('a' <= c && c <= 'z')) { continue; @@ -80,7 +89,7 @@ } if (invalidChars != null) { - var error = "Modid contains invalid characters: " + invalidChars.map(value => "'" + value + "'").join(", ") + "!"; + let error = "Modid contains invalid characters: " + invalidChars.map(value => "'" + value + "'").join(", ") + "!"; errorList.push(error + "!"); } @@ -91,8 +100,16 @@ return errorList; } + function computeModIdErrors(id: string | undefined) : string[] | undefined { + if (id === undefined) { + return undefined; + } + + return sharedModIdChecks(id, customModId === undefined); + } + async function generate() { - if (modIdErrors != undefined || modid === "") { + if (modIdErrors !== undefined || (customModId !== undefined && customIdErrors !== undefined)) { return; } @@ -157,9 +174,12 @@ - {#if modid === ""} -

The Modname can not be empty!

- {/if} + {#if modIdErrors != undefined} + {#each modIdErrors as error} +
  • {error}
  • + {/each} +
    + {/if} {#if customModId != undefined} @@ -167,11 +187,11 @@

    Mod ID:


    Enter the modid you wish to use for your mod. Use default

    - {#if modIdErrors != undefined} - {#each modIdErrors as error} + {#if customIdErrors != undefined} + {#each customIdErrors as error}
  • {error}
  • {/each} -
    +
    {/if} From 8fe10baf0e90e51449677ab839a2d0f8c0566904 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 19:25:22 +0100 Subject: [PATCH 5/8] Fixed #33 random whitespace --- .../src/lib/template/templates/gradle/groovy/build.gradle.eta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta index e7123913..f3e5d94f 100644 --- a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta +++ b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta @@ -1,7 +1,7 @@ plugins { id 'fabric-loom' version '1.1-SNAPSHOT' id 'maven-publish' - <% if (it.kotlin) { %>id "org.jetbrains.kotlin.jvm" version "<%= it.kotlin.kotlinVersion %>"<% } %> + <%_ if (it.kotlin) { %>id "org.jetbrains.kotlin.jvm" version "<%= it.kotlin.kotlinVersion %>"<% } %> } sourceCompatibility = JavaVersion.<%= it.java.compatibility %> From bf81ea024f3b2fe0f712ea78259a2ac3de71b5ad Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 19:44:26 +0100 Subject: [PATCH 6/8] Fixed #35 use spaces instead of \t --- .../entrypoint/ClientEntrypoint.java.eta | 8 +++---- .../entrypoint/ClientEntrypoint.kt.eta | 6 ++--- .../DataGeneratorEntrypoint.java.eta | 6 ++--- .../entrypoint/DataGeneratorEntrypoint.kt.eta | 4 ++-- .../templates/entrypoint/Entrypoint.java.eta | 24 +++++++++---------- .../templates/entrypoint/Entrypoint.kt.eta | 16 ++++++------- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.java.eta b/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.java.eta index df538a89..555a906c 100644 --- a/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.java.eta +++ b/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.java.eta @@ -3,8 +3,8 @@ package <%= it.package %>; import net.fabricmc.api.ClientModInitializer; public class <%= it.className %> implements ClientModInitializer { - @Override - public void onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - } + @Override + public void onInitializeClient() { + // This entrypoint is suitable for setting up client-specific logic, such as rendering. + } } \ No newline at end of file diff --git a/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.kt.eta b/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.kt.eta index d572be72..a2b63814 100644 --- a/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.kt.eta +++ b/scripts/src/lib/template/templates/entrypoint/ClientEntrypoint.kt.eta @@ -3,7 +3,7 @@ package <%= it.package %> import net.fabricmc.api.ClientModInitializer object <%= it.className %> : ClientModInitializer { - override fun onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - } + override fun onInitializeClient() { + // This entrypoint is suitable for setting up client-specific logic, such as rendering. + } } \ No newline at end of file diff --git a/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.java.eta b/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.java.eta index 4e6d199a..8c661808 100644 --- a/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.java.eta +++ b/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.java.eta @@ -4,8 +4,8 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; public class <%= it.className %> implements DataGeneratorEntrypoint { - @Override - public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { + @Override + public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { - } + } } diff --git a/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.kt.eta b/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.kt.eta index 17261b9d..0adb31d1 100644 --- a/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.kt.eta +++ b/scripts/src/lib/template/templates/entrypoint/DataGeneratorEntrypoint.kt.eta @@ -4,6 +4,6 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator object <%= it.className %> : DataGeneratorEntrypoint { - override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) { - } + override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) { + } } \ No newline at end of file diff --git a/scripts/src/lib/template/templates/entrypoint/Entrypoint.java.eta b/scripts/src/lib/template/templates/entrypoint/Entrypoint.java.eta index de841615..7cebb42e 100644 --- a/scripts/src/lib/template/templates/entrypoint/Entrypoint.java.eta +++ b/scripts/src/lib/template/templates/entrypoint/Entrypoint.java.eta @@ -9,17 +9,17 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; <% } %> public class <%= it.className %> implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. -<% if (it.slf4j) { %> public static final Logger LOGGER = LoggerFactory.getLogger("<%= it.modid %>"); -<% } else { %> public static final Logger LOGGER = LogManager.getLogger("<%= it.modid %>");<% } %> - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. + // This logger is used to write text to the console and the log file. + // It is considered best practice to use your mod id as the logger's name. + // That way, it's clear which mod wrote info, warnings, and errors. +<% if (it.slf4j) { %> public static final Logger LOGGER = LoggerFactory.getLogger("<%= it.modid %>"); +<% } else { %> public static final Logger LOGGER = LogManager.getLogger("<%= it.modid %>");<% } %> + @Override + public void onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. - LOGGER.info("Hello Fabric world!"); - } + LOGGER.info("Hello Fabric world!"); + } } \ No newline at end of file diff --git a/scripts/src/lib/template/templates/entrypoint/Entrypoint.kt.eta b/scripts/src/lib/template/templates/entrypoint/Entrypoint.kt.eta index 51f6b81e..daa027b7 100644 --- a/scripts/src/lib/template/templates/entrypoint/Entrypoint.kt.eta +++ b/scripts/src/lib/template/templates/entrypoint/Entrypoint.kt.eta @@ -4,12 +4,12 @@ import net.fabricmc.api.ModInitializer <% if (it.slf4j) { %>import org.slf4j.LoggerFactory <% } else { %>import org.apache.logging.log4j.LogManager<% } %> object <%= it.className %> : ModInitializer { -<% if (it.slf4j) { %> private val logger = LoggerFactory.getLogger("<%= it.modid %>") -<% } else { %> private val logger = LogManager.getLogger("<%= it.modid %>")<% } %> - override fun onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - logger.info("Hello Fabric world!") - } +<% if (it.slf4j) { %> private val logger = LoggerFactory.getLogger("<%= it.modid %>") +<% } else { %> private val logger = LogManager.getLogger("<%= it.modid %>")<% } %> + override fun onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + logger.info("Hello Fabric world!") + } } \ No newline at end of file From 1d6598066963792cd41768acc1e8495bb9e09925 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 19:45:26 +0100 Subject: [PATCH 7/8] Fixed #36 use moid as the classpath group name --- .../src/lib/template/templates/gradle/groovy/build.gradle.eta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta index f3e5d94f..dfa36fc8 100644 --- a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta +++ b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta @@ -23,7 +23,7 @@ loom { <% if (it.splitSources) { %> splitEnvironmentSourceSets() mods { - modid { + "<%= it.modid %>" { sourceSet sourceSets.main sourceSet sourceSets.client } From d2a9e1c483cd31d5566f4b28572355f6fafbfba5 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Fri, 21 Apr 2023 20:07:22 +0100 Subject: [PATCH 8/8] Fixed #33 but for kotlin as well --- .../src/lib/template/templates/gradle/groovy/build.gradle.eta | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta index dfa36fc8..9e26c74e 100644 --- a/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta +++ b/scripts/src/lib/template/templates/gradle/groovy/build.gradle.eta @@ -1,7 +1,9 @@ plugins { id 'fabric-loom' version '1.1-SNAPSHOT' id 'maven-publish' - <%_ if (it.kotlin) { %>id "org.jetbrains.kotlin.jvm" version "<%= it.kotlin.kotlinVersion %>"<% } %> + <%_ if (it.kotlin) { %> + id "org.jetbrains.kotlin.jvm" version "<%= it.kotlin.kotlinVersion %>" + <%_ } %> } sourceCompatibility = JavaVersion.<%= it.java.compatibility %>