| 1 | #!/usr/bin/env python3 |
| 2 | import argparse |
| 3 | import json |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | |
| 7 | |
| 8 | def build(repo, destination, manifest): |
| 9 | spec = json.loads(manifest.read_text()) |
| 10 | source = (repo / "dashboard/agent" / spec["source"]).resolve(strict=True) |
| 11 | entry = (source / spec["entry"]).resolve(strict=True) |
| 12 | if not source.is_relative_to(repo.parent) or not entry.is_relative_to(source): |
| 13 | raise ValueError("agent source must stay inside the workspace") |
| 14 | destination.parent.mkdir(parents=True, exist_ok=True) |
| 15 | subprocess.run([ |
| 16 | str(repo / "dashboard/node_modules/.bin/esbuild"), str(entry), |
| 17 | "--bundle", "--platform=node", "--format=esm", "--target=node24", |
| 18 | "--external:bufferutil", "--external:utf-8-validate", |
| 19 | "--banner:js=import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);", |
| 20 | "--outfile=" + str(destination), |
| 21 | ], check=True) |
| 22 | |
| 23 | |
| 24 | if __name__ == "__main__": |
| 25 | parser = argparse.ArgumentParser() |
| 26 | parser.add_argument("--output", type=Path) |
| 27 | args = parser.parse_args() |
| 28 | repo = Path(__file__).resolve().parent.parent |
| 29 | build(repo, args.output or repo / "dashboard/agent/relay.mjs", repo / "dashboard/agent/source.json") |