Skip to content

Commit

Permalink
refactor: reference version file instead of fvmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgnhnt96 committed Feb 28, 2024
1 parent ddc741f commit fcf5ea9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
7 changes: 0 additions & 7 deletions lib/src/models/config_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class AppConfig extends Config {
/// Project config
class ProjectConfig extends Config {
/// Flutter SDK version configured
String? flutterSdkVersion;
/// Flavors configured
Map<String, String>? flavors;
Expand All @@ -292,7 +291,6 @@ class ProjectConfig extends Config {
super.gitCachePath,
super.flutterUrl,
super.priviledgedAccess,
this.flutterSdkVersion,
this.flavors,
bool? updateVscodeSettings,
bool? updateGitIgnore,
Expand All @@ -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?,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -399,7 +394,6 @@ class ProjectConfig extends Config {

Map<String, dynamic> toLegacyMap() {
return {
if (flutterSdkVersion != null) 'flutterSdkVersion': flutterSdkVersion,
if (flavors != null && flavors!.isNotEmpty) 'flavors': flavors,
};
}
Expand All @@ -412,7 +406,6 @@ class ProjectConfig extends Config {
Map<String, dynamic> toMap() {
return {
...super.toMap(),
if (flutterSdkVersion != null) 'flutter': flutterSdkVersion,
if (_updateVscodeSettings != null)
'updateVscodeSettings': _updateVscodeSettings,
if (_updateGitIgnore != null) 'updateGitIgnore': _updateGitIgnore,
Expand Down
35 changes: 16 additions & 19 deletions lib/src/models/project_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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]),
);
}

Expand Down

0 comments on commit fcf5ea9

Please sign in to comment.