All files / src/cli/commands validate.ts

0% Statements 0/38
0% Branches 0/10
0% Functions 0/3
0% Lines 0/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                                                                                                                             
import chalk from 'chalk';
import { existsSync } from 'fs';
import { ConfigManager } from '@/core/config-manager';
 
/**
 * Validation options
 */
export interface ValidateOptions {
  config?: string;
}
 
/**
 * Validate scraper configuration
 */
export async function validateConfig(options: ValidateOptions): Promise<void> {
  console.log(chalk.blue('🔍 Validating Configuration'));
  console.log();
 
  const configPath = options.config || './scraper.config.yaml';
 
  Iif (!existsSync(configPath)) {
    console.error(chalk.red(`Configuration file not found: ${configPath}`));
    process.exit(1);
  }
 
  try {
    const configManager = new ConfigManager();
    configManager.loadFromFile(configPath);
    
    const validation = configManager.validateConfig();
    
    if (validation.valid) {
      console.log(chalk.green('✅ Configuration is valid'));
      
      // Show configuration summary
      const config = configManager.getConfig();
      console.log();
      console.log(chalk.yellow('Configuration Summary:'));
      console.log(`  Browser Pool Size: ${config.browserPool.maxSize}`);
      console.log(`  Default Retries: ${config.defaultOptions.retries}`);
      console.log(`  Default Timeout: ${config.defaultOptions.timeout}ms`);
      console.log(`  Logging Level: ${config.logging.level}`);
      console.log(`  Plugins: ${config.plugins.length}`);
      
      // Show profiles if any
      const profiles = configManager.getProfiles();
      Iif (profiles.length > 0) {
        console.log();
        console.log(chalk.yellow('Available Profiles:'));
        profiles.forEach(profile => {
          console.log(`  - ${profile.name}: ${profile.description || 'No description'}`);
        });
      }
      
    } else {
      console.log(chalk.red('❌ Configuration validation failed'));
      console.log();
      validation.errors.forEach(error => {
        console.log(chalk.red(`  • ${error}`));
      });
      process.exit(1);
    }
    
  } catch (error) {
    console.error(chalk.red('Failed to validate configuration:'));
    console.error(chalk.red(error instanceof Error ? error.message : String(error)));
    process.exit(1);
  }
}