getProjectName method
Returns the name field from the target project's pubspec.yaml.
Falls back to the directory name when parsing fails.
Implementation
Future<String> getProjectName({required String workingDirectory}) async {
try {
final content = await File('$workingDirectory/pubspec.yaml').readAsString();
final doc = loadYaml(content) as YamlMap;
final projectName = doc['name'] as String;
return projectName;
} catch (e) {
CommandHelper().error('Could not get project name: $e');
return workingDirectory.split(Platform.pathSeparator).last;
}
}