update method

Future<void> update()

Prints notice if version needs update

Implementation

Future<void> update() async {
  try {
    final latestVersion = await _fetchLatestVersion();
    // Could not get latest version
    if (latestVersion == null) return;
    // Compare semver
    final comparison = compareSemver(currentVersion, latestVersion);
    // Check as need update if latest version is higher
    final needUpdate = comparison < 0;

    if (needUpdate) {
      final updateCmd = 'dart pub global activate $packageName'.cyan();
      final current = '$currentVersion'.grey();
      final latest = '$latestVersion'.green();

      print(
        '\n\n\n___________________________________________________\n\n'
            .yellow(),
      );
      print(
        'Update Available '
        '$current → $latest ',
      );
      print('Run $updateCmd to update');
      print('Changelog: ${_changelogUrl(packageName)}');
      print(
        '\n___________________________________________________\n\n\n'
            .yellow(),
      );
      return;
    }
    return;
  } on Exception {
    // Don't do anything fail silently
    return;
  }
}