v0.4.2: host preview icons on OSS for slim Pages deploys.
Add STATIC_ASSET_BASE so Cloudflare Pages ships ~2MB HTML/JS/data; icons served from climperor OSS via _oss_static_assets.py. New machines can deploy without local fetch scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+44
-13
@@ -43,6 +43,7 @@ ROOT = Path(__file__).resolve().parent
|
||||
DEFAULT_PROJECT = "climperor-relations"
|
||||
DEFAULT_DOMAIN = "dota2.refining.dev"
|
||||
DEFAULT_DIST = ROOT / "dist" / "relations"
|
||||
DEFAULT_OSS_BASE = "https://climperor.oss-cn-shanghai.aliyuncs.com"
|
||||
|
||||
# Directories export_relations_site.py writes under dist/relations. Keys are
|
||||
# the sub-directory names; values flag whether an empty dir is a hard failure
|
||||
@@ -148,25 +149,49 @@ def ensure_project(email: str, api_key: str, account_id: str, project: str) -> N
|
||||
raise SystemExit(f"create project failed: {d.get('errors')}")
|
||||
|
||||
|
||||
def run_export(ability_video_base: str | None = None) -> None:
|
||||
def run_export(
|
||||
ability_video_base: str | None = None,
|
||||
static_asset_base: str | None = None,
|
||||
) -> None:
|
||||
"""Re-run export_relations_site.py to refresh dist/relations."""
|
||||
print("exporting static site ...")
|
||||
cmd = [sys.executable, str(ROOT / "export_relations_site.py")]
|
||||
# Production Pages should load ability demos from OSS, not bundle GB of video.
|
||||
base = ability_video_base
|
||||
if base is None:
|
||||
base = os.environ.get(
|
||||
"ABILITY_VIDEO_BASE",
|
||||
"https://climperor.oss-cn-shanghai.aliyuncs.com",
|
||||
)
|
||||
if base:
|
||||
cmd.extend(["--ability-video-base", base])
|
||||
print(f"ABILITY_VIDEO_BASE={base}")
|
||||
oss = ability_video_base
|
||||
if oss is None:
|
||||
oss = os.environ.get("ABILITY_VIDEO_BASE", DEFAULT_OSS_BASE)
|
||||
static = static_asset_base
|
||||
if static is None:
|
||||
static = os.environ.get("STATIC_ASSET_BASE", oss or DEFAULT_OSS_BASE)
|
||||
if oss:
|
||||
cmd.extend(["--ability-video-base", oss])
|
||||
print(f"ABILITY_VIDEO_BASE={oss}")
|
||||
if static:
|
||||
cmd.extend(["--static-asset-base", static])
|
||||
print(f"STATIC_ASSET_BASE={static}")
|
||||
subprocess.run(cmd, cwd=str(ROOT), check=True)
|
||||
|
||||
|
||||
def read_config_js_var(dist: Path, name: str) -> str:
|
||||
"""Parse a string literal from generated config.js."""
|
||||
cfg = dist / "config.js"
|
||||
if not cfg.is_file():
|
||||
return ""
|
||||
prefix = f"var {name} = "
|
||||
for line in cfg.read_text(encoding="utf-8").splitlines():
|
||||
if line.startswith(prefix):
|
||||
return json.loads(line[len(prefix) :].rstrip(";"))
|
||||
return ""
|
||||
|
||||
|
||||
def check_integrity(dist: Path) -> None:
|
||||
"""Abort if a hard-required asset directory is empty; warn otherwise."""
|
||||
static_base = read_config_js_var(dist, "STATIC_ASSET_BASE")
|
||||
if static_base:
|
||||
print(
|
||||
f"asset integrity check: skipped local dirs "
|
||||
f"(STATIC_ASSET_BASE={static_base})"
|
||||
)
|
||||
return
|
||||
problems: list[str] = []
|
||||
for sub, required in INTEGRITY_DIRS.items():
|
||||
d = dist / sub
|
||||
@@ -191,7 +216,7 @@ def check_integrity(dist: Path) -> None:
|
||||
if hard:
|
||||
raise SystemExit(
|
||||
f"aborting deploy: required asset dirs empty: {hard}. "
|
||||
"Run the fetch scripts first so the exported site is complete."
|
||||
"Run the fetch scripts first, or set STATIC_ASSET_BASE for OSS hosting."
|
||||
)
|
||||
|
||||
|
||||
@@ -322,6 +347,12 @@ def main() -> None:
|
||||
help="passed to export as --ability-video-base (default: OSS climperor endpoint "
|
||||
"or ABILITY_VIDEO_BASE env)",
|
||||
)
|
||||
ap.add_argument(
|
||||
"--static-asset-base",
|
||||
default=None,
|
||||
help="passed to export as --static-asset-base (default: same as ability-video-base "
|
||||
"or STATIC_ASSET_BASE env)",
|
||||
)
|
||||
args = ap.parse_args()
|
||||
|
||||
dist = Path(args.dist).resolve()
|
||||
@@ -333,7 +364,7 @@ def main() -> None:
|
||||
ensure_project(email, api_key, account_id, args.project_name)
|
||||
|
||||
if not args.no_export:
|
||||
run_export(args.ability_video_base)
|
||||
run_export(args.ability_video_base, args.static_asset_base)
|
||||
else:
|
||||
print("--no-export: using existing dist")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user