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 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame] | 8 | |
Philipp Schrader | 45721a7 | 2022-04-02 16:27:53 -0700 | [diff] [blame] | 9 | def compute_sha256(filepath): |
| 10 | return hashlib.sha256(filepath.read_bytes()).hexdigest() |
| 11 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame] | 12 | |
Philipp Schrader | 45721a7 | 2022-04-02 16:27:53 -0700 | [diff] [blame] | 13 | def main(argv): |
| 14 | parser = argparse.ArgumentParser() |
| 15 | parser.add_argument("--template", type=str) |
| 16 | parser.add_argument("--bundle", type=str) |
| 17 | parser.add_argument("--output", type=str) |
| 18 | args = parser.parse_args(argv[1:]) |
| 19 | |
| 20 | template = Path(args.template).read_text() |
| 21 | bundle_path = Path(args.bundle) |
| 22 | bundle_sha256 = compute_sha256(bundle_path) |
| 23 | |
| 24 | output = template.format( |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame] | 25 | MAIN_BUNDLE_FILE=f"/sha256/{bundle_sha256}/{bundle_path.name}", ) |
Philipp Schrader | 45721a7 | 2022-04-02 16:27:53 -0700 | [diff] [blame] | 26 | Path(args.output).write_text(output) |
| 27 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame] | 28 | |
Philipp Schrader | 45721a7 | 2022-04-02 16:27:53 -0700 | [diff] [blame] | 29 | if __name__ == "__main__": |
| 30 | sys.exit(main(sys.argv)) |