All files / src/report interactive-setup.ts

0% Statements 0/30
0% Branches 0/33
0% Functions 0/4
0% Lines 0/30

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 85 86 87 88 89 90 91 92 93 94 95 96 97                                                                                                                                                                                                 
import chalk from 'chalk';
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import prompts from 'prompts';
 
/**
 * Interactive setup: detect common frameworks and suggest excludes & focus areas
 */
export async function runInteractiveSetup(
  directory: string,
  current: any
): Promise<any> {
  console.log(chalk.yellow("🧭 Interactive mode: let's tailor the analysis."));
 
  const pkgPath = join(directory, 'package.json');
  let deps: Record<string, string> = {};
  if (existsSync(pkgPath)) {
    try {
      const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
      deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
    } catch (e) {
      void e;
      // Ignore parse errors, use empty deps
    }
  }
 
  const hasNextJs = existsSync(join(directory, '.next')) || !!deps['next'];
  const hasCDK =
    existsSync(join(directory, 'cdk.out')) ||
    !!deps['aws-cdk-lib'] ||
    Object.keys(deps).some((d) => d.startsWith('@aws-cdk/'));
 
  const recommendedExcludes = new Set<string>(current.exclude || []);
  if (
    hasNextJs &&
    !Array.from(recommendedExcludes).some((p) => p.includes('.next'))
  ) {
    recommendedExcludes.add('**/.next/**');
  }
  if (
    hasCDK &&
    !Array.from(recommendedExcludes).some((p) => p.includes('cdk.out'))
  ) {
    recommendedExcludes.add('**/cdk.out/**');
  }
 
  const { applyExcludes } = await prompts({
    type: 'toggle',
    name: 'applyExcludes',
    message: `Detected ${hasNextJs ? 'Next.js ' : ''}${hasCDK ? 'AWS CDK ' : ''}frameworks. Apply recommended excludes?`,
    initial: true,
    active: 'yes',
    inactive: 'no',
  });
 
  const nextOptions = { ...current };
  if (applyExcludes) {
    nextOptions.exclude = Array.from(recommendedExcludes);
  }
 
  const { focusArea } = await prompts({
    type: 'select',
    name: 'focusArea',
    message: 'Which areas to focus?',
    choices: [
      { title: 'Frontend (web app)', value: 'frontend' },
      { title: 'Backend (API/infra)', value: 'backend' },
      { title: 'Both', value: 'both' },
    ],
    initial: 2,
  });
 
  if (focusArea === 'frontend') {
    nextOptions.include = ['**/*.{ts,tsx,js,jsx}'];
    nextOptions.exclude = Array.from(
      new Set([
        ...(nextOptions.exclude || []),
        '**/cdk.out/**',
        '**/infra/**',
        '**/server/**',
        '**/backend/**',
      ])
    );
  } else if (focusArea === 'backend') {
    nextOptions.include = [
      '**/api/**',
      '**/server/**',
      '**/backend/**',
      '**/infra/**',
      '**/*.{ts,js,py,java}',
    ];
  }
 
  console.log(chalk.green('✓ Interactive configuration applied.'));
  return nextOptions;
}