load static method
Loads the project from the pubspec.yaml in root (the current
directory by default).
Throws a LiveCommandException when there is no readable pubspec.
Implementation
static LiveProject load([String? root]) {
final String directory = root ?? Directory.current.path;
final File pubspec = File('$directory/pubspec.yaml');
if (!pubspec.existsSync()) {
throw LiveCommandException(
'No pubspec.yaml in $directory. Run metro from your Flutter project '
'root.',
);
}
try {
final Object? yaml = loadYaml(pubspec.readAsStringSync());
final Object? name = yaml is YamlMap ? yaml['name'] : null;
if (name is String && name.isNotEmpty) {
return LiveProject(directory, name);
}
} catch (_) {
// Fall through to the error below.
}
throw LiveCommandException(
'Couldn\'t read the package name from ${pubspec.path}.',
);
}