generateCICDFiles function

void generateCICDFiles({
  1. required String projectName,
  2. required String ciCdChoice,
})

Implementation

void generateCICDFiles({
  required String projectName,
  required String ciCdChoice,
}) {
  final projectDir = getProjectDir(projectName);

  if (!projectDir.existsSync()) {
    print('❌ Project "$projectName" does not exist.');
    return;
  }

  String exampleCiCdContent = '';
  String destinationPath = '';

  switch (ciCdChoice) {
    case '1':
    case 'github':
      exampleCiCdContent = githubExample;
      destinationPath = '.github/workflows/main.yml';
      break;

    case '2':
    case 'gitlab':
      exampleCiCdContent = gitlabExample;
      destinationPath = '.gitlab-ci.yml';
      break;

    case '3':
    case 'custom':
      exampleCiCdContent = _generateCustomScript();
      destinationPath = 'ci/build.sh';
      break;

    default:
      print('⚠️  Unknown CI/CD choice: $ciCdChoice');
      return;
  }

  final fullDestinationPath = '${projectDir.path}/$destinationPath';
  final file = File(fullDestinationPath);

  // Create directories if needed
  file.createSync(recursive: true);
  file.writeAsStringSync(exampleCiCdContent);

  // Make shell scripts executable
  if (destinationPath.endsWith('.sh')) {
    Process.runSync('chmod', ['+x', fullDestinationPath]);
  }

  print('✅ CI/CD configuration created: $destinationPath');
}