getCurrentPuroVersion function
Implementation
Future<({bool standalone, String version})> getCurrentPuroVersion() async {
final puroPath = getPuroPath();
if (puroPath == null) {
throw PuroNotFoundException();
}
final progress = Progress.capture();
try {
await puro(
['--version'],
progress: progress,
workingDirectory: puroPath.parent.parent.absolute,
);
} catch (e, stackTrace) {
print('puro --version failed: $e');
print(stackTrace);
if (progress.lines.isNotEmpty) {
print('output:\n${progress.lines.join('\n')}');
}
rethrow;
}
final versionLine = progress.lines.firstWhere(
(line) => line.contains('[i] Puro'),
orElse: () => '',
);
final regex = RegExp(r'\b\d+\.\d+\.\d+\b');
final match = regex.firstMatch(versionLine);
String? version;
if (match != null) {
version = match.group(0);
}
if (version == null) {
final output = progress.lines.join('\n');
throw Exception(
'Could not parse puro version from output:\n$output',
);
}
final standalone = versionLine.contains('standalone');
return (standalone: standalone, version: version);
}