getCurrentPuroVersion function

Future<({bool standalone, String version})> getCurrentPuroVersion()

Implementation

Future<({bool standalone, String version})> getCurrentPuroVersion() async {
  final puroPath = getPuroPath();
  if (puroPath == null) {
    throw PuroInstallationFailedException();
  }
  final progress = Progress.capture();
  await puro(
    ['--version'],
    progress: progress,
    workingDirectory: puroPath.parent.parent.absolute,
  );
  final versionLine = progress.lines.firstWhere(
    (line) => line.contains('[i] Puro'),
  );

  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) {
    throw PuroInstallationFailedException();
  }
  final standalone = versionLine.contains('standalone');
  return (standalone: standalone, version: version);
}