getCurrentPackageVersion static method

String? getCurrentPackageVersion()

Implementation

static String? getCurrentPackageVersion() {
  try {
    // First try to find pubspec.yaml in the package directory (for global installation)
    final packageDir = findTemplatePath();
    final pubspecPath = path.join(packageDir, 'pubspec.yaml');

    // Debug: print the path we're checking
    stdout.writeln('πŸ” Checking for pubspec.yaml at: $pubspecPath');

    final pubspecFile = File(pubspecPath);
    if (pubspecFile.existsSync()) {
      final content = pubspecFile.readAsStringSync();
      final versionMatch = RegExp(r'version:\s*([^\s]+)').firstMatch(content);
      if (versionMatch != null) {
        final version = versionMatch.group(1);
        stdout.writeln('βœ… Found version: $version');
        return version;
      }
    }

    stdout.writeln('❌ Could not find version in pubspec.yaml');
    return null;
  } catch (e) {
    stdout.writeln('❌ Error getting version: $e');
    return null;
  }
}