mirror of
https://github.com/gittrahan/support-fins.git
synced 2026-10-21 11:23:02 -05:00
Orca's engine glue wasn't Orca-specific. Move it where the Fusion add-in (and any later JS-running plugin) can use it too: - plugins/orca/panel/fins_entry.js -> plugins/shared/engine/fins_entry.js - plugins/orca/panel/engine_bridge.js -> plugins/shared/engine/bridge.js - the esbuild step in orca/build.py -> plugins/shared/bundle.py (bundle_engine) - bridge/entry tests, sensitivity repro and ENGINE-SENSITIVITY.md move with them No behaviour change: the built Orca plugin and its engine bundle are byte-identical to main's. The Python V8 loader stays in Orca for now; it moves to shared when Fusion needs it.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Bundle the printfins.com engine for the plugins.
|
|
|
|
python3 plugins/shared/bundle.py OUT.js # -> one minified IIFE, global SupportFinsEngine
|
|
|
|
Bundles engine/bridge.js (which imports web/*.js, untouched) into one IIFE with
|
|
esbuild. Each plugin's own build calls bundle_engine() and packages the result
|
|
its own way (Orca inlines it into a single .py).
|
|
|
|
Needs esbuild: `npx esbuild` (fetched on demand) or ESBUILD=/path/to/esbuild.
|
|
"""
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
HERE = pathlib.Path(__file__).resolve().parent
|
|
BRIDGE = HERE / "engine" / "bridge.js"
|
|
GLOBAL_NAME = "SupportFinsEngine"
|
|
|
|
|
|
def esbuild_cmd():
|
|
if os.environ.get("ESBUILD"):
|
|
return [os.environ["ESBUILD"]]
|
|
if shutil.which("esbuild"):
|
|
return ["esbuild"]
|
|
# shutil.which finds npx.cmd on Windows, where a bare "npx" isn't executable
|
|
return [shutil.which("npx") or "npx", "--yes", "esbuild@0.28"]
|
|
|
|
|
|
def bundle_engine(outfile):
|
|
"""Write the engine bundle to `outfile` and return its source."""
|
|
outfile = pathlib.Path(outfile)
|
|
outfile.parent.mkdir(parents=True, exist_ok=True)
|
|
subprocess.run(esbuild_cmd() + [
|
|
str(BRIDGE), "--bundle", "--format=iife",
|
|
f"--global-name={GLOBAL_NAME}", "--target=es2022", "--minify",
|
|
f"--outfile={outfile}", "--log-level=warning",
|
|
], check=True)
|
|
return outfile.read_text(encoding="utf-8")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
sys.exit(__doc__)
|
|
js = bundle_engine(sys.argv[1])
|
|
print(f"bundled {sys.argv[1]} ({len(js) / 1024:.0f} KB)")
|