Skip to content

Commit

Permalink
Update puro command
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Jul 16, 2024
1 parent cedaf2a commit 2c90576
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
12 changes: 2 additions & 10 deletions lib/src/commands/puro_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ class PuroCommand extends ForwardCommand {
Future<void> 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;
}
}
38 changes: 24 additions & 14 deletions lib/src/puro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProcessCompletion> puro(
List<String> 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() {
Expand Down

0 comments on commit 2c90576

Please sign in to comment.