72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import shutil
|
|
from typing import cast
|
|
from script_common import ensure_dotnet_publish, find_csproj_by_keyword, resolve_repo_root, SdtResult
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Cross-platform ASP.NET gateway publish helper")
|
|
_ = parser.add_argument("--configuration", choices=["Release", "Debug"], default="Release")
|
|
_ = parser.add_argument("--runtime", default="win-x64")
|
|
_ = parser.add_argument("--self-contained", action="store_true")
|
|
_ = parser.add_argument("--skip-web-assets", action="store_true")
|
|
_ = parser.add_argument("--repo-root", default=None)
|
|
_ = parser.add_argument("--project", default=None, help="Relative/absolute path to gateway csproj")
|
|
_ = parser.add_argument("--web-build-dir", default=None, help="Relative path to web build assets root")
|
|
_ = parser.add_argument("--output-dir", default="output/webgateway")
|
|
args = parser.parse_args()
|
|
|
|
repo_root_val = cast(str | None, args.repo_root)
|
|
repo_root = resolve_repo_root(repo_root_val)
|
|
output_dir_val = cast(str, args.output_dir)
|
|
output_dir = (repo_root / output_dir_val).resolve()
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
project_val = cast(str | None, args.project)
|
|
if project_val:
|
|
csproj = (repo_root / project_val).resolve()
|
|
else:
|
|
csproj = find_csproj_by_keyword(repo_root, ["webgateway", "gateway"])
|
|
|
|
if csproj is None or not csproj.exists():
|
|
print("Could not locate web gateway project. Pass --project <path/to/project.csproj>.")
|
|
return 2
|
|
|
|
res: SdtResult = ensure_dotnet_publish(
|
|
csproj=csproj,
|
|
output_dir=output_dir,
|
|
configuration=str(args.configuration),
|
|
runtime=str(args.runtime),
|
|
self_contained=bool(args.self_contained),
|
|
single_file=False
|
|
)
|
|
|
|
if res["exit_code"] != 0:
|
|
return int(res["exit_code"])
|
|
|
|
if not args.skip_web_assets:
|
|
web_build_dir_val = cast(str | None, args.web_build_dir)
|
|
if web_build_dir_val:
|
|
web_build_dir = (repo_root / web_build_dir_val).resolve()
|
|
else:
|
|
# Look for recent web build output
|
|
# (Note: rglob is costly but necessary for discovery here)
|
|
web_pj = next((p.parent for p in repo_root.rglob("package.json") if (p.parent / "build").exists()), None)
|
|
web_build_dir = web_pj / "build" if web_pj else None
|
|
|
|
if web_build_dir is None or not web_build_dir.exists():
|
|
print("Web assets not found. Skip with --skip-web-assets or pass --web-build-dir.")
|
|
else:
|
|
web_out = output_dir / "wwwroot"
|
|
print(f"Copying web assets: {web_build_dir} -> {web_out}")
|
|
shutil.copytree(web_build_dir, web_out, dirs_exist_ok=True)
|
|
print(f"Copied web assets to {web_out}")
|
|
|
|
print(f"Publish completed: {output_dir}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|