|
| 1 | +#!/usr/bin/env node |
| 2 | +import {fileURLToPath} from 'node:url'; |
| 3 | +import path from 'node:path'; |
| 4 | +import {isPodmanAvailable, removeTempDir, runLambdaContainer} from './utils/lambda.js'; |
| 5 | + |
| 6 | +const parseArgs = argv => { |
| 7 | + const args = {}; |
| 8 | + |
| 9 | + for (let index = 0; index < argv.length; index += 1) { |
| 10 | + const value = argv[index]; |
| 11 | + |
| 12 | + if (value === '--image-tag') { |
| 13 | + args.imageTag = argv[index + 1]; |
| 14 | + index += 1; |
| 15 | + continue; |
| 16 | + } |
| 17 | + |
| 18 | + if (value === '--base-image') { |
| 19 | + args.baseImage = argv[index + 1]; |
| 20 | + index += 1; |
| 21 | + continue; |
| 22 | + } |
| 23 | + |
| 24 | + if (value === '--bundle') { |
| 25 | + args.bundlePath = argv[index + 1]; |
| 26 | + index += 1; |
| 27 | + continue; |
| 28 | + } |
| 29 | + |
| 30 | + if (value === '--fixtures') { |
| 31 | + args.documentsDir = argv[index + 1]; |
| 32 | + index += 1; |
| 33 | + continue; |
| 34 | + } |
| 35 | + |
| 36 | + if (value === '--port') { |
| 37 | + args.port = Number(argv[index + 1]); |
| 38 | + index += 1; |
| 39 | + continue; |
| 40 | + } |
| 41 | + |
| 42 | + if (value === '--cleanup') { |
| 43 | + args.cleanup = true; |
| 44 | + continue; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return args; |
| 49 | +}; |
| 50 | + |
| 51 | +const main = async () => { |
| 52 | + const args = parseArgs(process.argv.slice(2)); |
| 53 | + |
| 54 | + if (!(await isPodmanAvailable())) { |
| 55 | + console.error('podman is not available. Install it to run the Lambda integration harness.'); |
| 56 | + process.exitCode = 1; |
| 57 | + |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + let cleanupDir; |
| 62 | + |
| 63 | + try { |
| 64 | + const result = await runLambdaContainer(args); |
| 65 | + cleanupDir = result.outputDir; |
| 66 | + |
| 67 | + console.log('Lambda invocation response:', result.response); |
| 68 | + |
| 69 | + if (result.results) { |
| 70 | + console.log('Conversion results parsed from logs:', result.results); |
| 71 | + } else { |
| 72 | + console.log('Raw container logs:\n', result.logs); |
| 73 | + } |
| 74 | + |
| 75 | + console.log('Generated files:', result.outputFiles); |
| 76 | + console.log(`Output directory: ${result.outputDir}`); |
| 77 | + } catch (error) { |
| 78 | + console.error(error instanceof Error ? error.message : error); |
| 79 | + process.exitCode = 1; |
| 80 | + } finally { |
| 81 | + if (args.cleanup && cleanupDir) { |
| 82 | + await removeTempDir(cleanupDir); |
| 83 | + } |
| 84 | + } |
| 85 | +}; |
| 86 | + |
| 87 | +const executedFile = fileURLToPath(import.meta.url); |
| 88 | + |
| 89 | +if (process.argv[1] && path.resolve(process.argv[1]) === executedFile) { |
| 90 | + await main(); |
| 91 | +} |
0 commit comments