-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·61 lines (43 loc) · 1.61 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
import pathlib
from importlib import import_module
from shutil import copy, make_archive, rmtree
import json
from src.generators._base import BaseGenerator, GeneratorError
SOURCE = pathlib.Path(".") / "src"
BUILD = pathlib.Path(".") / "build"
rmtree(BUILD, ignore_errors=True)
BUILD.mkdir(exist_ok=True)
PACK = BUILD / "gurkpack"
PACK.mkdir()
INTERMEDIATE = BUILD / "intermediate"
INTERMEDIATE.mkdir()
GEN_NAMESPACE = PACK / "data" / "generated"
FUNCTIONS = GEN_NAMESPACE / "functions"
FUNCTIONS.mkdir(parents=True)
MINECRAFT_TAGS = PACK / "data" / "minecraft" / "tags" / "functions"
MINECRAFT_TAGS.mkdir(parents=True)
copy(SOURCE / "pack.mcmeta", PACK / "pack.mcmeta")
GENERATORS = sorted(g for g in (SOURCE / "generators").iterdir() if g.is_file() and not g.name.startswith("_"))
STEPS = len(GENERATORS) + 1
step = 1
setup_functions = []
tick_functions = []
for generator in GENERATORS:
module_path = ".".join(generator.parts).removesuffix(".py")
gen: BaseGenerator = import_module(module_path).Generator()
print(f"[{step}/{STEPS}] {gen.name}")
try:
result = gen.generate()
except GeneratorError as e:
print(f" Error while executing generator: {e}")
exit(1)
setup_functions.extend(result.setup_hooks)
tick_functions.extend(result.tick_hooks)
step += 1
with open(MINECRAFT_TAGS / "tick.json", "w") as file:
json.dump({"values": tick_functions}, file)
with open(MINECRAFT_TAGS / "load.json", "w") as file:
json.dump({"values": setup_functions}, file)
make_archive(PACK, "zip", PACK)
print(f"[{STEPS}/{STEPS}] Pack created in {PACK}.zip")