Philipp Schrader | 45721a7 | 2022-04-02 16:27:53 -0700 | [diff] [blame] | 1 | """Generates index.html with the right checksum for main_bundle_file.js filled in.""" |
| 2 | |
| 3 | import argparse |
| 4 | import hashlib |
| 5 | import sys |
| 6 | from pathlib import Path |
| 7 | |
| 8 | def compute_sha256(filepath): |
| 9 | return hashlib.sha256(filepath.read_bytes()).hexdigest() |
| 10 | |
| 11 | def main(argv): |
| 12 | parser = argparse.ArgumentParser() |
| 13 | parser.add_argument("--template", type=str) |
| 14 | parser.add_argument("--bundle", type=str) |
| 15 | parser.add_argument("--output", type=str) |
| 16 | args = parser.parse_args(argv[1:]) |
| 17 | |
| 18 | template = Path(args.template).read_text() |
| 19 | bundle_path = Path(args.bundle) |
| 20 | bundle_sha256 = compute_sha256(bundle_path) |
| 21 | |
| 22 | output = template.format( |
| 23 | MAIN_BUNDLE_FILE = f"/sha256/{bundle_sha256}/{bundle_path.name}", |
| 24 | ) |
| 25 | Path(args.output).write_text(output) |
| 26 | |
| 27 | if __name__ == "__main__": |
| 28 | sys.exit(main(sys.argv)) |