121 lines
5.5 KiB
Python
121 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import shutil
|
|
import sys
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
from script_common import find_csproj_by_keyword, find_node_app_root, resolve_repo_root, run # type: ignore
|
|
|
|
def has_package_script(app_root: Path, script_name: str) -> bool:
|
|
package_json = app_root / "package.json"
|
|
if not package_json.exists():
|
|
return False
|
|
try:
|
|
data = json.loads(package_json.read_text(encoding="utf-8"))
|
|
except Exception:
|
|
return False
|
|
scripts = data.get("scripts")
|
|
if not isinstance(scripts, dict):
|
|
return False
|
|
value = scripts.get(script_name)
|
|
return isinstance(value, str) and value.strip() != ""
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Publish bundled outputs using Python script entrypoints")
|
|
_ = parser.add_argument("--configuration", choices=["Release", "Debug"], default="Release")
|
|
_ = parser.add_argument("--runtime", default="win-x64")
|
|
_ = parser.add_argument("--skip-sidecar", action="store_true")
|
|
_ = parser.add_argument("--skip-web", action="store_true")
|
|
_ = parser.add_argument("--skip-webgateway", action="store_true")
|
|
_ = parser.add_argument("--skip-tauri", action="store_true")
|
|
_ = parser.add_argument("--dry-run", action="store_true")
|
|
_ = parser.add_argument("--repo-root", default=None)
|
|
_ = parser.add_argument("--sidecar-project", default=None)
|
|
_ = parser.add_argument("--gateway-project", default=None)
|
|
_ = parser.add_argument("--app-root", default=None)
|
|
_ = parser.add_argument("--output-dir", default="output")
|
|
args = parser.parse_args()
|
|
|
|
repo_root = resolve_repo_root(args.repo_root)
|
|
output_root = (repo_root / args.output_dir).resolve()
|
|
output_root.mkdir(parents=True, exist_ok=True)
|
|
|
|
sidecar_project = (repo_root / args.sidecar_project).resolve() if args.sidecar_project else find_csproj_by_keyword(repo_root, ["sidecar"])
|
|
gateway_project = (repo_root / args.gateway_project).resolve() if args.gateway_project else find_csproj_by_keyword(repo_root, ["webgateway", "gateway"])
|
|
app_root = (repo_root / args.app_root).resolve() if args.app_root else find_node_app_root(repo_root, None)
|
|
|
|
tauri_conf = None
|
|
if app_root is not None:
|
|
tauri_conf = next((p for p in [app_root/"src-tauri"/"tauri.conf.json", app_root/"tauri.conf.json"] if p.exists()), None)
|
|
|
|
py = sys.executable
|
|
scripts_dir = Path(__file__).parent
|
|
|
|
if not args.skip_sidecar:
|
|
if sidecar_project is None:
|
|
print("Skipping sidecar: no sidecar csproj detected.")
|
|
else:
|
|
cmd = ["-m", "scripts.publish-sidecar" if __package__ else "publish-sidecar",
|
|
"--configuration", args.configuration, "--runtime", args.runtime, "--project", str(sidecar_project)]
|
|
print(f"\n> Publishing Sidecar\n$ {py} {' '.join(cmd)}")
|
|
if not args.dry_run:
|
|
code = run(py, cmd, scripts_dir)
|
|
if code != 0: return code
|
|
|
|
if not args.skip_web:
|
|
if app_root is None:
|
|
print("Skipping web: no app root detected.")
|
|
elif not has_package_script(app_root, "build"):
|
|
print("Skipping web: package.json has no 'build' script.")
|
|
else:
|
|
cmd = ["-m", "scripts.publish-app" if __package__ else "publish-app",
|
|
"--target", "web", "--configuration", args.configuration, "--app-root", str(app_root)]
|
|
print(f"\n> Building Web\n$ {py} {' '.join(cmd)}")
|
|
if not args.dry_run:
|
|
code = run(py, cmd, scripts_dir)
|
|
if code != 0: return code
|
|
|
|
if not args.skip_webgateway:
|
|
if gateway_project is None:
|
|
print("Skipping web gateway: no gateway csproj detected.")
|
|
else:
|
|
cmd = ["-m", "scripts.publish-webgateway" if __package__ else "publish-webgateway",
|
|
"--configuration", args.configuration, "--runtime", args.runtime, "--project", str(gateway_project)]
|
|
print(f"\n> Publishing Web Gateway\n$ {py} {' '.join(cmd)}")
|
|
if not args.dry_run:
|
|
code = run(py, cmd, scripts_dir)
|
|
if code != 0: return code
|
|
|
|
if not args.skip_tauri:
|
|
if app_root is None or tauri_conf is None:
|
|
print("Skipping tauri: tauri app not detected.")
|
|
elif not has_package_script(app_root, "tauri"):
|
|
print("Skipping tauri: package.json has no 'tauri' script.")
|
|
else:
|
|
cmd = ["-m", "scripts.publish-app" if __package__ else "publish-app",
|
|
"--target", "tauri", "--configuration", args.configuration, "--tauri-bundles", "none", "--app-root", str(app_root)]
|
|
print(f"\n> Building Tauri\n$ {py} {' '.join(cmd)}")
|
|
if not args.dry_run:
|
|
code = run(py, cmd, scripts_dir)
|
|
if code != 0: return code
|
|
|
|
target_dir = app_root / "src-tauri" / "target" / ("debug" if args.configuration == "Debug" else "release")
|
|
pattern = "*.exe" if os.name == "nt" else "*"
|
|
exes = sorted((p for p in target_dir.glob(pattern) if p.is_file() and (os.name == "nt" or not p.suffix)), key=lambda p: p.stat().st_mtime, reverse=True)
|
|
|
|
if exes:
|
|
staged = output_root / exes[0].name
|
|
if args.dry_run: print(f"Would copy: {exes[0]} -> {staged}")
|
|
else:
|
|
shutil.copy2(exes[0], staged)
|
|
print(f"Staged desktop executable: {staged}")
|
|
|
|
print("\nPublish output workflow complete.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|