| 229 | } |
| 230 | |
| 231 | export function createXcodebuildPipeline(options: PipelineOptions): XcodebuildPipeline { |
| 232 | if (!options.emit) { |
| 233 | throw new Error('Pipeline requires an emit callback. Pass emit explicitly.'); |
| 234 | } |
| 235 | const kind: BuildLikeKind = |
| 236 | options.kind ?? (options.operation === 'TEST' ? 'test-result' : 'build-result'); |
| 237 | const logCapture = createLogCapture(options.toolName); |
| 238 | const debugCapture = createParserDebugCapture(options.toolName); |
| 239 | const emit = options.emit; |
| 240 | |
| 241 | const runState = createXcodebuildRunState({ |
| 242 | operation: options.operation, |
| 243 | minimumStage: options.minimumStage, |
| 244 | onEvent: emit, |
| 245 | }); |
| 246 | |
| 247 | const parser = createXcodebuildEventParser({ |
| 248 | operation: options.operation, |
| 249 | kind, |
| 250 | onEvent: (fragment) => { |
| 251 | if (isRunStateFragment(fragment)) { |
| 252 | runState.push(fragment); |
| 253 | } else { |
| 254 | emit(fragment); |
| 255 | } |
| 256 | }, |
| 257 | onUnrecognizedLine: (line: string) => { |
| 258 | debugCapture.addUnrecognizedLine(line); |
| 259 | }, |
| 260 | }); |
| 261 | |
| 262 | return { |
| 263 | onStdout(chunk: string): void { |
| 264 | logCapture.write(chunk); |
| 265 | parser.onStdout(chunk); |
| 266 | }, |
| 267 | |
| 268 | onStderr(chunk: string): void { |
| 269 | logCapture.write(chunk); |
| 270 | parser.onStderr(chunk); |
| 271 | }, |
| 272 | |
| 273 | emitFragment(fragment: DomainFragment): void { |
| 274 | if (isRunStateFragment(fragment)) { |
| 275 | runState.push(fragment); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | emit(fragment); |
| 280 | }, |
| 281 | |
| 282 | finalize( |
| 283 | succeeded: boolean, |
| 284 | durationMs?: number, |
| 285 | _finalizeOptions?: PipelineFinalizeOptions, |
| 286 | ): PipelineResult { |
| 287 | parser.flush(); |
| 288 | logCapture.close(); |