({
positionals,
flags,
}: ReplayCommandParams)
| 30 | } |
| 31 | |
| 32 | async function handleReplayExportCommand({ |
| 33 | positionals, |
| 34 | flags, |
| 35 | }: ReplayCommandParams): Promise<true> { |
| 36 | validateReplayExportOptions(positionals, flags); |
| 37 | const inputPath = positionals[1]; |
| 38 | if (!inputPath) { |
| 39 | throw new AppError('INVALID_ARGS', 'replay export requires an input path.'); |
| 40 | } |
| 41 | |
| 42 | const sourcePath = resolveUserPath(inputPath); |
| 43 | const script = fs.readFileSync(sourcePath, 'utf8'); |
| 44 | const result = exportReplayScriptToMaestro(script); |
| 45 | const outputPath = typeof flags.out === 'string' ? resolveUserPath(flags.out) : undefined; |
| 46 | if (outputPath) { |
| 47 | fs.mkdirSync(path.dirname(outputPath), { recursive: true }); |
| 48 | fs.writeFileSync(outputPath, result.yaml); |
| 49 | } |
| 50 | for (const warning of result.warnings) { |
| 51 | process.stderr.write(`Warning: line ${warning.line}: ${warning.message}\n`); |
| 52 | } |
| 53 | |
| 54 | writeCommandOutput( |
| 55 | flags, |
| 56 | { |
| 57 | format: flags.replayExportFormat ?? 'maestro', |
| 58 | sourcePath, |
| 59 | ...(outputPath ? { path: outputPath } : { yaml: result.yaml }), |
| 60 | warnings: result.warnings, |
| 61 | }, |
| 62 | () => outputPath ?? result.yaml, |
| 63 | ); |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | function validateReplayExportOptions( |
| 68 | positionals: ReplayCommandParams['positionals'], |
no test coverage detected