From fcf5ea918f7b82e93e26432ec4058cc7226596ea Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 28 Feb 2024 14:00:56 -0700 Subject: [PATCH] refactor: reference version file instead of fvmrc --- lib/src/models/config_model.dart | 7 ------- lib/src/models/project_model.dart | 35 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 25cc4581..a4605e78 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -271,7 +271,6 @@ class AppConfig extends Config { /// Project config class ProjectConfig extends Config { /// Flutter SDK version configured - String? flutterSdkVersion; /// Flavors configured Map? flavors; @@ -292,7 +291,6 @@ class ProjectConfig extends Config { super.gitCachePath, super.flutterUrl, super.priviledgedAccess, - this.flutterSdkVersion, this.flavors, bool? updateVscodeSettings, bool? updateGitIgnore, @@ -311,7 +309,6 @@ class ProjectConfig extends Config { gitCachePath: envConfig.gitCachePath, flutterUrl: envConfig.flutterUrl, priviledgedAccess: envConfig.priviledgedAccess, - flutterSdkVersion: map['flutterSdkVersion'] ?? map['flutter'] as String?, flavors: map['flavors'] != null ? Map.from(map['flavors'] as Map) : null, updateVscodeSettings: map['updateVscodeSettings'] as bool?, updateGitIgnore: map['updateGitIgnore'] as bool?, @@ -368,7 +365,6 @@ class ProjectConfig extends Config { gitCachePath: gitCachePath ?? this.gitCachePath, flutterUrl: flutterUrl ?? this.flutterUrl, priviledgedAccess: priviledgedAccess ?? this.priviledgedAccess, - flutterSdkVersion: flutterSdkVersion ?? this.flutterSdkVersion, flavors: mergedFlavors, updateVscodeSettings: updateVscodeSettings ?? _updateVscodeSettings, updateGitIgnore: updateGitIgnore ?? _updateGitIgnore, @@ -379,7 +375,6 @@ class ProjectConfig extends Config { ProjectConfig merge(ProjectConfig config) { return copyWith( cachePath: config.cachePath, - flutterSdkVersion: config.flutterSdkVersion, useGitCache: config.useGitCache, updateVscodeSettings: config._updateVscodeSettings, updateGitIgnore: config._updateGitIgnore, @@ -399,7 +394,6 @@ class ProjectConfig extends Config { Map toLegacyMap() { return { - if (flutterSdkVersion != null) 'flutterSdkVersion': flutterSdkVersion, if (flavors != null && flavors!.isNotEmpty) 'flavors': flavors, }; } @@ -412,7 +406,6 @@ class ProjectConfig extends Config { Map toMap() { return { ...super.toMap(), - if (flutterSdkVersion != null) 'flutter': flutterSdkVersion, if (_updateVscodeSettings != null) 'updateVscodeSettings': _updateVscodeSettings, if (_updateGitIgnore != null) 'updateGitIgnore': _updateGitIgnore, diff --git a/lib/src/models/project_model.dart b/lib/src/models/project_model.dart index 45b30967..bda10207 100644 --- a/lib/src/models/project_model.dart +++ b/lib/src/models/project_model.dart @@ -5,7 +5,6 @@ import 'package:path/path.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:pubspec/pubspec.dart'; -import '../services/logger_service.dart'; import '../utils/constants.dart'; import '../utils/extensions.dart'; import 'config_model.dart'; @@ -46,22 +45,6 @@ class Project { // Used for migration of config files final legacyConfig = ProjectConfig.loadFromPath(legacyConfigFile); - if (legacyConfig != null && config != null) { - final legacyVersion = legacyConfig.flutterSdkVersion; - final version = config.flutterSdkVersion; - - if (legacyVersion != version) { - logger - ..warn( - 'Found fvm_config.json with SDK version different than .fvmrc\n' - 'fvm_config.json is deprecated and will be removed in future versions.\n' - 'Please do not modify this file manually.', - ) - ..spacer - ..warn('Ignoring fvm_config.json'); - } - } - if (config == null && legacyConfig != null) { legacyConfig.save(configFile); } @@ -79,11 +62,23 @@ class Project { /// Retrieves the name of the project. String get name => basename(path); + String? get flutterSdkRelease { + final sdkReleaseFile = join(localFvmPath, 'release'); + + return sdkReleaseFile.file.read(); + } + + String? get flutterSdkVersion { + final sdkVersionFile = join(localFvmPath, 'version'); + + return sdkVersionFile.file.read(); + } + /// Retrieves the pinned Flutter SDK version within the project. /// /// Returns `null` if no version is pinned. FlutterVersion? get pinnedVersion { - final sdkVersion = config?.flutterSdkVersion; + final sdkVersion = flutterSdkVersion; if (sdkVersion != null) { return FlutterVersion.parse(sdkVersion); } @@ -93,8 +88,10 @@ class Project { /// Retrieves the active configured flavor of the project. String? get activeFlavor { + final possibleValues = {flutterSdkRelease, flutterSdkVersion}; + return flavors.keys.firstWhereOrNull( - (key) => flavors[key] == pinnedVersion?.name, + (key) => possibleValues.contains(flavors[key]), ); }