| 75 | } |
| 76 | |
| 77 | function readOptions() { |
| 78 | return commander |
| 79 | .requiredOption('-d, --dir <directory>', 'input root directory (required)') |
| 80 | .option('-b, --baseURL <URL>', 'base URL') |
| 81 | .option( |
| 82 | '-f, --formatVersion <formatVersion>', |
| 83 | 'webbundle format version, possible values are ' + |
| 84 | APPROVED_VERSIONS.map((v) => `"${v}"`).join(' and ') + |
| 85 | ' (default: "' + |
| 86 | DEFAULT_VERSION + |
| 87 | '")', |
| 88 | DEFAULT_VERSION |
| 89 | ) |
| 90 | .option( |
| 91 | '-p, --primaryURL <URL>', |
| 92 | 'primary URL (defaults to base URL, only valid with format version "' + |
| 93 | B1 + |
| 94 | '")' |
| 95 | ) |
| 96 | .option( |
| 97 | '-m, --manifestURL <URL>', |
| 98 | 'manifest URL (only valid with format version "' + B1 + '")' |
| 99 | ) |
| 100 | .option('-o, --output <file>', 'webbundle output file', 'out.wbn') |
| 101 | .option( |
| 102 | '-h, --headerOverride <jsonFilePath>', |
| 103 | 'path to a JSON file specifying the headers as an object of strings' |
| 104 | ) |
| 105 | .parse(process.argv); |
| 106 | } |
| 107 | |
| 108 | function validateOptions(options: any): string | null { |
| 109 | if (options.baseURL && !options.baseURL.endsWith('/')) { |