-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
53 lines (46 loc) · 2.02 KB
/
build.py
File metadata and controls
53 lines (46 loc) · 2.02 KB
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
#!/usr/bin/env python3
import os, json, zipfile, re
from shutil import copyfile
ROOT = os.path.dirname(os.path.abspath(__file__))
def sanitize_filename(name: str) -> str:
# Keep it filesystem-safe and nice
return re.sub(r"[^A-Za-z0-9._-]+", "-", name).strip("-")
def find_sd_plugin_folders(root: str) -> list:
# Find all .sdPlugin folders in the root directory
return [
os.path.join(root, entry)
for entry in os.listdir(root)
if entry.endswith(".sdPlugin") and os.path.isdir(os.path.join(root, entry))
]
def read_manifest(sd_plugin_path: str) -> dict:
mf = os.path.join(sd_plugin_path, "manifest.json")
if not os.path.exists(mf):
raise SystemExit("manifest.json not found in " + sd_plugin_path)
with open(mf, "r", encoding="utf-8") as f:
return json.load(f)
def zip_directory(src_dir: str, zip_path: str):
with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as z:
for root, _, files in os.walk(src_dir):
for file in files:
full = os.path.join(root, file)
# Stream Deck plugin expects the top-level folder name in the archive
archive_name = os.path.relpath(full, os.path.dirname(src_dir))
z.write(full, archive_name)
def main():
sd_plugins = find_sd_plugin_folders(ROOT)
if not sd_plugins:
raise SystemExit("No .sdPlugin folders found next to build.py")
out_dir = os.path.join(ROOT, "dist")
os.makedirs(out_dir, exist_ok=True)
for plugin in sd_plugins:
manifest = read_manifest(plugin)
name = sanitize_filename(manifest.get("Name", "Plugin"))
version = sanitize_filename(manifest.get("Version", "0.0.0"))
out_file = os.path.join(out_dir, f"{name}-{version}.streamDeckPlugin")
zip_directory(plugin, out_file)
# Make a copy renamed .zip
zip_copy = out_file.replace(".streamDeckPlugin", ".zip")
copyfile(out_file, zip_copy)
print("Built:", out_file)
if __name__ == "__main__":
main()