writePubspecContent static method

void writePubspecContent(
  1. String newContent,
  2. dynamic newVersionName,
  3. dynamic newBuildNumber
)

Write a new content to the pubspec.yaml file

Implementation

static void writePubspecContent(
  String newContent,
  dynamic newVersionName,
  dynamic newBuildNumber,
) {
  final pubspecFilePath = p.join(Directory.current.path, 'pubspec.yaml');
  final pubspecFile = File(pubspecFilePath);

  try {
    pubspecFile.writeAsStringSync(newContent);
    print(
      'Success: Updated version to $newVersionName${newBuildNumber != null ? '+$newBuildNumber' : ''}',
    );
  } on FileSystemException catch (e) {
    stderr.writeln('Error writing to pubspec.yaml: ${e.message}');
  }
}