(args: Record<string, unknown>)
| 486 | |
| 487 | // fallow-ignore-next-line complexity |
| 488 | async function runRender(args: Record<string, unknown>): Promise<void> { |
| 489 | const projectDir = args.target as string | undefined; |
| 490 | if (!projectDir) { |
| 491 | console.error( |
| 492 | "[cloudrun render] usage: hyperframes cloudrun render <projectDir> --width <px> --height <px>", |
| 493 | ); |
| 494 | process.exit(1); |
| 495 | } |
| 496 | const width = parsePositiveInt(args.width, "--width"); |
| 497 | const height = parsePositiveInt(args.height, "--height"); |
| 498 | if (width === undefined || height === undefined) { |
| 499 | console.error("[cloudrun render] --width and --height are required."); |
| 500 | process.exit(1); |
| 501 | } |
| 502 | const fps = parseIntFlag(args.fps) ?? 30; |
| 503 | if (fps !== 24 && fps !== 30 && fps !== 60) { |
| 504 | console.error(`[cloudrun render] --fps must be 24, 30, or 60; got ${fps}.`); |
| 505 | process.exit(1); |
| 506 | } |
| 507 | const state = readState(args); |
| 508 | const variables = resolveAndValidateVariables(args, resolve(projectDir)); |
| 509 | const config = buildRenderConfig(args, fps, width, height, variables); |
| 510 | |
| 511 | const { renderToCloudRun, getRenderProgress } = await import("@hyperframes/gcp-cloud-run/sdk"); |
| 512 | const handle = await renderToCloudRun({ |
| 513 | projectDir: resolve(projectDir), |
| 514 | config: config as Parameters<typeof renderToCloudRun>[0]["config"], |
| 515 | bucketName: state.bucketName, |
| 516 | projectId: state.projectId, |
| 517 | location: state.region, |
| 518 | workflowId: state.workflowId, |
| 519 | serviceUrl: state.serviceUrl, |
| 520 | renderId: args["render-id"] as string | undefined, |
| 521 | outputKey: args["output-key"] as string | undefined, |
| 522 | } as Parameters<typeof renderToCloudRun>[0]); |
| 523 | |
| 524 | if (!args.wait) { |
| 525 | if (args.json) console.log(JSON.stringify(handle, null, 2)); |
| 526 | else { |
| 527 | console.log(`${c.accent("✓ render started")} renderId=${handle.renderId}`); |
| 528 | console.log(` output → ${handle.outputGcsUri}`); |
| 529 | console.log( |
| 530 | ` progress: ${c.accent(`hyperframes cloudrun progress ${handle.executionName}`)}`, |
| 531 | ); |
| 532 | } |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | const intervalMs = parsePositiveInt(args["wait-interval-ms"], "--wait-interval-ms") ?? 5000; |
| 537 | let progress = await getRenderProgress({ executionName: handle.executionName }); |
| 538 | while (progress.status === "running") { |
| 539 | await new Promise((r) => setTimeout(r, intervalMs)); |
| 540 | progress = await getRenderProgress({ executionName: handle.executionName }); |
| 541 | if (!args.json) process.stdout.write(`\r status=${progress.status} `); |
| 542 | } |
| 543 | if (!args.json) process.stdout.write("\n"); |
| 544 | if (args.json) { |
| 545 | console.log(JSON.stringify(progress, null, 2)); |
no test coverage detected