|
| 1 | +import zipfile |
| 2 | +import shutil |
| 3 | +from pathlib import Path |
| 4 | +import datetime |
| 5 | + |
| 6 | +# Paths |
| 7 | +project_root = Path(__file__).parent |
| 8 | +dist_dir = project_root / "dist" |
| 9 | +build_dir = project_root / "dadmin-dist" |
| 10 | +data_dir = project_root / "data" |
| 11 | +output_name = f"dadmin-v{datetime.datetime.now().strftime('%Y%m%d')}.zip" |
| 12 | +output_zip = project_root / output_name |
| 13 | + |
| 14 | +# Clean build dir |
| 15 | +if build_dir.exists(): |
| 16 | + shutil.rmtree(build_dir) |
| 17 | +build_dir.mkdir() |
| 18 | + |
| 19 | +# Ensure data dir exists |
| 20 | +if not data_dir.exists(): |
| 21 | + data_dir.mkdir(parents=True) |
| 22 | + (data_dir / "items.json").write_text("[]") |
| 23 | + (data_dir / "effects.json").write_text("[]") |
| 24 | + |
| 25 | +# Ensure example config exists |
| 26 | +config_path = project_root / "server_config.txt" |
| 27 | +if not config_path.exists(): |
| 28 | + config_path.write_text("host=localhost\nport=25575\npassword=changeme") |
| 29 | + |
| 30 | +# Ensure README exists |
| 31 | +readme_path = project_root / "README.md" |
| 32 | +if not readme_path.exists(): |
| 33 | + readme_path.write_text("# dadmin\n\nMinecraft RCON admin GUI.") |
| 34 | + |
| 35 | +# Copy essentials |
| 36 | +shutil.copy(dist_dir / "dadmin.exe", build_dir / "dadmin.exe") |
| 37 | +shutil.copy(config_path, build_dir / "server_config-example.txt") |
| 38 | +shutil.copy(readme_path, build_dir / "README.md") |
| 39 | +shutil.copytree(data_dir, build_dir / "data") |
| 40 | + |
| 41 | +# Optional icon handling |
| 42 | +icon_path = project_root / "icon.ico" |
| 43 | +if icon_path.exists(): |
| 44 | + shutil.copy(icon_path, build_dir / "icon.ico") |
| 45 | + |
| 46 | +# Zip it |
| 47 | +with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zipf: |
| 48 | + for path in build_dir.rglob("*"): |
| 49 | + zipf.write(path, path.relative_to(build_dir.parent)) |
| 50 | + |
| 51 | +print(f"✅ Created {output_zip}") |
0 commit comments