puro function

Future<ProcessCompletion> puro(
  1. List<String> args, {
  2. Directory? workingDirectory,
  3. Progress? progress,
  4. bool nothrow = false,
  5. String throwOnError()?,
})

Executes Flutter CLI via puro

https://github.com/phntmxyz/puro_sidekick_plugin

Implementation

Future<ProcessCompletion> puro(
  List<String> args, {
  Directory? workingDirectory,
  dcli.Progress? progress,
  bool nothrow = false,
  String Function()? throwOnError,
}) async {
  final puroPath = getPuroPath();

  if (puroPath == null) {
    throw PuroNotFoundException();
  }

  int exitCode = -1;
  try {
    final process = dcli.startFromArgs(
      puroPath.path,
      ['--no-update-check', '--no-install', ...args],
      workingDirectory: workingDirectory?.absolute.path,
      nothrow: nothrow || throwOnError != null,
      progress: progress,
      terminal: progress == null,
    );

    exitCode = process.exitCode ?? -1;
  } catch (e) {
    if (e is dcli.RunException) {
      exitCode = e.exitCode ?? 1;
    }
    if (throwOnError == null) {
      rethrow;
    }
  }
  if (exitCode != 0 && throwOnError != null) {
    throw throwOnError();
  }

  return ProcessCompletion(exitCode: exitCode);
}