pubump function

Future<void> pubump(
  1. {bool push,
  2. bool publish,
  3. Level level,
  4. String message}
)

Implementation

Future<void> pubump({bool push, bool publish, Level level, String message}) async {
  // Don't allow an empty version bump.
  if (await nothingStaged()) {
    die('Error: Please stage the changes (git add ...) you would like pubump to commit.');
  }

  // Update files.
  final version = await updatePubspec(level);
  if (version == null) {
    die("Error parsing pubspec.yaml: Didn't find a `version: 1.2.3+4` line to bump.");
  }
  var changelog, content;
  try {
    changelog = await File('CHANGELOG.md');
    content = await changelog.readAsString();
  } catch (e) {
    die("Error: Couldn't find CHANGELOG.md. Run pubump from your package root, and create a CHANGELOG.md file there.");
  }
  await changelog.writeAsString('## $version\n\n- $message\n\n$content');

  // Create a commit.
  final commit = successfully(await Process.run('git', ['commit', '-am', '$version: $message']));
  print(commit.stdout); // print(await coloredDiff());

  // Optional post-bump actions.
  if (push) {
    print('Running `git push`...');
    successfully(await Process.run('git', ['push']));
  }
  if (publish) {
    print('Running `pub publish --force`...');
    successfully(await Process.run('pub', ['publish', '--force']));
  }

  // Report success.
  final verbed =
      push ? (publish ? 'Pushed and published' : 'Pushed') : (publish ? 'Published' : 'Created');
  print('All done! $verbed version $version.');
  exit(0);
}