Skip to content

Commit

Permalink
Always set PURO_ROOT when initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Jun 10, 2024
1 parent 84022fe commit ce57cc2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
7 changes: 3 additions & 4 deletions puro_sidekick_plugin/lib/puro_sidekick_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// A Sidekick plugin that connects puro to the sidekick flutter command
library puro_sidekick_plugin;

import 'package:dcli/dcli.dart' as dcli;
import 'package:puro_sidekick_plugin/puro_sidekick_plugin.dart';
import 'package:puro_sidekick_plugin/src/flutter_sdk.dart';
import 'package:puro_sidekick_plugin/src/install_puro.dart';
Expand All @@ -15,10 +16,8 @@ void initializePuro(Directory sdk) {
// Create folder for flutter sdk symlink
final symlinkPath = flutterSdkSymlink();

final resultCode = installPuro();
if (resultCode != 0) {
throw PuroInstallationFailedException();
}
final puroRootDir = installPuro();
dcli.env['PURO_ROOT'] = puroRootDir.absolute.path;

// Setup puro environment
setupFlutterEnvironment();
Expand Down
30 changes: 16 additions & 14 deletions puro_sidekick_plugin/lib/src/install_puro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ const puroFallbackVersion = '1.4.6';
/// Executes Flutter CLI via puro
///
/// https://github.com/phntmxyz/puro_sidekick_plugin
int installPuro({
Directory? installDirectory,
Directory installPuro({
dcli.Progress? progress,
}) {
final puroPath = getPuroPath(installDirectory);
final puroPath = getPuroPath();

print('puro path: $puroPath');

if (puroPath != null) {
print('Puro is already installed at $puroPath');
return 0;
return puroPath.parent.parent;
}

final latestVersion = getLatestPuroVersion();
Expand All @@ -30,7 +29,7 @@ int installPuro({
final puroLinuxDownloadUrl = "https://puro.dev/builds/$latestVersion/linux-x64/puro";

int resultCode = -1;
final downloadPath = getPuroBinPath(installDirectory);
final downloadPath = getPuroBinPath();
if (Platform.isWindows) {
resultCode = installPuroWindows(puroWindowsDownloadUrl, downloadPath, progress);
} else if (Platform.isMacOS) {
Expand All @@ -40,7 +39,10 @@ int installPuro({
} else {
print('Unsupported platform.');
}
return resultCode;
if (resultCode != 0) {
throw PuroInstallationFailedException();
}
return downloadPath.parent;
}

String? getLatestPuroVersion() {
Expand All @@ -60,14 +62,14 @@ String? getLatestPuroVersion() {
}
}

int installPuroMacOs(String downloadUrl, String downloadPath, dcli.Progress? progress) {
int installPuroMacOs(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
final downloadProcess = dcli.startFromArgs(
'bash',
[
'-c',
'curl -O $downloadUrl',
],
workingDirectory: downloadPath,
workingDirectory: downloadPath.path,
nothrow: true,
progress: progress,
terminal: progress == null,
Expand All @@ -83,7 +85,7 @@ int installPuroMacOs(String downloadUrl, String downloadPath, dcli.Progress? pro
'-c',
'chmod +x puro',
],
workingDirectory: downloadPath,
workingDirectory: downloadPath.path,
nothrow: true,
progress: progress,
terminal: progress == null,
Expand All @@ -94,14 +96,14 @@ int installPuroMacOs(String downloadUrl, String downloadPath, dcli.Progress? pro
return chmodProcess.exitCode ?? -1;
}

int installPuroLinux(String downloadUrl, String downloadPath, dcli.Progress? progress) {
int installPuroLinux(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
final downloadProcess = dcli.startFromArgs(
'bash',
[
'-c',
'curl -O $downloadUrl',
],
workingDirectory: downloadPath,
workingDirectory: downloadPath.path,
nothrow: true,
progress: progress,
terminal: progress == null,
Expand All @@ -117,7 +119,7 @@ int installPuroLinux(String downloadUrl, String downloadPath, dcli.Progress? pro
'-c',
'chmod +x puro',
],
workingDirectory: downloadPath,
workingDirectory: downloadPath.path,
nothrow: true,
progress: progress,
terminal: progress == null,
Expand All @@ -128,13 +130,13 @@ int installPuroLinux(String downloadUrl, String downloadPath, dcli.Progress? pro
return chmodProcess.exitCode ?? -1;
}

int installPuroWindows(String downloadUrl, String downloadPath, dcli.Progress? progress) {
int installPuroWindows(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
final command = 'Invoke-WebRequest -Uri "$downloadUrl" -OutFile "\$env:temp\\puro.exe"; &"\$env:temp\\puro.exe"';

final process = dcli.startFromArgs(
'powershell.exe',
['-Command', command],
workingDirectory: downloadPath,
workingDirectory: downloadPath.path,
nothrow: true,
progress: progress,
terminal: progress == null,
Expand Down
19 changes: 8 additions & 11 deletions puro_sidekick_plugin/lib/src/puro.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:dcli/dcli.dart' as dcli;
import 'package:puro_sidekick_plugin/puro_sidekick_plugin.dart';
import 'package:sidekick_core/sidekick_core.dart';

/// Executes Flutter CLI via puro
Expand All @@ -8,21 +7,19 @@ import 'package:sidekick_core/sidekick_core.dart';
int puro(
List<String> args, {
Directory? workingDirectory,
Directory? installDirectory,
dcli.Progress? progress,
String Function()? throwOnError,
}) {
final workingDir = entryWorkingDirectory.absolute;
final installDir = installDirectory ?? SidekickContext.sidekickPackage.buildDir;

final puroPath = getPuroPath(installDir);
final puroPath = getPuroPath();

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

final process = dcli.startFromArgs(
puroPath,
puroPath.path,
['--no-update-check', '--no-install', ...args],
workingDirectory: workingDir.path,
nothrow: true,
Expand All @@ -39,9 +36,9 @@ int puro(
return exitCode;
}

String? getPuroPath(Directory? installDirectory) {
File? getPuroPath() {
String? path;
final result = dcli.find('puro', workingDirectory: getPuroBinPath(installDirectory), recursive: false);
final result = dcli.find('puro', workingDirectory: getPuroBinPath().path, recursive: false);
path = result.firstLine;
if (path == null) {
// Try to find puro in PATH
Expand All @@ -50,17 +47,17 @@ String? getPuroPath(Directory? installDirectory) {
path = which.path;
}
}
return path;
return path != null ? File(path) : null;
}

String getPuroBinPath(Directory? installDirectory) {
final installDir = installDirectory ?? SidekickContext.sidekickPackage.buildDir;
Directory getPuroBinPath() {
final installDir = SidekickContext.sidekickPackage.buildDir;

final puroPath = '${installDir.path}/bin/';
if (!dcli.exists(puroPath)) {
dcli.createDir(puroPath);
}
return puroPath;
return Directory(puroPath);
}

/// Thrown when puro is not found
Expand Down

0 comments on commit ce57cc2

Please sign in to comment.