readVersionConstant function

Future<String> readVersionConstant(
  1. String filePath, {
  2. String constant = 'packageVersion',
})

Reads the packageVersion constant from a generated version.g.dart.

Implementation

Future<String> readVersionConstant(
  String filePath, {
  String constant = 'packageVersion',
}) async {
  final content = await _readVersionFile(filePath);
  final pattern = RegExp(
    "const String ${RegExp.escape(constant)} = '([^']+)';",
  );
  final match = pattern.firstMatch(content);

  if (match == null) {
    throw ShipworldException('Missing $constant constant in $filePath');
  }

  return match.group(1)!;
}