(options: PrepareBatchRenderOptions)
| 229 | } |
| 230 | |
| 231 | export function prepareBatchRender(options: PrepareBatchRenderOptions): PreparedBatchRender { |
| 232 | const batchPath = resolve(options.batchPath); |
| 233 | const read = options.readFile ?? ((path: string) => readFileSync(path, "utf8")); |
| 234 | let raw: string; |
| 235 | try { |
| 236 | raw = read(batchPath); |
| 237 | } catch (error: unknown) { |
| 238 | throw new BatchRenderInputError( |
| 239 | "Could not read --batch", |
| 240 | `${batchPath}: ${errorMessage(error)}`, |
| 241 | ); |
| 242 | } |
| 243 | |
| 244 | const variableRows = parseBatchRows(raw, batchPath); |
| 245 | const rows = variableRows.map((variables, index) => ({ |
| 246 | index, |
| 247 | variables, |
| 248 | outputPath: resolve(resolveOutputTemplate(options.outputTemplate, variables, index)), |
| 249 | })); |
| 250 | const manifestPath = join( |
| 251 | commonOutputDirectory(rows.map((row) => row.outputPath)), |
| 252 | "manifest.json", |
| 253 | ); |
| 254 | checkOutputCollisions(rows, manifestPath); |
| 255 | |
| 256 | const variableIssueCount = validateBatchVariables( |
| 257 | variableRows, |
| 258 | options.indexPath, |
| 259 | options.strictVariables, |
| 260 | options.quiet, |
| 261 | options.json, |
| 262 | ); |
| 263 | |
| 264 | return { |
| 265 | batchPath, |
| 266 | manifestPath, |
| 267 | variableIssueCount, |
| 268 | rows, |
| 269 | }; |
| 270 | } |
| 271 | |
| 272 | function makeInitialManifest(prepared: PreparedBatchRender): BatchManifest { |
| 273 | return { |
no test coverage detected