copyFromGit function

void copyFromGit(
  1. Directory projectDir
)

Implementation

void copyFromGit(Directory projectDir) {
  print(projectDir.path);
  // Define the GitHub repository URL
  String repoUrl = 'https://github.com/Yoeri-z/EasyServer.git';
  Directory clonedRepoDir =
      Directory('${Directory.systemTemp.path}/easyTempStore');
  if (clonedRepoDir.existsSync()) {
    clonedRepoDir.deleteSync(recursive: true);
  }
  clonedRepoDir.createSync();
  // Clone the GitHub repository
  ProcessResult cloneResult =
      Process.runSync('git', ['clone', repoUrl, clonedRepoDir.path]);

  if (cloneResult.exitCode == 0) {
    // Define the folders to copy
    List<String> foldersToCopy = ['${clonedRepoDir.path}/templates/'];

    // Copy the specified folders to the current directory
    for (String folder in foldersToCopy) {
      ProcessResult copyResult = Process.runSync(
          'xcopy',
          [
            folder.replaceAll('/', '\\'),
            projectDir.path.replaceAll('/', '\\'),
            '/E',
            '/H',
          ],
          runInShell: true);

      if (copyResult.exitCode != 0) {
        print(
            'Failed to copy folder "$folder".\nExitcode:${copyResult.exitCode}');
        print('Error message:');
        print(copyResult.stderr);
      }
    }
    clonedRepoDir.delete(recursive: true);
  } else {
    print(
        'Failed to clone the repository. Check the repository URL and try again.\n Exitcode: ${cloneResult.exitCode}');
    print('Error message:');
    print(cloneResult.stderr);
  }
}