Last active
April 24, 2022 06:53
-
-
Save Jummit/03057cd3597dfb73d92760f3c1d8e612 to your computer and use it in GitHub Desktop.
Generate new Fabric/Forge/Quilt/Architectury mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Script to help create new modding projects. | |
Execute this inside the template folder and | |
fill in the form. | |
""" | |
import os | |
def main(): | |
settings = { | |
"name": "Mod Name", | |
"id": "Mod Id", | |
"description": "Mod Description", | |
"author": "Author", | |
"license": "License", | |
"website": "Website", | |
"package": "Java Package", | |
} | |
defaults = { | |
"id": lambda info: info["name"].replace(" ", "").lower(), | |
"package": lambda info: "com." + info["author"].lower() + "." + info["id"], | |
"license": lambda _: "MIT", | |
} | |
info = {} | |
print("Enter mod info, ^C to quit.") | |
for setting, description in settings.items(): | |
default = "" | |
if setting in defaults: | |
default = defaults[setting](info) | |
description += f" ({default})" | |
info[setting] = input(description + ": ") or default | |
replacements = { | |
"architectury-example-mod": info["name"].lower().replace(" ", "-"), | |
"example-mod": info["name"].lower().replace(" ", "-"), | |
"net/examplemod": info["package"].replace(".", "/"), | |
"Example Mod": info["name"], | |
"This is an example description! Tell everyone what your mod is about!": info["description"], | |
"Me!": info["author"], | |
"Insert License Here": info["license"], | |
"net.examplemod": info["package"], | |
"examplemod": info["name"].replace(" ", "").lower(), | |
"ExampleMod": info["name"].replace(" ", ""), | |
} | |
for root, _, files in os.walk("."): | |
for file in files: | |
old = os.path.join(root, file) | |
if old[0:1] == "./": | |
continue | |
new = old | |
for replacement, to in replacements.items(): | |
new = new.replace(replacement, to) | |
if old != new: | |
print(f"{old} -> {new}") | |
os.renames(old, new) | |
try: | |
with open(new) as original: | |
print(f"Replace in {new}:") | |
old_content = original.read() | |
new_content = old_content | |
for what, to in replacements.items(): | |
if what in new_content: | |
print(f" {what} -> {to}") | |
new_content = new_content.replace(what, to) | |
if old_content != new_content: | |
print(f"Replace in {new}") | |
with open(new, "w") as modified: | |
modified.write(new_content) | |
except UnicodeDecodeError: | |
print(f"Can't read {new}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment