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;
}
}