Skip to content

Commit

Permalink
run dart format and analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Jun 12, 2024
1 parent 7649a43 commit be8c821
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 53 deletions.
2 changes: 0 additions & 2 deletions ci_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
Expand Down
8 changes: 6 additions & 2 deletions lib/puro_sidekick_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import 'package:puro_sidekick_plugin/src/version_parser.dart';
import 'package:sidekick_core/sidekick_core.dart';

export 'package:puro_sidekick_plugin/src/commands/puro_command.dart';
export 'package:puro_sidekick_plugin/src/flutter_sdk.dart' hide createSymlink, puroFlutterSdkPath;
export 'package:puro_sidekick_plugin/src/flutter_sdk.dart'
hide createSymlink, puroFlutterSdkPath;
export 'package:puro_sidekick_plugin/src/puro.dart';

void initializePuro(Directory sdk) {
Expand Down Expand Up @@ -46,7 +47,10 @@ void _setupFlutterEnvironment() {
puro(['create', sdkVersion, sdkVersion], progress: Progress.print());
}
print('Use Puro environment: $sdkVersion');
puro(['use', '--project', entryWorkingDirectory.path, sdkVersion], progress: Progress.print());
puro(
['use', '--project', entryWorkingDirectory.path, sdkVersion],
progress: Progress.print(),
);
}

/// Thrown when puro could not be installed
Expand Down
4 changes: 3 additions & 1 deletion lib/src/flutter_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:sidekick_core/sidekick_core.dart';

/// Create an empty folder for flutter sdk symlink
String flutterSdkSymlink() {
final flutterPath = Directory("${SidekickContext.sidekickPackage.buildDir.absolute.path}/flutter");
final flutterPath = Directory(
"${SidekickContext.sidekickPackage.buildDir.absolute.path}/flutter",
);
flutterPath.createSync(recursive: true);
return flutterPath.absolute.path;
}
Expand Down
79 changes: 61 additions & 18 deletions lib/src/install_puro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ Directory installPuro({
final puroPath = getPuroPath();

if (puroPath != null && puroPath.existsSync()) {
print('Puro is already installed at ${puroPath.parent.parent.absolute.path}');
print(
'Puro is already installed at ${puroPath.parent.parent.absolute.path}',
);
return puroPath.parent.parent;
}

final installGlobal =
dcli.ask("Puro is not installed.\nDo you want to install Puro global? (y/n)", defaultValue: 'n');
final installGlobal = dcli.ask(
"Puro is not installed.\nDo you want to install Puro global? (y/n)",
defaultValue: 'n',
);

final latestVersion = getLatestPuroVersion();
print('Download Puro $latestVersion');
Expand Down Expand Up @@ -61,18 +65,33 @@ Directory installPuroGlobal(String version, dcli.Progress? progress) {
}

Directory installPuroStandalone(String version, dcli.Progress? progress) {
final puroWindowsDownloadUrl = "https://puro.dev/builds/$version/windows-x64/puro.exe";
final puroDarwinDownloadUrl = "https://puro.dev/builds/$version/darwin-x64/puro";
final puroLinuxDownloadUrl = "https://puro.dev/builds/$version/linux-x64/puro";
final puroWindowsDownloadUrl =
"https://puro.dev/builds/$version/windows-x64/puro.exe";
final puroDarwinDownloadUrl =
"https://puro.dev/builds/$version/darwin-x64/puro";
final puroLinuxDownloadUrl =
"https://puro.dev/builds/$version/linux-x64/puro";

int resultCode = -1;
final downloadPath = getPuroStandaloneBinPath(createIfNotExists: true);
if (Platform.isWindows) {
resultCode = installPuroStandaloneWindows(puroWindowsDownloadUrl, downloadPath, progress);
resultCode = installPuroStandaloneWindows(
puroWindowsDownloadUrl,
downloadPath,
progress,
);
} else if (Platform.isMacOS) {
resultCode = installPuroStandaloneMacOs(puroDarwinDownloadUrl, downloadPath, progress);
resultCode = installPuroStandaloneMacOs(
puroDarwinDownloadUrl,
downloadPath,
progress,
);
} else if (Platform.isLinux) {
resultCode = installPuroStandaloneLinux(puroLinuxDownloadUrl, downloadPath, progress);
resultCode = installPuroStandaloneLinux(
puroLinuxDownloadUrl,
downloadPath,
progress,
);
} else {
print('Unsupported platform.');
}
Expand All @@ -84,22 +103,29 @@ Directory installPuroStandalone(String version, dcli.Progress? progress) {

String getLatestPuroVersion() {
try {
const command = 'curl https://api.github.com/repos/pingbird/puro/releases?per_page=1&page=1';
final output = dcli.start(command, progress: Progress.capture(captureStderr: false));
const command =
'curl https://api.github.com/repos/pingbird/puro/releases?per_page=1&page=1';
final output =
dcli.start(command, progress: Progress.capture(captureStderr: false));
if (output.exitCode != 0) {
print('Failed to get the latest Puro version.');
return puroFallbackVersion;
}
final resultJson = output.lines.join('\n');
final result = jsonDecode(resultJson);
return ((result as List<dynamic>)[0] as Map<String, dynamic>)['tag_name'] as String;
return ((result as List<dynamic>)[0] as Map<String, dynamic>)['tag_name']
as String;
} catch (e) {
print('Failed to get the latest Puro version: $e');
return puroFallbackVersion;
}
}

int installPuroStandaloneMacOs(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
int installPuroStandaloneMacOs(
String downloadUrl,
Directory downloadPath,
dcli.Progress? progress,
) {
final downloadProcess = dcli.startFromArgs(
'bash',
[
Expand Down Expand Up @@ -133,7 +159,11 @@ int installPuroStandaloneMacOs(String downloadUrl, Directory downloadPath, dcli.
return chmodProcess.exitCode ?? -1;
}

int installPuroStandaloneLinux(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
int installPuroStandaloneLinux(
String downloadUrl,
Directory downloadPath,
dcli.Progress? progress,
) {
final downloadProcess = dcli.startFromArgs(
'bash',
[
Expand Down Expand Up @@ -167,8 +197,13 @@ int installPuroStandaloneLinux(String downloadUrl, Directory downloadPath, dcli.
return chmodProcess.exitCode ?? -1;
}

int installPuroStandaloneWindows(String downloadUrl, Directory downloadPath, dcli.Progress? progress) {
final command = 'Invoke-WebRequest -Uri "$downloadUrl" -OutFile "\$env:temp\\puro.exe"; &"\$env:temp\\puro.exe"';
int installPuroStandaloneWindows(
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',
Expand All @@ -182,7 +217,11 @@ int installPuroStandaloneWindows(String downloadUrl, Directory downloadPath, dcl
return process.exitCode ?? -1;
}

int installPuroGlobalUnix(String version, Directory downloadPath, dcli.Progress? progress) {
int installPuroGlobalUnix(
String version,
Directory downloadPath,
dcli.Progress? progress,
) {
final process = dcli.startFromArgs(
'bash',
[
Expand All @@ -198,7 +237,11 @@ int installPuroGlobalUnix(String version, Directory downloadPath, dcli.Progress?
return process.exitCode ?? -1;
}

int installPuroGlobalWindows(String version, Directory downloadPath, dcli.Progress? progress) {
int installPuroGlobalWindows(
String version,
Directory downloadPath,
dcli.Progress? progress,
) {
final command =
'Invoke-WebRequest -Uri "https://puro.dev/builds/$version/windows-x64/puro.exe" -OutFile "\$env:temp\\puro.exe"; &"\$env:temp\\puro.exe" install-puro --promote"';

Expand Down
10 changes: 8 additions & 2 deletions lib/src/puro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ File? getPuroPath() {
if (path == null) {
final standalonePath = getPuroStandaloneBinPath();
if (standalonePath.existsSync()) {
final result = dcli.find('puro', workingDirectory: standalonePath.path, recursive: false);
final result = dcli.find(
'puro',
workingDirectory: standalonePath.path,
recursive: false,
);
path = result.firstLine;
}
}
Expand All @@ -55,7 +59,9 @@ File? getPuroPath() {

/// Returns the puro standalone bin path. It may not exist.
Directory getPuroStandaloneBinPath({bool createIfNotExists = false}) {
final path = Directory("${SidekickContext.sidekickPackage.buildDir.absolute.path}/puro/bin/");
final path = Directory(
"${SidekickContext.sidekickPackage.buildDir.absolute.path}/puro/bin/",
);
if (createIfNotExists && !path.existsSync()) {
path.createSync(recursive: true);
}
Expand Down
35 changes: 27 additions & 8 deletions lib/src/version_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class VersionParser {
projectRoot != null &&
projectRoot!.existsSync() &&
projectRoot!.absolute.path != packagePath.absolute.path) {
print('Package is part of a workspace. Use the root package pubspec.yaml to get the flutter version.');
print(
'Package is part of a workspace. Use the root package pubspec.yaml to get the flutter version.',
);
final newPubspec = _readPubspecFile(projectRoot!);
if (newPubspec != null) {
pubspec = newPubspec;
Expand Down Expand Up @@ -156,8 +158,10 @@ class VersionParser {
final parts = line.split('|');
if (parts.length >= 3) {
try {
final flutterVersion = Version.parse(parts[0].replaceAll('Flutter', '').trim());
final listedDartVersion = Version.parse(parts[3].replaceAll('Dart', '').trim());
final flutterVersion =
Version.parse(parts[0].replaceAll('Flutter', '').trim());
final listedDartVersion =
Version.parse(parts[3].replaceAll('Dart', '').trim());

// Only add the latest version for each dart version
if (isBetaRelease) {
Expand All @@ -172,16 +176,24 @@ class VersionParser {
final SplayTreeMap<Version, Version> sortedVersions;
if (useBeta) {
sortedVersions = SplayTreeMap<Version, Version>.from(
betaVersionMap, (key1, key2) => betaVersionMap[key1]!.compareTo(betaVersionMap[key2]!));
betaVersionMap,
(key1, key2) => betaVersionMap[key1]!.compareTo(betaVersionMap[key2]!),
);
} else {
sortedVersions = SplayTreeMap<Version, Version>.from(
versionMap, (key1, key2) => versionMap[key1]!.compareTo(versionMap[key2]!));
versionMap,
(key1, key2) => versionMap[key1]!.compareTo(versionMap[key2]!),
);
}

return sortedVersions;
}

String? _getBestFlutterVersion(Map<Version, Version> versions, String? dartConstraint, String? flutterConstraint) {
String? _getBestFlutterVersion(
Map<Version, Version> versions,
String? dartConstraint,
String? flutterConstraint,
) {
final availableVersions = _parseAvailableVersions();

if (flutterConstraint != null) {
Expand All @@ -203,8 +215,15 @@ class VersionParser {
}

/// Test method to get the best flutter version for the given dart and flutter constraints
String? testGetBestFlutterVersion({String? dartConstraint, String? flutterConstraint}) {
String? testGetBestFlutterVersion({
String? dartConstraint,
String? flutterConstraint,
}) {
final availableVersions = _parseAvailableVersions();
return _getBestFlutterVersion(availableVersions, dartConstraint, flutterConstraint);
return _getBestFlutterVersion(
availableVersions,
dartConstraint,
flutterConstraint,
);
}
}
5 changes: 4 additions & 1 deletion test/set_named_parameter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ void main() {

extension on ModifiableSourceFile {
MethodInvocation findMethodInvocationByName(String name) {
return analyze().nodes.whereType<MethodInvocation>().firstWhere((node) => node.methodName.name == name);
return analyze()
.nodes
.whereType<MethodInvocation>()
.firstWhere((node) => node.methodName.name == name);
}
}

Expand Down
Loading

0 comments on commit be8c821

Please sign in to comment.