Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reference version file instead of fvmrc #671

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading