Skip to content

Commit

Permalink
Use directory rather than strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Mar 18, 2024
1 parent 9eeaacb commit b0a4133
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/realm_dart/lib/src/cli/install/install_command.dart
Expand Up @@ -31,14 +31,15 @@ class InstallCommand extends Command<void> {
populateOptionsParser(argParser);
}

Directory getBinaryPath(String realmPackagePath, {required bool isFlutter}) {
Directory getBinaryPath(Directory realmPackagePath, {required bool isFlutter}) {
if (isFlutter) {
final root = realmPackagePath.path;
return Directory(switch (options.targetOsType) {
TargetOsType.android => path.join(realmPackagePath, 'android', 'src', 'main', 'cpp', 'lib'),
TargetOsType.ios => path.join(realmPackagePath, 'ios'),
TargetOsType.macos => path.join(realmPackagePath, 'macos'),
TargetOsType.linux => path.join(realmPackagePath, 'linux', 'binary', 'linux'),
TargetOsType.windows => path.join(realmPackagePath, 'windows', 'binary', 'windows'),
TargetOsType.android => path.join(root, 'android', 'src', 'main', 'cpp', 'lib'),
TargetOsType.ios => path.join(root, 'ios'),
TargetOsType.macos => path.join(root, 'macos'),
TargetOsType.linux => path.join(root, 'linux', 'binary', 'linux'),
TargetOsType.windows => path.join(root, 'windows', 'binary', 'windows'),
_ => throw Exception('Unsupported target OS type for Flutter: ${options.targetOsType}')
});
}
Expand Down Expand Up @@ -99,7 +100,7 @@ class InstallCommand extends Command<void> {
await versionFile.writeAsString(version.toString());
}

Future<String> getPackagePath(String name) async {
Future<Directory> getPackagePath(String name) async {
final packageConfig = await findPackageConfig(Directory.current);
if (packageConfig == null) {
abort('Run `dart pub get`');
Expand All @@ -108,7 +109,7 @@ class InstallCommand extends Command<void> {
if (package == null) {
abort('$name package not found in dependencies. Add $name package to your pubspec.yaml');
}
return package.root.toFilePath();
return Directory.fromUri(package.root);
}

Future<Pubspec> parsePubspec(File file) async {
Expand Down Expand Up @@ -139,7 +140,7 @@ class InstallCommand extends Command<void> {
}

final realmPackagePath = await getPackagePath(flavorName);
final realmPubspec = await parsePubspec(File(path.join(realmPackagePath, "pubspec.yaml")));
final realmPubspec = await parsePubspec(File(path.join(realmPackagePath.path, "pubspec.yaml")));

final binaryPath = getBinaryPath(realmPackagePath, isFlutter: flavor == Flavor.flutter);
print(binaryPath);
Expand Down

0 comments on commit b0a4133

Please sign in to comment.