installToPackage function

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

Implementation

Future<void> installToPackage({
  required String name,
  required Version version,
}) async {
  Map<String, dynamic> package =
      json.decode(await File("package.json").readAsString());

  package["devDependencies"]?.removeWhere((k, v) => k == name);
  package["dependencies"][name] = version.toString();

  await File("package.json")
      .writeAsString(JsonEncoder.withIndent("  ").convert(package));
}