All files index.ts

100% Statements 20/20
100% Branches 3/3
100% Functions 3/3
100% Lines 20/20

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    2x 2x               2x   32x   32x   32x   32x               40x 40x 40x   40x         2x   2x         2x       2x 2x 2x   2x 2x     2x
 
 
import { Command } from 'commander';
import chalk from 'chalk';
 
/**
 * CLI tool to migrate React applications to newer versions (17, 18, 19).
 *
 * @remarks
 * This tool analyzes your React project, updates dependencies, transforms code, and provides a migration report.
 */
export class ReactMigrationTool {
  /** The target React version for migration. */
  targetVersion: string = '18';
  /** The root directory of the project being migrated. */
  projectRoot: string = process.cwd();
  /** List of issues found during migration. */
  issues: string[] = [];
  /** List of fixes applied during migration. */
  fixes: string[] = [];
 
  /**
   * Starts the migration process.
   * @param targetVersion The React version to migrate to.
   * @param projectPath The path to the React project.
   */
  async migrate(targetVersion: string, projectPath?: string): Promise<void> {
    this.targetVersion = targetVersion;
    this.projectRoot = projectPath !== undefined ? projectPath : process.cwd();
    console.log(chalk.blue(`🚀 Starting React ${targetVersion} migration...`));
    // ...implementation to be filled in
    console.log(chalk.green('✅ Migration completed (stub).'));
  }
}
 
// CLI Setup
const program = new Command();
 
program
  .name('react-migrate')
  .description('CLI tool to migrate React applications to newer versions')
  .version('1.0.0');
 
program
  .argument('[target-version]', 'Target React version (17, 18, 19)', '18')
  .argument('[project-path]', 'Path to React project', process.cwd())
  .action(async (targetVersion: string, projectPath: string) => {
    if (!['17', '18', '19'].includes(targetVersion)) {
      console.error(chalk.red('❌ Unsupported target version. Use 17, 18, or 19'));
      process.exit(1);
    }
    const migrator = new ReactMigrationTool();
    await migrator.migrate(targetVersion, projectPath);
  });
 
program.parse();