From d462aad5545bc0dc1ae31c933973925fdc85e980 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 2 Aug 2025 18:57:35 +0200 Subject: [PATCH] Add build script --- whiteprint.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 whiteprint.py diff --git a/whiteprint.py b/whiteprint.py new file mode 100644 index 0000000..1f7a10f --- /dev/null +++ b/whiteprint.py @@ -0,0 +1,66 @@ +import argparse +import shlex +import subprocess +from pathlib import Path + + +def run(*args): + argstrs = [str(arg) for arg in args] + print(f"$ {shlex.join(argstrs)}") + subprocess.run( + argstrs, + check=True, + ) + + +def run_with_output(*args): + argstrs = [str(arg) for arg in args] + print(f"$ {shlex.join(argstrs)}") + return subprocess.run( + argstrs, + check=True, + capture_output=True, + encoding="utf-8", + ).stdout + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("main", type=Path, nargs="?", default="main.typ") + args = parser.parse_args() + + # Produce PDF + print(f"Generating {args.main.with_suffix('.pdf')}") + run( + *("typst", "compile"), + *("--root", "."), + *("--features", "html"), + args.main, + ) + + # Produce HTML + print() + print(f"Generating {args.main.with_suffix('.html')}") + run( + *("typst", "compile"), + *("--root", "."), + *("--features", "html"), + *("--format", "html"), + args.main, + ) + + # Produce JSON + print() + print(f"Generating {args.main.with_suffix('.json')}") + json = run_with_output( + *("typst", "query"), + args.main, + "", + *("--field", "value"), + ) + with open(args.main.with_suffix(".json"), "w") as f: + f.write(json) + + +if __name__ == "__main__": + main()