| 81 | }; |
| 82 | |
| 83 | function parseArgs(argv: string[]): BuildOptions { |
| 84 | const opts = { ...DEFAULT_OPTIONS }; |
| 85 | for (const arg of argv.slice(2)) { |
| 86 | if (arg.startsWith("--source=")) { |
| 87 | const v = arg.slice("--source=".length); |
| 88 | if (v !== "sparticuz" && v !== "chrome-headless-shell") { |
| 89 | throw new Error(`--source must be 'sparticuz' or 'chrome-headless-shell' (got ${v})`); |
| 90 | } |
| 91 | opts.source = v; |
| 92 | } else if (arg.startsWith("--max-unzipped=")) { |
| 93 | opts.maxUnzippedBytes = Number.parseInt(arg.slice("--max-unzipped=".length), 10); |
| 94 | } else if (arg.startsWith("--max-zipped=")) { |
| 95 | opts.maxZippedBytes = Number.parseInt(arg.slice("--max-zipped=".length), 10); |
| 96 | } else if (arg === "--help") { |
| 97 | console.log( |
| 98 | "Usage: tsx build-zip.ts [--source=sparticuz|chrome-headless-shell]\n" + |
| 99 | " [--max-unzipped=<bytes>] [--max-zipped=<bytes>]", |
| 100 | ); |
| 101 | process.exit(0); |
| 102 | } else { |
| 103 | throw new Error(`Unknown flag: ${arg}`); |
| 104 | } |
| 105 | } |
| 106 | return opts; |
| 107 | } |
| 108 | |
| 109 | async function main(): Promise<void> { |
| 110 | const opts = parseArgs(process.argv); |