()
| 141 | } |
| 142 | |
| 143 | export function main() { |
| 144 | const options = readOptions(); |
| 145 | const errorMsg = validateOptions(options); |
| 146 | if (errorMsg) { |
| 147 | console.error(errorMsg); |
| 148 | process.exit(1); |
| 149 | } |
| 150 | |
| 151 | const version: FormatVersion = |
| 152 | options.formatVersion === undefined |
| 153 | ? DEFAULT_VERSION |
| 154 | : options.formatVersion; |
| 155 | |
| 156 | const headerOverrides = |
| 157 | options.headerOverride === undefined |
| 158 | ? undefined |
| 159 | : readHeaderOverridesFile(options.headerOverride); |
| 160 | |
| 161 | if (headerOverrides !== undefined && !isHeaders(headerOverrides)) { |
| 162 | throw new Error( |
| 163 | 'Malformatted override headers: They should be an object of strings.' |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | const builder = new BundleBuilder(version); |
| 168 | |
| 169 | switch (version) { |
| 170 | case B1: |
| 171 | builder.setPrimaryURL(options.primaryURL || options.baseURL); |
| 172 | if (options.manifestURL) { |
| 173 | builder.setManifestURL(options.manifestURL); |
| 174 | } |
| 175 | break; |
| 176 | |
| 177 | case B2: |
| 178 | if (options.primaryURL) { |
| 179 | builder.setPrimaryURL(options.primaryURL); |
| 180 | } |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | addFilesRecursively( |
| 185 | builder, |
| 186 | options.baseURL || '', |
| 187 | options.dir, |
| 188 | headerOverrides |
| 189 | ); |
| 190 | fs.writeFileSync(options.output, builder.createBundle()); |
| 191 | } |
no test coverage detected