From 2c9057640cd67921409af99ef378ec94e0dc6294 Mon Sep 17 00:00:00 2001 From: Maikel Rehl Date: Tue, 16 Jul 2024 17:27:23 +0200 Subject: [PATCH] Update puro command --- lib/src/commands/puro_command.dart | 12 ++-------- lib/src/puro.dart | 38 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/src/commands/puro_command.dart b/lib/src/commands/puro_command.dart index 13b5652..29abfe3 100644 --- a/lib/src/commands/puro_command.dart +++ b/lib/src/commands/puro_command.dart @@ -13,15 +13,7 @@ class PuroCommand extends ForwardCommand { Future run() async { final args = argResults!.arguments; - initializePuro( - SdkInitializerContext( - flutterSdk: flutterSdk, - dartSdk: dartSdk, - packageDir: SidekickContext.sidekickPackage, - workingDirectory: Directory.current, - ), - ); - - exitCode = puro(args); + final completion = await puro(args, nothrow: true); + exitCode = completion.exitCode ?? 1; } } diff --git a/lib/src/puro.dart b/lib/src/puro.dart index a381ab3..a6496ed 100644 --- a/lib/src/puro.dart +++ b/lib/src/puro.dart @@ -4,36 +4,46 @@ import 'package:sidekick_core/sidekick_core.dart'; /// Executes Flutter CLI via puro /// /// https://github.com/phntmxyz/puro_sidekick_plugin -int puro( +Future puro( List args, { Directory? workingDirectory, dcli.Progress? progress, + bool nothrow = false, String Function()? throwOnError, -}) { - final workingDir = entryWorkingDirectory.absolute; - +}) async { final puroPath = getPuroPath(); if (puroPath == null) { throw PuroNotFoundException(); } - final process = dcli.startFromArgs( - puroPath.path, - ['--no-update-check', '--no-install', ...args], - workingDirectory: workingDir.path, - nothrow: true, - progress: progress, - terminal: progress == null, - ); + await initializeSdkForPackage(workingDirectory); - final exitCode = process.exitCode ?? -1; + 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 exitCode; + return ProcessCompletion(exitCode: exitCode); } File? getPuroPath() {