fetchDependencies function

Future<void> fetchDependencies(
  1. String? projectName
)

Fetches the dependencies for the specified project.

The function checks if the pubspec.yaml and .env files exist in the specified projectName directory. If they do, it fetches the dependencies using getDependencies and writes them to a dependencies.txt file within the project directory.

Prints appropriate messages based on the outcome.

Implementation

Future<void> fetchDependencies(String? projectName) async {
  final File pubspecFile = File('$projectName/pubspec.yaml');
  final File envFile = File('$projectName/.env');

  if (!pubspecFile.existsSync() || !envFile.existsSync()) {
    print('This command must be run in the directory of an Oyda project.');
    return;
  }

  final List<String> dependencies = await getDependencies();
  if (dependencies.isNotEmpty) {
    final File dependenciesFile = File('$projectName/dependencies.txt');
    dependenciesFile.writeAsStringSync('dependencies:\n${dependencies.join('\n')}');
    print('Dependencies written to dependencies.txt');
  } else {
    print('No dependencies found.');
  }
}