Skip to content

Commit

Permalink
Fix flutter bin path
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Oct 8, 2024
1 parent 8005312 commit daa8dff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 10 additions & 4 deletions lib/puro_sidekick_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ void initializePuro(SdkInitializerContext context) {
_setupFlutterEnvironment(context);

// Create symlink to puro flutter sdk
final flutterPath = puroFlutterSdkPath();
dcli.env['PURO_FLUTTER_BIN'] = flutterPath;
final packageDir = context.packageDir?.root ?? SidekickContext.projectRoot;
final flutterPath = puroFlutterSdkPath(packageDir);

final flutterBinPath = Directory(flutterPath).directory('bin');

dcli.env['PURO_FLUTTER_BIN'] = flutterBinPath.absolute.path;
print('Use Puro Flutter SDK: $flutterPath');
createSymlink(symlinkPath, flutterPath);
}

void _setupFlutterEnvironment(SdkInitializerContext context) {
final packageDir = context.packageDir?.root ?? SidekickContext.projectRoot;

final sdkVersion = VersionParser(
packagePath: context.packageDir?.root ?? SidekickContext.projectRoot,
packagePath: packageDir,
projectRoot: SidekickContext.projectRoot,
).getMaxFlutterSdkVersionFromPubspec();

Expand All @@ -46,7 +52,7 @@ void _setupFlutterEnvironment(SdkInitializerContext context) {
}
print('Use Puro environment: $sdkVersion');
puro(
['use', '--project', entryWorkingDirectory.path, sdkVersion],
['use', '--project', packageDir.absolute.path, sdkVersion],
progress: Progress.print(),
);
}
Expand Down
17 changes: 9 additions & 8 deletions lib/src/flutter_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ String flutterSdkSymlink() {

/// Returns the Flutter SDK path from puro environment
/// throws [PuroNotFoundException] if puro is not found
String puroFlutterSdkPath() {
String puroFlutterSdkPath(Directory packageDir) {
String? envPath;
final pathMatcher = RegExp(r'.*executing: \[(.*)\].*');
final progress = Progress.capture();
puro(
['flutter', '-v', '--version'],
progress: Progress((line) {
if (envPath != null) return;
final match = pathMatcher.firstMatch(line);
if (match != null) {
envPath = match.group(1);
}
}),
progress: progress,
workingDirectory: packageDir,
);
final currentEnvs = progress.lines.join('\n');
final match = pathMatcher.firstMatch(currentEnvs);
if (match != null) {
envPath = match.group(1);
}
if (envPath == null) {
throw PuroNotFoundException();
}
Expand Down

0 comments on commit daa8dff

Please sign in to comment.