UNPKG

@thecodingwhale/cv-processor

Version:

CV Processor to extract structured data from PDF resumes using TypeScript

111 lines (110 loc) 4.79 kB
#!/usr/bin/env node "use strict"; /** * Optimized CV Processor CLI * Usage: npx cv-processor-ts input.pdf * Output: Creates output JSON file with extracted CV data */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const dotenv = __importStar(require("dotenv")); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const AICVProcessorX_1 = require("./AICVProcessorX"); const AIProviderFactory_1 = require("./ai/AIProviderFactory"); // Load environment variables dotenv.config(); // CLI config const program = new commander_1.Command(); program .name('cv-processor-ts') .description('Extract structured data from CV/resume PDF') .version('2.0.0') .argument('<pdf-file>', 'Path to the CV/resume PDF file') .option('-o, --output <file>', 'Output JSON file (defaults to output directory)') .option('-v, --verbose', 'Verbose output') .option('--use-ai [provider]', 'AI provider (openai, azure, gemini, etc.)', 'openai') .option('--ai-model <model>', 'AI model to use') .action(async (pdfFile, options) => { try { if (!fs.existsSync(pdfFile)) { console.error(`❌ Error: Input file not found: ${pdfFile}`); process.exit(1); } const outputDir = path.resolve(__dirname, '../output'); if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir); const outputFile = options.output || `${path.basename(pdfFile, path.extname(pdfFile))}.json`; const outputPath = path.join(outputDir, outputFile); // const providerType = options.useAi as AIProviderType // console.log(`🧠 Using AI provider: ${providerType}`) // Use the default provider (based on CLI args or environment vars) const defaultProvider = process.env.DEFAULT_AI_PROVIDER || 'gemini'; let apiProviderType = defaultProvider; // Get API key from environment variables const apiKeyEnvVar = apiProviderType === 'aws' ? 'AWS_ACCESS_KEY_ID' : `${apiProviderType.toUpperCase()}_API_KEY`; const apiKey = process.env[apiKeyEnvVar]; if (!apiKey) { console.error(`Error: API key not found in environment variables (${apiKeyEnvVar})`); console.error('Please set it in your .env file or environment'); throw new Error(`Missing API key for provider: ${apiProviderType}`); } // Configure AI provider let aiConfig = { apiKey, model: 'gemini', }; const aiProvider = AIProviderFactory_1.AIProviderFactory.createProvider(apiProviderType, aiConfig); // const aiProvider = AIProviderFactory.createProvider('gemini', { // model: options.aiModel, // }) const processor = new AICVProcessorX_1.AICVProcessorX(aiProvider, options.verbose); const start = Date.now(); const cvData = await processor.processCv(pdfFile); const duration = (Date.now() - start) / 1000; console.log(`✅ Processing completed in ${duration.toFixed(2)} seconds`); fs.writeFileSync(outputPath, JSON.stringify(cvData, null, 2)); console.log(`💾 Saved output to ${outputPath}`); } catch (err) { console.error(`❌ Failed to process CV: ${err.message}`); process.exit(1); } }); program.parse(process.argv);