UNPKG

veriqa

Version:

🎯 Smart Manual QA Test Advisor with AI-Powered Regression Suggestions and Advanced Git Integration

118 lines (99 loc) 3.33 kB
const fs = require('fs'); const path = require('path'); const chalk = require('chalk'); /** * SimplifiedEnvManager - Basic environment variable management * - Adds GEMINI_API_KEY to existing .env if present * - Creates new .env with template if not present * - No interactive prompts, just simple addition */ class SmartEnvManager { constructor(projectPath = process.cwd()) { this.projectPath = projectPath; this.envPath = path.join(projectPath, '.env'); } /** * Simple setup of Gemini API key placeholder */ async setupGeminiAPIKey() { try { if (fs.existsSync(this.envPath)) { // .env file exists - check if Gemini key already present return await this.handleExistingEnv(); } else { // No .env file - create new one return await this.createNewEnv(); } } catch (error) { console.log(chalk.red('❌ Environment setup failed:', error.message)); return { status: 'failed', updated: false }; } } /** * Handle existing .env file */ async handleExistingEnv() { const content = fs.readFileSync(this.envPath, 'utf8'); // Check if Gemini key already exists if (this.hasGeminiKey(content)) { console.log(chalk.green('✅ Gemini API key already configured in .env')); return { status: 'existing', updated: false }; } // Add Gemini key to existing file await this.appendGeminiKey(content); console.log(chalk.blue('✅ Added GEMINI_API_KEY to existing .env file')); return { status: 'appended', updated: true }; } /** * Create new .env file with Gemini key placeholder */ async createNewEnv() { const envContent = `# VeriQA Environment Configuration # Add your Gemini API key below to enable AI features GEMINI_API_KEY=your_gemini_api_key_here # Get your free API key from: https://ai.google.dev/ # Then replace 'your_gemini_api_key_here' with your actual key `; fs.writeFileSync(this.envPath, envContent, 'utf8'); console.log(chalk.green('✅ Created .env file with GEMINI_API_KEY placeholder')); return { status: 'created', updated: true }; } /** * Check if Gemini API key exists in content */ hasGeminiKey(content) { const geminiPatterns = [ /GEMINI_API_KEY\s*=/, /GOOGLE_AI_API_KEY\s*=/, /GOOGLE_GEMINI_KEY\s*=/ ]; return geminiPatterns.some(pattern => pattern.test(content)); } /** * Append Gemini key to existing .env content */ async appendGeminiKey(existingContent) { // Check if we need to add a newline const needsNewline = !existingContent.endsWith('\n'); const separator = needsNewline ? '\n' : ''; // Simple addition to existing file const geminiConfig = `${separator} # VeriQA AI Configuration GEMINI_API_KEY=your_gemini_api_key_here # Get your free API key from: https://ai.google.dev/ `; const updatedContent = existingContent + geminiConfig; fs.writeFileSync(this.envPath, updatedContent, 'utf8'); } /** * Check if environment is configured */ isConfigured() { if (!fs.existsSync(this.envPath)) { return false; } const content = fs.readFileSync(this.envPath, 'utf8'); return this.hasGeminiKey(content) && !content.includes('your_gemini_api_key_here'); } } module.exports = SmartEnvManager;