Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Node deps
node_modules/

# Python deps
env/
__pycache__/

# Build output
dist/
src/assets/
src/web/assets/

# Editor / OS
.vscode/
.idea/
.DS_Store
.DS_Store

*.log
*.egg-info/

modular_server_manager_web_client/
39 changes: 39 additions & 0 deletions build_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
This script builds a Python package using the `build` module.
It allows for passing additional arguments to the build command and
supports specifying a version number via command line arguments.
It also sets the `PACKAGE_VERSION` environment variable if a version is provided.
"""

import os
import subprocess
import sys
import re


def patch_pyproject_version(version: str):
pyproject_path = "pyproject.toml"
with open(pyproject_path, "r") as f:
content = f.read()

new_content = re.sub(
r'^version\s*=\s*"[0-9a-zA-Z\.\-\_]+"',
f'version = "{version}"',
content
)

with open(pyproject_path, "w") as f:
f.write(new_content)


if "--version" in sys.argv:
idx = sys.argv.index("--version")
version = sys.argv[idx + 1]
os.environ["PACKAGE_VERSION"] = version
patch_pyproject_version(version)
sys.argv.pop(idx) # remove --version
sys.argv.pop(idx) # remove version value

cmd = [sys.executable, "-m", "build"] + sys.argv[1:]
print(" ".join(cmd)) # Print the command for debugging
subprocess.run(cmd, check=True, stderr=sys.stderr, stdout=sys.stdout)
41 changes: 41 additions & 0 deletions get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

def install_if_not_installed(package_name, url):
try:
__import__(package_name)
except ImportError:
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", url])



install_if_not_installed("version", "https://github.com/T0ine34/python-sample/releases/download/1.0.2/version-1.0.2-py3-none-any.whl")


import os

from version import Version

branch = os.popen("git rev-parse --abbrev-ref HEAD").read().strip()

def get_tag():
tags_list = os.popen("git tag").read().strip().split("\n")
tags = [Version.from_string(t) for t in tags_list if t]
tags.sort(reverse=True)
return tags[0] if tags else Version(0, 0, 0)

try:
version = Version.from_string(branch)
except ValueError:
version = get_tag()
version.prerelease = "alpha"

if version.minor >= 1:
version.patch_increment()
else:
version.minor_increment()

last_commit = os.popen("git rev-parse HEAD").read().strip()

version.metadata = last_commit
print(version)
92 changes: 92 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.PHONY: all build clean

all: build

TEMP_DIR = build

PYPROJECT = pyproject.toml


BUILD_DIR = modular_server_manager_web_client/
WEB_BUILD_DIR = $(BUILD_DIR)client

PYTHON_PATH = $(shell if [ -d env/bin ]; then echo "env/bin/"; elif [ -d env/Scripts ]; then echo "env/Scripts/"; else echo ""; fi)
PYTHON_LIB = $(shell find env/lib -type d -name "site-packages" | head -n 1; if [ -d env/Lib/site-packages ]; then echo "env/Lib/site-packages/"; fi)
PYTHON = $(PYTHON_PATH)python

EXECUTABLE_EXTENSION = $(shell if [ -d env/bin ]; then echo ""; elif [ -d env/Scripts ]; then echo ".exe"; else echo ""; fi)
APP_EXECUTABLE = $(PYTHON_PATH)modular-server-manager$(EXECUTABLE_EXTENSION)

INSTAL_PATH = $(PYTHON_LIB)/modular_server_manager_web_client

# if not defined, get the version from git
VERSION ?= $(shell $(PYTHON) get_version.py)

# if version is in the form of x.y.z-dev-aaaa or x.y.z-dev+aaaa, set it to x.y.z-dev
VERSION_STR = $(shell echo $(VERSION) | sed "s/-dev-[a-z0-9]*//; s/-dev+.*//")

WHEEL = modular_server_manager_web_client-$(VERSION_STR)-py3-none-any.whl
ARCHIVE = modular_server_manager_web_client-$(VERSION_STR).tar.gz

SRV_SRC_DIR = src/server/
SRV_SRC = $(shell find $(SRV_SRC_DIR) -type f -name "*.py") $(SRV_SRC_DIR)compatibility.json
SRV_DIST = $(patsubst $(SRV_SRC_DIR)%,$(BUILD_DIR)%,$(SRV_SRC))

WEB_SRC_DIR = src/web/
WEB_SRC = $(shell find $(WEB_SRC_DIR) -type f -name "*.html" -o -name "*.scss" -o -name "*.ts")
WEB_DIST = $(WEB_BUILD_DIR)/index.html $(WEB_BUILD_DIR)/assets/css/main.css $(WEB_BUILD_DIR)/assets/app.js


print-%:
@echo $* = $($*)

dist:
mkdir -p dist

dist/$(WHEEL): $(SRV_DIST) $(PYPROJECT) $(WEB_DIST) $(PYTHON_LIB)/build dist
mkdir -p $(TEMP_DIR)
$(PYTHON) build_package.py --outdir $(TEMP_DIR) --wheel --version $(VERSION_STR)
mkdir -p dist
mv $(TEMP_DIR)/*.whl dist/$(WHEEL)
rm -rf $(TEMP_DIR)
@echo "Building wheel package complete."

dist/$(ARCHIVE): $(SRV_DIST) $(PYPROJECT) $(WEB_DIST) $(PYTHON_LIB)/build dist
mkdir -p $(TEMP_DIR)
$(PYTHON) build_package.py --outdir $(TEMP_DIR) --sdist --version $(VERSION_STR)
mkdir -p dist
mv $(TEMP_DIR)/*.tar.gz dist/$(ARCHIVE)
rm -rf $(TEMP_DIR)
@echo "Building archive package complete."

$(WEB_DIST): $(WEB_SRC)
npm run build

$(BUILD_DIR)%: $(SRV_SRC_DIR)%
@mkdir -p $(@D)
@echo "Copying $< to $@"
@cp $< $@


$(INSTAL_PATH) : dist/$(WHEEL)
@echo "Installing package..."
@$(PYTHON) -m pip install --upgrade --force-reinstall dist/$(WHEEL)
@echo "Package installed."


build: dist/$(WHEEL) dist/$(ARCHIVE)

install: $(INSTAL_PATH)

start: install
@$(APP_EXECUTABLE) \
-c /var/minecraft/config.json \
--log-file server.trace.log:TRACE \
--log-file server.debug.log:DEBUG


clean:
rm -rf $(BUILD_DIR)
rm -rf dist
rm -rf $(PYTHON_LIB)/modular_server_manager_web_client
rm -rf $(PYTHON_LIB)/modular_server_manager_web_client-*.dist-info
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "web-client",
"version": "0.1.0",
"private": true,
"description": "Web client (TypeScript + SCSS + SCSS + HTML) — lightweight build using esbuild and sass",
"description": "Web modular_server_manager_web_client/client (TypeScript + SCSS + SCSS + HTML) — lightweight build using esbuild and sass",
"scripts": {
"dev": "concurrently \"esbuild src/main.ts --bundle --outfile=src/assets/app.js --sourcemap --watch\" \"sass src/styles/main.scss src/assets/css/main.css --watch\" \"live-server src --port=3000 --open=./index.html\"",
"build": "rimraf dist && mkdir -p dist && sass src/styles/main.scss dist/assets/css/main.css --no-source-map && esbuild src/main.ts --bundle --minify --target=es2017 --outfile=dist/assets/app.js && cpy \"src/*.html\" dist/",
"clean": "rimraf dist src/assets",
"format": "prettier --write \"src/**/*.{ts,scss,html}\""
"dev": "concurrently \"esbuild src/web/main.ts --bundle --outfile=src/web/assets/app.js --sourcemap --watch\" \"sass src/web/styles/main.scss src/web/assets/css/main.css --watch\" \"live-server src/web --port=3000 --open=./index.html\"",
"build": "rimraf modular_server_manager_web_client/client && mkdir -p modular_server_manager_web_client/client && sass src/web/styles/main.scss modular_server_manager_web_client/client/assets/css/main.css --no-source-map && esbuild src/web/main.ts --bundle --minify --target=es2017 --outfile=modular_server_manager_web_client/client/assets/app.js && cpy \"src/web/*.html\" modular_server_manager_web_client/client/",
"clean": "rimraf modular_server_manager_web_client/client src/web/assets",
"format": "prettier --write \"src/web**/*.{ts,scss,html}\""
},
"devDependencies": {
"esbuild": "^0.19.0",
Expand Down
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[project]
name = "modular-server-manager-web-client"
version = "0.1.0"
description = "MSM Web Client"
authors = [
{ name = "Antoine BUIREY", email = "antoine.buirey@gmail.com" }
]
requires-python = ">=3.12"
dependencies = [
"blinker==1.9.0",
"click==8.1.8",
"Flask==3.1.1",
"gamuLogger>=3.2.4",
"itsdangerous==2.2.0",
"Jinja2==3.1.6",
"MarkupSafe==3.0.2",
"typing_extensions==4.13.2",
"urllib3==2.5.0",
"Werkzeug==3.1.3",
"dnspython==2.7.0",
"eventlet==0.40.3",
"greenlet==3.2.1",
"python-socketio==5.14.0",
"http_code @ https://github.com/T0ine34/python-sample/releases/download/1.1.6/http_code-1.1.6-py3-none-any.whl",
"singleton @ https://github.com/T0ine34/python-sample/releases/download/1.1.6/singleton-1.1.6-py3-none-any.whl",
"version @ https://github.com/T0ine34/python-sample/releases/download/1.1.6/version-1.1.6-py3-none-any.whl",
"modular-server-manager @ https://github.com/modular-server-manager/server/releases/download/0.1.4/modular_server_manager-0.1.4-py3-none-any.whl"
]

[tool.setuptools]
packages = ["modular_server_manager_web_client"]

package-data = { "modular_server_manager_web_client" = [
"client/*",
"client/**/*",
"compatibility.json",
] }
include-package-data = true
1 change: 1 addition & 0 deletions src/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .web_server import WebServer as Interface
17 changes: 17 additions & 0 deletions src/server/compatibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/AntoineBuirey/xml-json-schema/refs/tags/1.2.3/modular-server-manager/compatibility.schema",
"compatibility": {
"0.1.3": {
"min_module_version": "0.1.0",
"max_module_version": "0.1.0"
},
"0.1.4": {
"min_module_version": "0.1.0",
"max_module_version": "0.1.0"
},
"0.1.5": {
"min_module_version": "0.1.0",
"max_module_version": "0.1.0"
}
}
}
Loading