cloneProject static method

Future<void> cloneProject()

Implementation

static Future<void> cloneProject() async {
  // Step 1: Ask project name
  final projectName = await AppUtils.readLine(
    "project name (snake_case e.g. my_app)",
  );
  if (projectName.trim().isEmpty) {
    stdout.writeln("Project name is required");
    return;
  }

  // Step 2: Ask package name
  stdout.write("Enter package name (e.g. com.company.myapp): ");
  final packageName = stdin.readLineSync()?.trim() ?? '';
  if (packageName.trim().isEmpty) {
    stdout.writeln("Package name is required");
    return;
  }

  // Step 3: Clone
  stdout.writeln("⏳ Cloning template...");
  final command = await Process.run("git", [
    "clone",
    "https://github.com/dev-siddhartha/Flutter-templete-project.git",
    projectName,
  ]);

  if (command.exitCode != 0) {
    stdout.writeln(command.stderr);
    return;
  }

  // Step 4: Remove .git
  _removeGitFolder(projectName);

  // Step 5: Replace all occurrences inside file contents
  stdout.writeln("⚙️  Configuring project...");
  await _replaceInAllFiles(projectName, projectName, packageName);

  stdout.writeln("✅ Project '$projectName' created successfully!");
  stdout.writeln("👉 Run: cd $projectName && flutter pub get");
}