getPackageVersion function

Future<Version> getPackageVersion(
  1. {String dir}
)

Get package version at given dir.

Default to current dir. Returns null if the dir does not exists or is not a pub package.

Implementation

Future<Version> getPackageVersion({String dir}) async {
  try {
    dir ??= '.';
    var version = Version.parse(
        (loadYaml(await File(join(dir, 'pubspec.yaml')).readAsString())
                as Map)['version']
            ?.toString());
    return version;
  } catch (_) {
    return null;
  }
}