installToPubspec function

Future<void> installToPubspec({
  1. required String name,
  2. required Version version,
})

Implementation

Future<void> installToPubspec({
  required String name,
  required Version version,
}) async {
  print("installToPubspec");
  final pubspec =
      getModifiableNode(loadYaml(await File("pubspec.yaml").readAsString()));

  print("Modifying \"$name\" in pubspec.yaml");

  if (!RegExp("waveform").hasMatch(name)) {
    pubspec["dependencies"]
        [name.split("/").elementAt(1).replaceAll("-", "_")] = {
      "git": {
        "url": "https://github.com/${name.replaceAll("@", "")}.git",
        "ref": version.toString(),
      }
    };
  } else {
    pubspec["dependencies"]["waveform"] = version.toString();
  }

  await File("pubspec.yaml").writeAsString(
      toYamlString(pubspec).replaceAll("sdk: \"flutter\"", "sdk: flutter"));
}