All files cli.ts

60.6% Statements 20/33
56.25% Branches 9/16
100% Functions 1/1
60.6% Lines 20/33

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 72 73 74 75 76 77 78 79 80 81 82 83 84                1x       2x 2x 2x           2x   2x   1x 1x 1x     1x 1x 1x 1x 1x   1x             1x                       1x                             1x 1x                   1x      
#!/usr/bin/env node
import { Command } from 'commander';
import chalk from 'chalk';
import * as path from 'path';
import * as fs from 'fs';
import { analyzeChangeAmplification } from './analyzer';
import type { ChangeAmplificationOptions } from './types';
 
export const changeAmplificationAction = async (
  directory: string,
  options: any
) => {
  try {
    const resolvedDir = path.resolve(process.cwd(), directory);
    const finalOptions: ChangeAmplificationOptions = {
      rootDir: resolvedDir,
      include: options.include ? options.include.split(',') : undefined,
      exclude: options.exclude ? options.exclude.split(',') : undefined,
    };
 
    const report = await analyzeChangeAmplification(finalOptions);
 
    if (options.output === 'json') {
      const outputPath =
        options.outputFile || `change-amplification-report-${Date.now()}.json`;
      fs.writeFileSync(outputPath, JSON.stringify(report, null, 2));
      return;
    }
 
    console.log(chalk.bold('\n🌐 Change Amplification Analysis\n'));
    console.log(`Rating: ${chalk.bold(report.summary.rating)}`);
    console.log(`Score: ${Math.round(report.summary.score)}/100`);
    console.log(`Critical Issues: ${report.summary.criticalIssues}`);
    console.log(`Major Issues: ${report.summary.majorIssues}`);
 
    Iif (report.summary.recommendations.length > 0) {
      console.log(chalk.bold('\nRecommendations:'));
      for (const rec of report.summary.recommendations) {
        console.log(chalk.cyan(`• ${rec}`));
      }
    }
 
    Iif (report.results.length > 0) {
      console.log(chalk.bold('\nHotspots:'));
      for (const result of report.results) {
        console.log(`\n📄 ${chalk.cyan(result.fileName)}`);
        for (const issue of result.issues) {
          const color =
            issue.severity === 'critical' ? chalk.red : chalk.yellow;
          console.log(`  ${color('■')} ${issue.message}`);
          console.log(`    ${chalk.dim('Suggestion: ' + issue.suggestion)}`);
        }
      }
    } else {
      console.log(
        chalk.green(
          '\n✨ No change amplification issues found. Architecture is well contained.'
        )
      );
    }
  } catch (error) {
    console.error(
      chalk.red('Error during change amplification analysis:'),
      error
    );
    process.exit(1);
  }
};
 
const program = new Command();
program
  .name('aiready-change-amplification')
  .description('Analyze graph metrics for change amplification')
  .argument('[directory]', 'Directory to analyze', '.')
  .option('--include <patterns>', 'File patterns to include (comma-separated)')
  .option('--exclude <patterns>', 'File patterns to exclude (comma-separated)')
  .option('-o, --output <format>', 'Output format: console, json', 'console')
  .option('--output-file <path>', 'Output file path (for json)')
  .action(changeAmplificationAction);
 
Iif (require.main === module) {
  program.parse();
}