From b258be07e71dc32399ff056dc96670177b0203bf Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 08:47:09 -0500 Subject: [PATCH 01/10] Renaming and linting --- CHANGELOG.md | 5 +++++ lib/src/commands/install_command.dart | 4 ++-- lib/src/commands/list_command.dart | 10 +++++----- lib/src/commands/use_command.dart | 4 ++-- lib/src/models/cache_flutter_version_model.dart | 5 ++++- test/commands/flutter_command_test.dart | 2 +- test/complete_workflow_test.dart | 4 ++-- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9647e9dc..afbe3c1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +* feat: `fvm use [version] --force` now skips install confirmation prompt by @mrgnhnt96 +* feat: Added flag to skip pub get on `install` and `use`, `--skip-pub-get` by @mrgnhnt96 + ## 3.0.12 * Adds skipping version mismatch handling when using force or running with a custom fvm version. [#653](https://github.com/leoafarias/fvm/issues/653) diff --git a/lib/src/commands/install_command.dart b/lib/src/commands/install_command.dart index 859cbcfe..7b4845f0 100644 --- a/lib/src/commands/install_command.dart +++ b/lib/src/commands/install_command.dart @@ -30,8 +30,8 @@ class InstallCommand extends BaseCommand { ..addFlag( 'skip-pub-get', help: 'Skip resolving dependencies after switching Flutter SDK', - negatable: false, defaultsTo: false, + negatable: false, ); } @@ -65,7 +65,7 @@ class InstallCommand extends BaseCommand { project: project, force: true, skipSetup: !setup, - resolveDependencies: !skipPubGet, + runPubGetOnSdkChange: !skipPubGet, ); return ExitCode.success.code; diff --git a/lib/src/commands/list_command.dart b/lib/src/commands/list_command.dart index ceb47a04..fc7ee13d 100644 --- a/lib/src/commands/list_command.dart +++ b/lib/src/commands/list_command.dart @@ -1,13 +1,13 @@ import 'package:dart_console/dart_console.dart'; -import '../services/global_version_service.dart'; -import '../services/releases_service/models/release.model.dart'; -import '../services/releases_service/releases_client.dart'; -import '../utils/helpers.dart'; import 'package:mason_logger/mason_logger.dart'; import '../services/cache_service.dart'; +import '../services/global_version_service.dart'; import '../services/logger_service.dart'; +import '../services/releases_service/models/release.model.dart'; +import '../services/releases_service/releases_client.dart'; import '../utils/context.dart'; +import '../utils/helpers.dart'; import 'base_command.dart'; /// List installed SDK Versions @@ -71,7 +71,7 @@ class ListCommand extends BaseCommand { String flutterSdkVersion = version.flutterSdkVersion ?? ''; String getVersionOutput() { - if (version.notSetup) { + if (version.isNotSetup) { return flutterSdkVersion = '${yellow.wrap('Need setup')}'; } if (latestRelease != null && version.isChannel) { diff --git a/lib/src/commands/use_command.dart b/lib/src/commands/use_command.dart index 91a5f854..aa47ce77 100644 --- a/lib/src/commands/use_command.dart +++ b/lib/src/commands/use_command.dart @@ -46,8 +46,8 @@ class UseCommand extends BaseCommand { ..addFlag( 'skip-pub-get', help: 'Skip resolving dependencies after switching Flutter SDK', - negatable: false, defaultsTo: false, + negatable: false, ) ..addFlag( 'skip-setup', @@ -135,8 +135,8 @@ class UseCommand extends BaseCommand { project: project, force: forceOption, skipSetup: skipSetup, + runPubGetOnSdkChange: !skipPubGet, flavor: flavorOption, - resolveDependencies: !skipPubGet, ); return ExitCode.success.code; diff --git a/lib/src/models/cache_flutter_version_model.dart b/lib/src/models/cache_flutter_version_model.dart index 3d794dcf..7199b950 100644 --- a/lib/src/models/cache_flutter_version_model.dart +++ b/lib/src/models/cache_flutter_version_model.dart @@ -65,7 +65,10 @@ class CacheFlutterVersion extends FlutterVersion { } /// Verifies that cacheVersion has been setup - bool get notSetup => flutterSdkVersion == null; + bool get isNotSetup => flutterSdkVersion == null; + + /// Returns bool if version is setup + bool get isSetup => flutterSdkVersion != null; Future run( String command, { diff --git a/test/commands/flutter_command_test.dart b/test/commands/flutter_command_test.dart index 69432cd2..85778f70 100644 --- a/test/commands/flutter_command_test.dart +++ b/test/commands/flutter_command_test.dart @@ -28,7 +28,7 @@ void main() { expect(project.pinnedVersion?.name, channel); expect( - cacheVersion?.notSetup, + cacheVersion?.isNotSetup, false, reason: 'Version should be setup', ); diff --git a/test/complete_workflow_test.dart b/test/complete_workflow_test.dart index e9c81845..6c43c8ad 100644 --- a/test/complete_workflow_test.dart +++ b/test/complete_workflow_test.dart @@ -29,7 +29,7 @@ void main() { expect(existingChannel, channel); expect( - cacheVersion?.notSetup, + cacheVersion?.isNotSetup, true, reason: 'Version should not be setup', ); @@ -63,7 +63,7 @@ void main() { expect(project.pinnedVersion?.name, channel); expect( - cacheVersion?.notSetup, + cacheVersion?.isNotSetup, true, reason: 'Version should not be setup', ); From 976d789f4476ce29e5cbf762f6b218069133ae69 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 08:47:32 -0500 Subject: [PATCH 02/10] Further adjustments --- lib/src/models/project_model.dart | 8 +++++--- lib/src/workflows/resolve_dependencies.workflow.dart | 2 +- lib/src/workflows/use_version.workflow.dart | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/src/models/project_model.dart b/lib/src/models/project_model.dart index 45b30967..9234a165 100644 --- a/lib/src/models/project_model.dart +++ b/lib/src/models/project_model.dart @@ -25,14 +25,16 @@ class Project { final PubSpec? pubspec; - const - /// Creates a new instance of [Project]. /// /// The [config] parameter represents the configuration of the project. /// The [path] parameter is the directory path of the project. /// The [pubspec] parameter represents the pubspec.yaml file of the project. - Project({required this.config, required this.path, required this.pubspec}); + const Project({ + required this.config, + required this.path, + required this.pubspec, + }); /// Loads the Flutter project from the given [path]. /// diff --git a/lib/src/workflows/resolve_dependencies.workflow.dart b/lib/src/workflows/resolve_dependencies.workflow.dart index 509a1c51..d10e5e7c 100644 --- a/lib/src/workflows/resolve_dependencies.workflow.dart +++ b/lib/src/workflows/resolve_dependencies.workflow.dart @@ -12,7 +12,7 @@ Future resolveDependenciesWorkflow( CacheFlutterVersion version, { required bool force, }) async { - if (version.notSetup) return; + if (version.isNotSetup) return; if (project.dartToolVersion == version.flutterSdkVersion) { return; diff --git a/lib/src/workflows/use_version.workflow.dart b/lib/src/workflows/use_version.workflow.dart index 0956a56d..5dfb5b87 100644 --- a/lib/src/workflows/use_version.workflow.dart +++ b/lib/src/workflows/use_version.workflow.dart @@ -27,7 +27,7 @@ Future useVersionWorkflow({ required Project project, bool force = false, bool skipSetup = false, - bool resolveDependencies = true, + bool runPubGetOnSdkChange = true, String? flavor, }) async { // If project use check that is Flutter project @@ -47,7 +47,7 @@ Future useVersionWorkflow({ ..detail('Project path: ${project.path}') ..detail(''); - if (!skipSetup && version.notSetup) { + if (!skipSetup && version.isNotSetup) { await setupFlutterWorkflow(version); } @@ -62,7 +62,7 @@ Future useVersionWorkflow({ await _checkGitignore(updatedProject, force: force); - if (resolveDependencies) { + if (runPubGetOnSdkChange) { await resolveDependenciesWorkflow(updatedProject, version, force: force); } From 1357e369b71d723f478430b55700e530ac9ec726 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 09:37:17 -0500 Subject: [PATCH 03/10] wip --- lib/src/models/config_model.dart | 69 +++++++++++++------------ lib/src/services/config_repository.dart | 35 +++++-------- lib/src/services/project_service.dart | 38 +++++++++----- lib/src/utils/context.dart | 22 ++++++-- 4 files changed, 93 insertions(+), 71 deletions(-) diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 25cc4581..48533843 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -18,6 +18,8 @@ class ConfigKeys { static const ConfigKeys gitCachePath = ConfigKeys('git_cache_path'); static const ConfigKeys flutterUrl = ConfigKeys('flutter_url'); static const ConfigKeys priviledgedAccess = ConfigKeys('priviledged_access'); + static const ConfigKeys runPubGetOnSdkChanges = + ConfigKeys('run_pub_get_on_sdk_changes'); static const values = [ cachePath, @@ -117,6 +119,9 @@ class Config { /// If FVM should run with priviledged access bool? priviledgedAccess; + // Run pub get on sdk changes + bool? runPubGetOnSdkChanges; + /// Constructor Config({ required this.cachePath, @@ -124,6 +129,7 @@ class Config { required this.gitCachePath, required this.flutterUrl, required this.priviledgedAccess, + required this.runPubGetOnSdkChanges, }); factory Config.empty() { @@ -133,6 +139,7 @@ class Config { gitCachePath: null, flutterUrl: null, priviledgedAccess: null, + runPubGetOnSdkChanges: null, ); } @@ -143,6 +150,8 @@ class Config { gitCachePath: map[ConfigKeys.gitCachePath.propKey] as String?, flutterUrl: map[ConfigKeys.flutterUrl.propKey] as String?, priviledgedAccess: map[ConfigKeys.priviledgedAccess.propKey] as bool?, + runPubGetOnSdkChanges: + map[ConfigKeys.runPubGetOnSdkChanges.propKey] as bool?, ); } @@ -154,6 +163,8 @@ class Config { if (flutterUrl != null) ConfigKeys.flutterUrl.propKey: flutterUrl, if (priviledgedAccess != null) ConfigKeys.priviledgedAccess.propKey: priviledgedAccess, + if (runPubGetOnSdkChanges != null) + ConfigKeys.runPubGetOnSdkChanges.propKey: runPubGetOnSdkChanges, }; } } @@ -173,6 +184,7 @@ class AppConfig extends Config { required super.gitCachePath, required super.flutterUrl, required super.priviledgedAccess, + required super.runPubGetOnSdkChanges, }); factory AppConfig.empty() { @@ -184,6 +196,7 @@ class AppConfig extends Config { gitCachePath: null, flutterUrl: null, priviledgedAccess: null, + runPubGetOnSdkChanges: null, ); } @@ -200,6 +213,7 @@ class AppConfig extends Config { gitCachePath: envConfig.gitCachePath, flutterUrl: envConfig.flutterUrl, priviledgedAccess: envConfig.priviledgedAccess, + runPubGetOnSdkChanges: envConfig.runPubGetOnSdkChanges, ); } @@ -223,6 +237,7 @@ class AppConfig extends Config { bool? disableUpdateCheck, DateTime? lastUpdateCheck, bool? priviledgedAccess, + bool? runPubGetOnSdkChanges, }) { return AppConfig( disableUpdateCheck: disableUpdateCheck ?? this.disableUpdateCheck, @@ -232,6 +247,8 @@ class AppConfig extends Config { gitCachePath: gitCachePath ?? this.gitCachePath, flutterUrl: flutterUrl ?? this.flutterUrl, priviledgedAccess: priviledgedAccess ?? this.priviledgedAccess, + runPubGetOnSdkChanges: + runPubGetOnSdkChanges ?? this.runPubGetOnSdkChanges, ); } @@ -244,6 +261,7 @@ class AppConfig extends Config { disableUpdateCheck: config?.disableUpdateCheck, lastUpdateCheck: config?.lastUpdateCheck, priviledgedAccess: config?.priviledgedAccess, + runPubGetOnSdkChanges: config?.runPubGetOnSdkChanges, ); } @@ -254,6 +272,7 @@ class AppConfig extends Config { gitCachePath: config?.gitCachePath, flutterUrl: config?.flutterUrl, priviledgedAccess: config?.priviledgedAccess, + runPubGetOnSdkChanges: config?.runPubGetOnSdkChanges, ); } @@ -277,13 +296,10 @@ class ProjectConfig extends Config { Map? flavors; /// If Vscode settings is not managed by FVM - bool? _updateVscodeSettings; + bool? updateVscodeSettings; /// If FVM should update .gitignore - bool? _updateGitIgnore; - - /// If should run pub get on sdk change - bool? _runPubGetOnSdkChanges; + bool? updateGitIgnore; /// Constructor ProjectConfig({ @@ -292,14 +308,12 @@ class ProjectConfig extends Config { super.gitCachePath, super.flutterUrl, super.priviledgedAccess, + super.runPubGetOnSdkChanges, this.flutterSdkVersion, this.flavors, - bool? updateVscodeSettings, - bool? updateGitIgnore, - bool? runPubGetOnSdkChanges, - }) : _updateVscodeSettings = updateVscodeSettings, - _updateGitIgnore = updateGitIgnore, - _runPubGetOnSdkChanges = runPubGetOnSdkChanges; + this.updateVscodeSettings, + this.updateGitIgnore, + }); /// Returns ConfigDto from a map factory ProjectConfig.fromMap(Map map) { @@ -311,11 +325,11 @@ class ProjectConfig extends Config { gitCachePath: envConfig.gitCachePath, flutterUrl: envConfig.flutterUrl, priviledgedAccess: envConfig.priviledgedAccess, + runPubGetOnSdkChanges: envConfig.runPubGetOnSdkChanges, 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?, - runPubGetOnSdkChanges: map['runPubGetOnSdkChanges'] as bool?, ); } @@ -331,15 +345,6 @@ class ProjectConfig extends Config { : null; } - /// Returns update vscode settings - bool? get updateVscodeSettings => _updateVscodeSettings; - - /// Returns update git ignore - bool? get updateGitIgnore => _updateGitIgnore; - - /// Returns run pub get on sdk changes - bool? get runPubGetOnSdkChanges => _runPubGetOnSdkChanges; - /// Copies current config and overrides with new values /// Returns a new ConfigDto @@ -368,11 +373,12 @@ class ProjectConfig extends Config { gitCachePath: gitCachePath ?? this.gitCachePath, flutterUrl: flutterUrl ?? this.flutterUrl, priviledgedAccess: priviledgedAccess ?? this.priviledgedAccess, + runPubGetOnSdkChanges: + runPubGetOnSdkChanges ?? this.runPubGetOnSdkChanges, flutterSdkVersion: flutterSdkVersion ?? this.flutterSdkVersion, flavors: mergedFlavors, - updateVscodeSettings: updateVscodeSettings ?? _updateVscodeSettings, - updateGitIgnore: updateGitIgnore ?? _updateGitIgnore, - runPubGetOnSdkChanges: runPubGetOnSdkChanges ?? _runPubGetOnSdkChanges, + updateVscodeSettings: updateVscodeSettings ?? this.updateVscodeSettings, + updateGitIgnore: updateGitIgnore ?? this.updateGitIgnore, ); } @@ -381,9 +387,9 @@ class ProjectConfig extends Config { cachePath: config.cachePath, flutterSdkVersion: config.flutterSdkVersion, useGitCache: config.useGitCache, - updateVscodeSettings: config._updateVscodeSettings, - updateGitIgnore: config._updateGitIgnore, - runPubGetOnSdkChanges: config._runPubGetOnSdkChanges, + updateVscodeSettings: config.updateVscodeSettings, + updateGitIgnore: config.updateGitIgnore, + runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, priviledgedAccess: config.priviledgedAccess, gitCachePath: config.gitCachePath, flutterUrl: config.flutterUrl, @@ -413,11 +419,10 @@ class ProjectConfig extends Config { return { ...super.toMap(), if (flutterSdkVersion != null) 'flutter': flutterSdkVersion, - if (_updateVscodeSettings != null) - 'updateVscodeSettings': _updateVscodeSettings, - if (_updateGitIgnore != null) 'updateGitIgnore': _updateGitIgnore, - if (_runPubGetOnSdkChanges != null) - 'runPubGetOnSdkChanges': _runPubGetOnSdkChanges, + if (updateVscodeSettings != null) + 'updateVscodeSettings': updateVscodeSettings, + if (updateGitIgnore != null) 'updateGitIgnore': updateGitIgnore, + 'runPubGetOnSdkChanges': runPubGetOnSdkChanges, if (flavors != null && flavors!.isNotEmpty) 'flavors': flavors, }; } diff --git a/lib/src/services/config_repository.dart b/lib/src/services/config_repository.dart index 0ba003c8..f930b489 100644 --- a/lib/src/services/config_repository.dart +++ b/lib/src/services/config_repository.dart @@ -48,15 +48,11 @@ class ConfigRepository { static Config loadEnv() { final environments = Platform.environment; - bool? gitCache; - String? gitCachePath; - String? flutterUrl; - String? cachePath; - bool? priviledgedAccess; + final config = Config.empty(); // Default to Flutter's environment variable if present; can still be overridden if (environments.containsKey(flutterGitUrl)) { - flutterUrl = environments[flutterGitUrl]; + config.flutterUrl = environments[flutterGitUrl]; } for (final variable in ConfigKeys.values) { @@ -64,40 +60,33 @@ class ConfigRepository { final legacyFvmHome = environments['FVM_HOME']; if (variable == ConfigKeys.cachePath) { - cachePath = value ?? legacyFvmHome; - break; + config.cachePath = value ?? legacyFvmHome; } if (value == null) continue; if (variable == ConfigKeys.useGitCache) { - gitCache = stringToBool(value); - break; + config.useGitCache = stringToBool(value); } if (variable == ConfigKeys.gitCachePath) { - gitCachePath = value; - break; + config.gitCachePath = value; } if (variable == ConfigKeys.flutterUrl) { - flutterUrl = value; - break; + config.flutterUrl = value; } if (variable == ConfigKeys.priviledgedAccess) { - priviledgedAccess = stringToBool(value); - break; + config.priviledgedAccess = stringToBool(value); + } + + if (variable == ConfigKeys.runPubGetOnSdkChanges) { + config.runPubGetOnSdkChanges = stringToBool(value); } } - return Config( - cachePath: cachePath, - useGitCache: gitCache, - gitCachePath: gitCachePath, - flutterUrl: flutterUrl, - priviledgedAccess: priviledgedAccess, - ); + return config; } static String get _configPath => kAppConfigFile; diff --git a/lib/src/services/project_service.dart b/lib/src/services/project_service.dart index 4288dd7f..e30e9fab 100644 --- a/lib/src/services/project_service.dart +++ b/lib/src/services/project_service.dart @@ -9,6 +9,30 @@ import '../utils/extensions.dart'; import '../utils/pretty_json.dart'; import 'base_service.dart'; +class ProjectRepository { + const ProjectRepository._(); + static Project findAncestor(Directory directory) { + // Checks if the directory is root + final isRootDir = path.rootPrefix(directory.path) == directory.path; + + // Gets project from directory + final project = Project.loadFromPath(directory.path); + + // If project has a config return it + if (project.hasConfig && project.hasPubspec) { + return project; + } + + // Return working directory if has reached root + if (isRootDir) { + return Project.loadFromPath(directory.path); + } + + // Recursive look up + return findAncestor(directory.parent); + } +} + /// Flutter Project Services /// APIs for interacting with local Flutter projects /// @@ -32,19 +56,7 @@ class ProjectService extends ContextService { // Get directory, defined root or current directory ??= Directory(context.workingDirectory); - // Checks if the directory is root - final isRootDir = path.rootPrefix(directory.path) == directory.path; - - // Gets project from directory - final project = Project.loadFromPath(directory.path); - - // If project has a config return it - if (project.hasConfig && project.hasPubspec) return project; - - // Return working directory if has reached root - if (isRootDir) return Project.loadFromPath(context.workingDirectory); - - return findAncestor(directory: directory.parent); + return ProjectRepository.findAncestor(directory); } /// Search for version configured diff --git a/lib/src/utils/context.dart b/lib/src/utils/context.dart index 2b5ede1b..abf7c3c6 100644 --- a/lib/src/utils/context.dart +++ b/lib/src/utils/context.dart @@ -57,6 +57,7 @@ class FVMContext { workingDirectory ??= Directory.current.path; // Load config from file in config path + final projectConfig = ProjectConfig.loadFromPath(workingDirectory); final envConfig = ConfigRepository.loadEnv(); @@ -105,7 +106,16 @@ class FVMContext { String get fvmDir => config.cachePath ?? kAppDirHome; /// Flag to determine if should use git cache - bool get gitCache => config.useGitCache ?? true; + bool get gitCache { + return config.useGitCache != null ? config.useGitCache! : true; + } + + /// Run pub get on sdk changes + bool get runPubGetOnSdkChanges { + return config.runPubGetOnSdkChanges != null + ? config.runPubGetOnSdkChanges! + : true; + } String get gitCachePath { // If git cache is not overriden use default based on fvmDir @@ -121,10 +131,16 @@ class FVMContext { DateTime? get lastUpdateCheck => config.lastUpdateCheck; /// Flutter SDK Path - bool get updateCheckDisabled => config.disableUpdateCheck ?? false; + bool get updateCheckDisabled { + return config.disableUpdateCheck != null + ? config.disableUpdateCheck! + : false; + } /// Priviledged access - bool get priviledgedAccess => config.priviledgedAccess ?? true; + bool get priviledgedAccess { + return config.priviledgedAccess != null ? config.priviledgedAccess! : true; + } /// Where Default Flutter SDK is stored String get globalCacheLink => join(fvmDir, 'default'); From 1a6cfeae5f812bbf23022c85427b146328d83738 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 09:41:36 -0500 Subject: [PATCH 04/10] Update project service with better logging --- lib/src/services/project_service.dart | 49 +++++++++++++-------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/src/services/project_service.dart b/lib/src/services/project_service.dart index e30e9fab..016dd00e 100644 --- a/lib/src/services/project_service.dart +++ b/lib/src/services/project_service.dart @@ -8,30 +8,7 @@ import '../utils/context.dart'; import '../utils/extensions.dart'; import '../utils/pretty_json.dart'; import 'base_service.dart'; - -class ProjectRepository { - const ProjectRepository._(); - static Project findAncestor(Directory directory) { - // Checks if the directory is root - final isRootDir = path.rootPrefix(directory.path) == directory.path; - - // Gets project from directory - final project = Project.loadFromPath(directory.path); - - // If project has a config return it - if (project.hasConfig && project.hasPubspec) { - return project; - } - - // Return working directory if has reached root - if (isRootDir) { - return Project.loadFromPath(directory.path); - } - - // Recursive look up - return findAncestor(directory.parent); - } -} +import 'logger_service.dart'; /// Flutter Project Services /// APIs for interacting with local Flutter projects @@ -56,7 +33,29 @@ class ProjectService extends ContextService { // Get directory, defined root or current directory ??= Directory(context.workingDirectory); - return ProjectRepository.findAncestor(directory); + logger.detail('Searching for project in ${directory.path}'); + + // Checks if the directory is root + final isRootDir = path.rootPrefix(directory.path) == directory.path; + + // Gets project from directory + final project = Project.loadFromPath(directory.path); + + // If project has a config return it + if (project.hasConfig && project.hasPubspec) { + logger.detail('Found project in ${project.path}'); + + return project; + } + + // Return working directory if has reached root + if (isRootDir) { + logger.detail('No project found in ${context.workingDirectory}'); + + return Project.loadFromPath(context.workingDirectory); + } + + return findAncestor(directory: directory.parent); } /// Search for version configured From 0cba4aa6cd21b3f9f06729d80abc9f1358e17fd7 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 10:05:03 -0500 Subject: [PATCH 05/10] Fixes --- lib/src/services/base_service.dart | 1 + .../releases_service/releases_client.dart | 1 - lib/src/utils/context.dart | 23 +++++++++++-------- .../resolve_dependencies.workflow.dart | 5 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/src/services/base_service.dart b/lib/src/services/base_service.dart index ea0b3012..783f4ba3 100644 --- a/lib/src/services/base_service.dart +++ b/lib/src/services/base_service.dart @@ -2,6 +2,7 @@ import '../utils/context.dart'; abstract class ContextService { final FVMContext? _context; + const ContextService(FVMContext? context) : _context = context; /// Gets context, if no context is passed will get from scope diff --git a/lib/src/services/releases_service/releases_client.dart b/lib/src/services/releases_service/releases_client.dart index 7f180340..472ebc27 100644 --- a/lib/src/services/releases_service/releases_client.dart +++ b/lib/src/services/releases_service/releases_client.dart @@ -28,7 +28,6 @@ String getReleasesUrl(String platform) { class FlutterReleases { static Releases? _cacheReleasesRes; - const FlutterReleases._(); /// Gets Flutter SDK Releases diff --git a/lib/src/utils/context.dart b/lib/src/utils/context.dart index abf7c3c6..5225f42b 100644 --- a/lib/src/utils/context.dart +++ b/lib/src/utils/context.dart @@ -38,12 +38,12 @@ class FVMContext { /// Flag to determine if context is running in a test final bool isTest; - /// App config - final AppConfig config; - /// Generators for dependencies final Map? generators; + /// App config + final AppConfig _config; + /// Generated values final Map _dependencies = {}; @@ -58,12 +58,9 @@ class FVMContext { // Load config from file in config path - final projectConfig = ProjectConfig.loadFromPath(workingDirectory); final envConfig = ConfigRepository.loadEnv(); - final appConfig = ConfigRepository.loadFile() - .mergeConfig(envConfig) - .mergeConfig(projectConfig); + final appConfig = ConfigRepository.loadFile().mergeConfig(envConfig); // Merge config from file with env config final config = appConfig.merge(configOverrides); @@ -94,10 +91,18 @@ class FVMContext { FVMContext._({ required this.id, required this.workingDirectory, - required this.config, + required AppConfig config, this.generators = const {}, this.isTest = false, - }); + }) : _config = config; + + AppConfig get config { + // TODO: Need to optimize this + // For now optimizing for correctness + final projectConfig = ProjectService(this).findAncestor().config; + + return _config.mergeConfig(projectConfig); + } /// Environment variables Map get environment => Platform.environment; diff --git a/lib/src/workflows/resolve_dependencies.workflow.dart b/lib/src/workflows/resolve_dependencies.workflow.dart index d10e5e7c..018d40f3 100644 --- a/lib/src/workflows/resolve_dependencies.workflow.dart +++ b/lib/src/workflows/resolve_dependencies.workflow.dart @@ -5,6 +5,7 @@ import 'package:mason_logger/mason_logger.dart'; import '../models/cache_flutter_version_model.dart'; import '../models/project_model.dart'; import '../services/logger_service.dart'; +import '../utils/context.dart'; import '../utils/exceptions.dart'; Future resolveDependenciesWorkflow( @@ -18,9 +19,7 @@ Future resolveDependenciesWorkflow( return; } - final runPubGetOnSdkChanges = project.config?.runPubGetOnSdkChanges ?? true; - - if (!runPubGetOnSdkChanges) { + if (!ctx.runPubGetOnSdkChanges) { logger ..info('Skipping "pub get" because of config setting.') ..spacer; From 0ee3b2d4c6963a412b133018d462b039271916a7 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 13:18:28 -0500 Subject: [PATCH 06/10] Added dart mappable --- .github/actions/prepare/action.yml | 2 +- lib/src/commands/config_command.dart | 36 +- lib/src/commands/update_command.dart | 2 +- lib/src/models/config_model.dart | 448 +++++------- lib/src/models/config_model.mapper.dart | 866 ++++++++++++++++++++++++ lib/src/runner.dart | 2 +- lib/src/services/config_repository.dart | 75 +- lib/src/services/project_service.dart | 4 +- lib/src/utils/context.dart | 18 +- lib/src/utils/deprecation_util.dart | 2 +- lib/src/version.dart | 2 + lib/src/version.g.dart | 3 - pubspec.lock | 168 +++++ pubspec.yaml | 5 + test/ensure_build_test.dart | 6 + test/utils/helpers_test.dart | 2 +- tool/grind.dart | 36 - 17 files changed, 1296 insertions(+), 381 deletions(-) create mode 100644 lib/src/models/config_model.mapper.dart create mode 100644 lib/src/version.dart delete mode 100644 lib/src/version.g.dart create mode 100644 test/ensure_build_test.dart diff --git a/.github/actions/prepare/action.yml b/.github/actions/prepare/action.yml index 159cc5b4..7ddccb1e 100644 --- a/.github/actions/prepare/action.yml +++ b/.github/actions/prepare/action.yml @@ -21,5 +21,5 @@ runs: shell: bash - name: Build Version - run: dart run grinder build-version + run: dart run build_runner build --delete-conflicting-outputs shell: bash diff --git a/lib/src/commands/config_command.dart b/lib/src/commands/config_command.dart index 864a08d0..7adcafba 100644 --- a/lib/src/commands/config_command.dart +++ b/lib/src/commands/config_command.dart @@ -29,23 +29,24 @@ class ConfigCommand extends BaseCommand { @override Future run() async { // Flag if settings should be saved - var shouldSave = false; - var current = ConfigRepository.loadFile(); + final currentConfig = ConfigRepository.loadAppConfig(); + var updatedConfig = currentConfig; + + // TODO: Consolidate redundant code if (wasParsed(ConfigKeys.flutterUrl.paramKey)) { final flutterRepo = stringArg(ConfigKeys.flutterUrl.paramKey); logger.info('Setting flutter repo to: ${yellow.wrap(flutterRepo)}'); - current.flutterUrl = flutterRepo; - - shouldSave = true; + // current.flutterUrl = flutterRepo; + updatedConfig = currentConfig.copyWith(flutterUrl: flutterRepo); } if (wasParsed(ConfigKeys.gitCachePath.paramKey)) { final gitCachePath = stringArg(ConfigKeys.gitCachePath.paramKey); logger.info('Setting git cache path to: ${yellow.wrap(gitCachePath)}'); - current.gitCachePath = gitCachePath; - shouldSave = true; + // currentConfig.gitCachePath = gitCachePath; + updatedConfig = currentConfig.copyWith(gitCachePath: gitCachePath); } if (wasParsed(ConfigKeys.useGitCache.paramKey)) { @@ -53,24 +54,31 @@ class ConfigCommand extends BaseCommand { logger.info( 'Setting use git cache to: ${yellow.wrap(gitCache.toString())}', ); - current.useGitCache = gitCache; - shouldSave = true; + updatedConfig = currentConfig.copyWith(useGitCache: gitCache); } if (wasParsed(ConfigKeys.cachePath.paramKey)) { final cachePath = stringArg(ConfigKeys.cachePath.paramKey); logger.info('Setting fvm path to: ${yellow.wrap(cachePath)}'); - current.cachePath = cachePath; - shouldSave = true; + updatedConfig = currentConfig.copyWith(cachePath: cachePath); + } + + if (wasParsed(ConfigKeys.priviledgedAccess.paramKey)) { + final priviledgedAccess = boolArg(ConfigKeys.priviledgedAccess.paramKey); + logger.info( + 'Setting priviledged access to: ${yellow.wrap(priviledgedAccess.toString())}', + ); + updatedConfig = + currentConfig.copyWith(priviledgedAccess: priviledgedAccess); } // Save - if (shouldSave) { + if (updatedConfig != currentConfig) { logger.info(''); final updateProgress = logger.progress('Saving settings'); // Update settings try { - ConfigRepository.save(current); + ConfigRepository.save(currentConfig); } catch (error) { updateProgress.fail('Failed to save settings'); rethrow; @@ -84,7 +92,7 @@ class ConfigCommand extends BaseCommand { ..info('Located at ${ctx.configPath}') ..info(''); - final options = current.toMap(); + final options = currentConfig.toMap(); if (options.keys.isEmpty) { logger.info('No settings have been configured.'); diff --git a/lib/src/commands/update_command.dart b/lib/src/commands/update_command.dart index 3afe0901..47a93873 100644 --- a/lib/src/commands/update_command.dart +++ b/lib/src/commands/update_command.dart @@ -6,7 +6,7 @@ import 'package:pub_updater/pub_updater.dart'; import '../services/logger_service.dart'; import '../utils/constants.dart'; -import '../version.g.dart'; +import '../version.dart'; class UpdateCommand extends Command { static const String commandName = 'update'; diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 48533843..7c7d53ae 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -3,59 +3,48 @@ import 'dart:io'; import 'package:args/args.dart'; -import 'package:jsonc/jsonc.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import '../utils/change_case.dart'; import '../utils/constants.dart'; import '../utils/extensions.dart'; import '../utils/pretty_json.dart'; -class ConfigKeys { - final String key; +part 'config_model.mapper.dart'; - static const ConfigKeys cachePath = ConfigKeys('cache_path'); - static const ConfigKeys useGitCache = ConfigKeys('git_cache'); - static const ConfigKeys gitCachePath = ConfigKeys('git_cache_path'); - static const ConfigKeys flutterUrl = ConfigKeys('flutter_url'); - static const ConfigKeys priviledgedAccess = ConfigKeys('priviledged_access'); - static const ConfigKeys runPubGetOnSdkChanges = - ConfigKeys('run_pub_get_on_sdk_changes'); +@MappableEnum() +enum ConfigKeys { + cachePath(description: 'Path where $kPackageName will cache versions'), + useGitCache( + description: + 'Enable/Disable git cache globally, which is used for faster version installs.', + ), + gitCachePath(description: 'Path where local Git reference cache is stored'), + flutterUrl(description: 'Flutter repository Git URL to clone from'), - static const values = [ - cachePath, - useGitCache, - gitCachePath, - flutterUrl, - ]; + priviledgedAccess(description: 'Enable/Disable priviledged access for FVM'); - const ConfigKeys(this.key); + const ConfigKeys({required this.description}); - static ConfigKeys fromName(String name) { - return values.firstWhere((e) => e.key == name); - } + final String description; - static argResultsToMap(ArgResults argResults) { - final configMap = {}; + ChangeCase get _recase => ChangeCase(toString()); - for (final key in values) { - final value = argResults[key.paramKey]; - if (value != null) { - configMap[key.propKey] = value; - } - } + String get envKey => 'FVM_${_recase.constantCase}'; - return configMap; - } + String get paramKey => _recase.paramCase; + + String get propKey => _recase.camelCase; static injectArgParser(ArgParser argParser) { final configKeysFuncs = { - ConfigKeys.cachePath.key: () { + ConfigKeys.cachePath: () { argParser.addOption( ConfigKeys.cachePath.paramKey, help: 'Path where $kPackageName will cache versions', ); }, - ConfigKeys.useGitCache.key: () { + ConfigKeys.useGitCache: () { argParser.addFlag( ConfigKeys.useGitCache.paramKey, help: @@ -64,19 +53,19 @@ class ConfigKeys { negatable: true, ); }, - ConfigKeys.gitCachePath.key: () { + ConfigKeys.gitCachePath: () { argParser.addOption( ConfigKeys.gitCachePath.paramKey, help: 'Path where local Git reference cache is stored', ); }, - ConfigKeys.flutterUrl.key: () { + ConfigKeys.flutterUrl: () { argParser.addOption( ConfigKeys.flutterUrl.paramKey, help: 'Flutter repository Git URL to clone from', ); }, - ConfigKeys.priviledgedAccess.key: () { + ConfigKeys.priviledgedAccess: () { argParser.addFlag( ConfigKeys.priviledgedAccess.paramKey, help: 'Enable/Disable priviledged access for FVM', @@ -86,97 +75,103 @@ class ConfigKeys { }, }; - for (final key in values) { - configKeysFuncs[key.key]?.call(); + for (final key in ConfigKeys.values) { + configKeysFuncs[key]?.call(); } } - - ChangeCase get _recase => ChangeCase(key); - - String get envKey => 'FVM_${_recase.constantCase}'; - String get paramKey => _recase.paramCase; - String get propKey => _recase.camelCase; - - @override - operator ==(Object other) => other is ConfigKeys && other.key == key; - - @override - int get hashCode => key.hashCode; } -class Config { +@MappableClass() +abstract class BaseConfig with BaseConfigMappable { // If should use gitCache - bool? useGitCache; + final bool? useGitCache; - String? gitCachePath; + final String? gitCachePath; /// Flutter repo url - String? flutterUrl; + final String? flutterUrl; /// Directory where FVM is stored - String? cachePath; - - /// If FVM should run with priviledged access - bool? priviledgedAccess; - - // Run pub get on sdk changes - bool? runPubGetOnSdkChanges; + final String? cachePath; /// Constructor - Config({ + const BaseConfig({ required this.cachePath, required this.useGitCache, required this.gitCachePath, required this.flutterUrl, - required this.priviledgedAccess, - required this.runPubGetOnSdkChanges, }); +} - factory Config.empty() { - return Config( +@MappableClass() +class EnvConfig extends BaseConfig with EnvConfigMappable { + static final fromMap = EnvConfigMapper.fromMap; + static final fromJson = EnvConfigMapper.fromJson; + + const EnvConfig({ + required super.cachePath, + required super.useGitCache, + required super.gitCachePath, + required super.flutterUrl, + }); + + static EnvConfig empty() { + return EnvConfig( cachePath: null, useGitCache: null, gitCachePath: null, flutterUrl: null, - priviledgedAccess: null, - runPubGetOnSdkChanges: null, ); } +} - factory Config.fromMap(Map map) { - return Config( - cachePath: map[ConfigKeys.cachePath.propKey] as String?, - useGitCache: map[ConfigKeys.useGitCache.propKey] as bool?, - gitCachePath: map[ConfigKeys.gitCachePath.propKey] as String?, - flutterUrl: map[ConfigKeys.flutterUrl.propKey] as String?, - priviledgedAccess: map[ConfigKeys.priviledgedAccess.propKey] as bool?, - runPubGetOnSdkChanges: - map[ConfigKeys.runPubGetOnSdkChanges.propKey] as bool?, - ); - } +@MappableClass() +class FileConfig extends BaseConfig with FileConfigMappable { + /// If Vscode settings is not managed by FVM + final bool? updateVscodeSettings; - Map toMap() { - return { - if (cachePath != null) ConfigKeys.cachePath.propKey: cachePath, - if (useGitCache != null) ConfigKeys.useGitCache.propKey: useGitCache, - if (gitCachePath != null) ConfigKeys.gitCachePath.propKey: gitCachePath, - if (flutterUrl != null) ConfigKeys.flutterUrl.propKey: flutterUrl, - if (priviledgedAccess != null) - ConfigKeys.priviledgedAccess.propKey: priviledgedAccess, - if (runPubGetOnSdkChanges != null) - ConfigKeys.runPubGetOnSdkChanges.propKey: runPubGetOnSdkChanges, - }; + /// If FVM should update .gitignore + final bool? updateGitIgnore; + + final bool? runPubGetOnSdkChanges; + + /// If FVM should run with priviledged access + final bool? priviledgedAccess; + + static final fromMap = FileConfigMapper.fromMap; + static final fromJson = FileConfigMapper.fromJson; + + /// Constructor + const FileConfig({ + required super.cachePath, + required super.useGitCache, + required super.gitCachePath, + required super.flutterUrl, + required this.priviledgedAccess, + required this.runPubGetOnSdkChanges, + required this.updateVscodeSettings, + required this.updateGitIgnore, + }); + + void save(String path) { + final jsonContents = prettyJson(toMap()); + + path.file.write(jsonContents); } } -/// App config -class AppConfig extends Config { +@MappableClass() +class AppConfig extends FileConfig with AppConfigMappable { /// Disables update notification - bool? disableUpdateCheck; - DateTime? lastUpdateCheck; + + final bool? disableUpdateCheck; + final DateTime? lastUpdateCheck; + + static final fromMap = AppConfigMapper.fromMap; + static final fromJson = AppConfigMapper.fromJson; /// Constructor - AppConfig({ + const AppConfig({ required this.disableUpdateCheck, required this.lastUpdateCheck, required super.cachePath, @@ -185,9 +180,11 @@ class AppConfig extends Config { required super.flutterUrl, required super.priviledgedAccess, required super.runPubGetOnSdkChanges, + required super.updateVscodeSettings, + required super.updateGitIgnore, }); - factory AppConfig.empty() { + static AppConfig empty() { return AppConfig( disableUpdateCheck: null, lastUpdateCheck: null, @@ -197,30 +194,11 @@ class AppConfig extends Config { flutterUrl: null, priviledgedAccess: null, runPubGetOnSdkChanges: null, + updateVscodeSettings: null, + updateGitIgnore: null, ); } - factory AppConfig.fromMap(Map map) { - final envConfig = Config.fromMap(map); - - return AppConfig( - disableUpdateCheck: map['disableUpdateCheck'] as bool?, - lastUpdateCheck: map['lastUpdateCheck'] != null - ? DateTime.parse(map['lastUpdateCheck'] as String) - : null, - cachePath: envConfig.cachePath, - useGitCache: envConfig.useGitCache, - gitCachePath: envConfig.gitCachePath, - flutterUrl: envConfig.flutterUrl, - priviledgedAccess: envConfig.priviledgedAccess, - runPubGetOnSdkChanges: envConfig.runPubGetOnSdkChanges, - ); - } - - factory AppConfig.fromJson(String source) { - return AppConfig.fromMap(jsonc.decode(source) as Map); - } - static AppConfig? loadFromPath(String path) { final configFile = File(path); @@ -229,114 +207,92 @@ class AppConfig extends Config { : null; } - AppConfig copyWith({ - String? cachePath, - bool? useGitCache, - String? gitCachePath, - String? flutterUrl, - bool? disableUpdateCheck, - DateTime? lastUpdateCheck, - bool? priviledgedAccess, - bool? runPubGetOnSdkChanges, - }) { - return AppConfig( - disableUpdateCheck: disableUpdateCheck ?? this.disableUpdateCheck, - lastUpdateCheck: lastUpdateCheck ?? this.lastUpdateCheck, - cachePath: cachePath ?? this.cachePath, - useGitCache: useGitCache ?? this.useGitCache, - gitCachePath: gitCachePath ?? this.gitCachePath, - flutterUrl: flutterUrl ?? this.flutterUrl, - priviledgedAccess: priviledgedAccess ?? this.priviledgedAccess, - runPubGetOnSdkChanges: - runPubGetOnSdkChanges ?? this.runPubGetOnSdkChanges, - ); - } + AppConfig merge(BaseConfig? config) { + if (config == null) return this; + if (config is EnvConfig) { + return copyWith( + cachePath: config.cachePath, + disableUpdateCheck: disableUpdateCheck, + flutterUrl: config.flutterUrl, + gitCachePath: config.gitCachePath, + useGitCache: config.useGitCache, + ); + } - AppConfig merge(AppConfig? config) { - return copyWith( - cachePath: config?.cachePath, - useGitCache: config?.useGitCache, - gitCachePath: config?.gitCachePath, - flutterUrl: config?.flutterUrl, - disableUpdateCheck: config?.disableUpdateCheck, - lastUpdateCheck: config?.lastUpdateCheck, - priviledgedAccess: config?.priviledgedAccess, - runPubGetOnSdkChanges: config?.runPubGetOnSdkChanges, - ); - } + if (config is ProjectConfig) { + return copyWith( + cachePath: config.cachePath, + flutterUrl: config.flutterUrl, + gitCachePath: config.gitCachePath, + priviledgedAccess: config.priviledgedAccess, + runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, + updateGitIgnore: config.updateGitIgnore, + updateVscodeSettings: config.updateVscodeSettings, + useGitCache: config.useGitCache, + ); + } + + if (config is AppConfig) { + return copyWith( + cachePath: config.cachePath, + disableUpdateCheck: config.disableUpdateCheck, + flutterUrl: config.flutterUrl, + gitCachePath: config.gitCachePath, + lastUpdateCheck: config.lastUpdateCheck, + priviledgedAccess: config.priviledgedAccess, + runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, + updateGitIgnore: config.updateGitIgnore, + updateVscodeSettings: config.updateVscodeSettings, + useGitCache: config.useGitCache, + ); + } - AppConfig mergeConfig(Config? config) { return copyWith( - cachePath: config?.cachePath, - useGitCache: config?.useGitCache, - gitCachePath: config?.gitCachePath, - flutterUrl: config?.flutterUrl, - priviledgedAccess: config?.priviledgedAccess, - runPubGetOnSdkChanges: config?.runPubGetOnSdkChanges, + cachePath: config.cachePath, + flutterUrl: config.flutterUrl, + gitCachePath: config.gitCachePath, + useGitCache: config.useGitCache, ); } - - @override - Map toMap() { - return { - ...super.toMap(), - if (disableUpdateCheck != null) 'disableUpdateCheck': disableUpdateCheck, - if (lastUpdateCheck != null) - 'lastUpdateCheck': lastUpdateCheck?.toIso8601String(), - }; - } } /// Project config -class ProjectConfig extends Config { - /// Flutter SDK version configured - String? flutterSdkVersion; - - /// Flavors configured - Map? flavors; +@MappableClass() +class ProjectConfig extends FileConfig with ProjectConfigMappable { + final String? flutterSdkVersion; + final Map? flavors; - /// If Vscode settings is not managed by FVM - bool? updateVscodeSettings; - - /// If FVM should update .gitignore - bool? updateGitIgnore; + static final fromJson = ProjectConfigMapper.fromJson; /// Constructor - ProjectConfig({ - super.cachePath, - super.useGitCache, - super.gitCachePath, - super.flutterUrl, - super.priviledgedAccess, - super.runPubGetOnSdkChanges, - this.flutterSdkVersion, - this.flavors, - this.updateVscodeSettings, - this.updateGitIgnore, + const ProjectConfig({ + required this.flutterSdkVersion, + required this.flavors, + required super.cachePath, + required super.useGitCache, + required super.gitCachePath, + required super.flutterUrl, + required super.priviledgedAccess, + required super.runPubGetOnSdkChanges, + required super.updateVscodeSettings, + required super.updateGitIgnore, }); - /// Returns ConfigDto from a map - factory ProjectConfig.fromMap(Map map) { - final envConfig = Config.fromMap(map); - + static ProjectConfig empty() { return ProjectConfig( - cachePath: envConfig.cachePath, - useGitCache: envConfig.useGitCache, - gitCachePath: envConfig.gitCachePath, - flutterUrl: envConfig.flutterUrl, - priviledgedAccess: envConfig.priviledgedAccess, - runPubGetOnSdkChanges: envConfig.runPubGetOnSdkChanges, - 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?, + flutterSdkVersion: null, + flavors: null, + cachePath: null, + useGitCache: null, + gitCachePath: null, + flutterUrl: null, + priviledgedAccess: null, + runPubGetOnSdkChanges: null, + updateVscodeSettings: null, + updateGitIgnore: null, ); } - /// Returns ConfigDto from a json string - factory ProjectConfig.fromJson(String source) => - ProjectConfig.fromMap(jsonc.decode(source) as Map); - static ProjectConfig? loadFromPath(String path) { final configFile = File(path); @@ -345,62 +301,11 @@ class ProjectConfig extends Config { : null; } - /// Copies current config and overrides with new values - /// Returns a new ConfigDto - - ProjectConfig copyWith({ - String? cachePath, - String? flutterSdkVersion, - bool? useGitCache, - bool? updateVscodeSettings, - bool? updateGitIgnore, - bool? runPubGetOnSdkChanges, - bool? priviledgedAccess, - String? gitCachePath, - String? flutterUrl, - Map? flavors, - }) { - // merge map and override the keys - final mergedFlavors = { - if (this.flavors != null) ...?this.flavors, - // ignore: prefer-null-aware-spread - if (flavors != null) ...flavors, - }; - - return ProjectConfig( - cachePath: cachePath ?? this.cachePath, - useGitCache: useGitCache ?? this.useGitCache, - gitCachePath: gitCachePath ?? this.gitCachePath, - flutterUrl: flutterUrl ?? this.flutterUrl, - priviledgedAccess: priviledgedAccess ?? this.priviledgedAccess, - runPubGetOnSdkChanges: - runPubGetOnSdkChanges ?? this.runPubGetOnSdkChanges, - flutterSdkVersion: flutterSdkVersion ?? this.flutterSdkVersion, - flavors: mergedFlavors, - updateVscodeSettings: updateVscodeSettings ?? this.updateVscodeSettings, - updateGitIgnore: updateGitIgnore ?? this.updateGitIgnore, - ); - } - - ProjectConfig merge(ProjectConfig config) { - return copyWith( - cachePath: config.cachePath, - flutterSdkVersion: config.flutterSdkVersion, - useGitCache: config.useGitCache, - updateVscodeSettings: config.updateVscodeSettings, - updateGitIgnore: config.updateGitIgnore, - runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, - priviledgedAccess: config.priviledgedAccess, - gitCachePath: config.gitCachePath, - flutterUrl: config.flutterUrl, - flavors: config.flavors, - ); - } - - void save(String path) { - final jsonContents = prettyJson(toMap()); - - path.file.write(jsonContents); + ProjectConfig fromMap(Map map) { + return ProjectConfigMapper.fromMap({ + ...map, + 'flutterSdkVersion': map['flutterSdkVersion'] ?? map['flutter'], + }); } Map toLegacyMap() { @@ -409,21 +314,4 @@ class ProjectConfig extends Config { if (flavors != null && flavors!.isNotEmpty) 'flavors': flavors, }; } - - /// It checks each property for null prior to adding it to the map. - /// This is to ensure the returned map doesn't contain any null values. - /// Also, if [flavors] is not empty it adds it to the map. - - @override - Map toMap() { - return { - ...super.toMap(), - if (flutterSdkVersion != null) 'flutter': flutterSdkVersion, - if (updateVscodeSettings != null) - 'updateVscodeSettings': updateVscodeSettings, - if (updateGitIgnore != null) 'updateGitIgnore': updateGitIgnore, - 'runPubGetOnSdkChanges': runPubGetOnSdkChanges, - if (flavors != null && flavors!.isNotEmpty) 'flavors': flavors, - }; - } } diff --git a/lib/src/models/config_model.mapper.dart b/lib/src/models/config_model.mapper.dart new file mode 100644 index 00000000..6b77670c --- /dev/null +++ b/lib/src/models/config_model.mapper.dart @@ -0,0 +1,866 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of 'config_model.dart'; + +class ConfigKeysMapper extends EnumMapper { + ConfigKeysMapper._(); + + static ConfigKeysMapper? _instance; + static ConfigKeysMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ConfigKeysMapper._()); + } + return _instance!; + } + + static ConfigKeys fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + ConfigKeys decode(dynamic value) { + switch (value) { + case 'cachePath': + return ConfigKeys.cachePath; + case 'useGitCache': + return ConfigKeys.useGitCache; + case 'gitCachePath': + return ConfigKeys.gitCachePath; + case 'flutterUrl': + return ConfigKeys.flutterUrl; + case 'priviledgedAccess': + return ConfigKeys.priviledgedAccess; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(ConfigKeys self) { + switch (self) { + case ConfigKeys.cachePath: + return 'cachePath'; + case ConfigKeys.useGitCache: + return 'useGitCache'; + case ConfigKeys.gitCachePath: + return 'gitCachePath'; + case ConfigKeys.flutterUrl: + return 'flutterUrl'; + case ConfigKeys.priviledgedAccess: + return 'priviledgedAccess'; + } + } +} + +extension ConfigKeysMapperExtension on ConfigKeys { + String toValue() { + ConfigKeysMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class BaseConfigMapper extends ClassMapperBase { + BaseConfigMapper._(); + + static BaseConfigMapper? _instance; + static BaseConfigMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = BaseConfigMapper._()); + EnvConfigMapper.ensureInitialized(); + FileConfigMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'BaseConfig'; + + static String? _$cachePath(BaseConfig v) => v.cachePath; + static const Field _f$cachePath = + Field('cachePath', _$cachePath); + static bool? _$useGitCache(BaseConfig v) => v.useGitCache; + static const Field _f$useGitCache = + Field('useGitCache', _$useGitCache); + static String? _$gitCachePath(BaseConfig v) => v.gitCachePath; + static const Field _f$gitCachePath = + Field('gitCachePath', _$gitCachePath); + static String? _$flutterUrl(BaseConfig v) => v.flutterUrl; + static const Field _f$flutterUrl = + Field('flutterUrl', _$flutterUrl); + + @override + final MappableFields fields = const { + #cachePath: _f$cachePath, + #useGitCache: _f$useGitCache, + #gitCachePath: _f$gitCachePath, + #flutterUrl: _f$flutterUrl, + }; + + static BaseConfig _instantiate(DecodingData data) { + throw MapperException.missingConstructor('BaseConfig'); + } + + @override + final Function instantiate = _instantiate; + + static BaseConfig fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static BaseConfig fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin BaseConfigMappable { + String toJson(); + Map toMap(); + BaseConfigCopyWith get copyWith; +} + +abstract class BaseConfigCopyWith<$R, $In extends BaseConfig, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call( + {String? cachePath, + bool? useGitCache, + String? gitCachePath, + String? flutterUrl}); + BaseConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class EnvConfigMapper extends ClassMapperBase { + EnvConfigMapper._(); + + static EnvConfigMapper? _instance; + static EnvConfigMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = EnvConfigMapper._()); + BaseConfigMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'EnvConfig'; + + static String? _$cachePath(EnvConfig v) => v.cachePath; + static const Field _f$cachePath = + Field('cachePath', _$cachePath); + static bool? _$useGitCache(EnvConfig v) => v.useGitCache; + static const Field _f$useGitCache = + Field('useGitCache', _$useGitCache); + static String? _$gitCachePath(EnvConfig v) => v.gitCachePath; + static const Field _f$gitCachePath = + Field('gitCachePath', _$gitCachePath); + static String? _$flutterUrl(EnvConfig v) => v.flutterUrl; + static const Field _f$flutterUrl = + Field('flutterUrl', _$flutterUrl); + + @override + final MappableFields fields = const { + #cachePath: _f$cachePath, + #useGitCache: _f$useGitCache, + #gitCachePath: _f$gitCachePath, + #flutterUrl: _f$flutterUrl, + }; + + static EnvConfig _instantiate(DecodingData data) { + return EnvConfig( + cachePath: data.dec(_f$cachePath), + useGitCache: data.dec(_f$useGitCache), + gitCachePath: data.dec(_f$gitCachePath), + flutterUrl: data.dec(_f$flutterUrl)); + } + + @override + final Function instantiate = _instantiate; + + static EnvConfig fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static EnvConfig fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin EnvConfigMappable { + String toJson() { + return EnvConfigMapper.ensureInitialized() + .encodeJson(this as EnvConfig); + } + + Map toMap() { + return EnvConfigMapper.ensureInitialized() + .encodeMap(this as EnvConfig); + } + + EnvConfigCopyWith get copyWith => + _EnvConfigCopyWithImpl(this as EnvConfig, $identity, $identity); + @override + String toString() { + return EnvConfigMapper.ensureInitialized() + .stringifyValue(this as EnvConfig); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (runtimeType == other.runtimeType && + EnvConfigMapper.ensureInitialized() + .isValueEqual(this as EnvConfig, other)); + } + + @override + int get hashCode { + return EnvConfigMapper.ensureInitialized().hashValue(this as EnvConfig); + } +} + +extension EnvConfigValueCopy<$R, $Out> on ObjectCopyWith<$R, EnvConfig, $Out> { + EnvConfigCopyWith<$R, EnvConfig, $Out> get $asEnvConfig => + $base.as((v, t, t2) => _EnvConfigCopyWithImpl(v, t, t2)); +} + +abstract class EnvConfigCopyWith<$R, $In extends EnvConfig, $Out> + implements BaseConfigCopyWith<$R, $In, $Out> { + @override + $R call( + {String? cachePath, + bool? useGitCache, + String? gitCachePath, + String? flutterUrl}); + EnvConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _EnvConfigCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, EnvConfig, $Out> + implements EnvConfigCopyWith<$R, EnvConfig, $Out> { + _EnvConfigCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + EnvConfigMapper.ensureInitialized(); + @override + $R call( + {Object? cachePath = $none, + Object? useGitCache = $none, + Object? gitCachePath = $none, + Object? flutterUrl = $none}) => + $apply(FieldCopyWithData({ + if (cachePath != $none) #cachePath: cachePath, + if (useGitCache != $none) #useGitCache: useGitCache, + if (gitCachePath != $none) #gitCachePath: gitCachePath, + if (flutterUrl != $none) #flutterUrl: flutterUrl + })); + @override + EnvConfig $make(CopyWithData data) => EnvConfig( + cachePath: data.get(#cachePath, or: $value.cachePath), + useGitCache: data.get(#useGitCache, or: $value.useGitCache), + gitCachePath: data.get(#gitCachePath, or: $value.gitCachePath), + flutterUrl: data.get(#flutterUrl, or: $value.flutterUrl)); + + @override + EnvConfigCopyWith<$R2, EnvConfig, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t) => + _EnvConfigCopyWithImpl($value, $cast, t); +} + +class FileConfigMapper extends ClassMapperBase { + FileConfigMapper._(); + + static FileConfigMapper? _instance; + static FileConfigMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = FileConfigMapper._()); + BaseConfigMapper.ensureInitialized(); + AppConfigMapper.ensureInitialized(); + ProjectConfigMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'FileConfig'; + + static String? _$cachePath(FileConfig v) => v.cachePath; + static const Field _f$cachePath = + Field('cachePath', _$cachePath); + static bool? _$useGitCache(FileConfig v) => v.useGitCache; + static const Field _f$useGitCache = + Field('useGitCache', _$useGitCache); + static String? _$gitCachePath(FileConfig v) => v.gitCachePath; + static const Field _f$gitCachePath = + Field('gitCachePath', _$gitCachePath); + static String? _$flutterUrl(FileConfig v) => v.flutterUrl; + static const Field _f$flutterUrl = + Field('flutterUrl', _$flutterUrl); + static bool? _$priviledgedAccess(FileConfig v) => v.priviledgedAccess; + static const Field _f$priviledgedAccess = + Field('priviledgedAccess', _$priviledgedAccess); + static bool? _$runPubGetOnSdkChanges(FileConfig v) => v.runPubGetOnSdkChanges; + static const Field _f$runPubGetOnSdkChanges = + Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges); + static bool? _$updateVscodeSettings(FileConfig v) => v.updateVscodeSettings; + static const Field _f$updateVscodeSettings = + Field('updateVscodeSettings', _$updateVscodeSettings); + static bool? _$updateGitIgnore(FileConfig v) => v.updateGitIgnore; + static const Field _f$updateGitIgnore = + Field('updateGitIgnore', _$updateGitIgnore); + + @override + final MappableFields fields = const { + #cachePath: _f$cachePath, + #useGitCache: _f$useGitCache, + #gitCachePath: _f$gitCachePath, + #flutterUrl: _f$flutterUrl, + #priviledgedAccess: _f$priviledgedAccess, + #runPubGetOnSdkChanges: _f$runPubGetOnSdkChanges, + #updateVscodeSettings: _f$updateVscodeSettings, + #updateGitIgnore: _f$updateGitIgnore, + }; + + static FileConfig _instantiate(DecodingData data) { + return FileConfig( + cachePath: data.dec(_f$cachePath), + useGitCache: data.dec(_f$useGitCache), + gitCachePath: data.dec(_f$gitCachePath), + flutterUrl: data.dec(_f$flutterUrl), + priviledgedAccess: data.dec(_f$priviledgedAccess), + runPubGetOnSdkChanges: data.dec(_f$runPubGetOnSdkChanges), + updateVscodeSettings: data.dec(_f$updateVscodeSettings), + updateGitIgnore: data.dec(_f$updateGitIgnore)); + } + + @override + final Function instantiate = _instantiate; + + static FileConfig fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static FileConfig fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin FileConfigMappable { + String toJson() { + return FileConfigMapper.ensureInitialized() + .encodeJson(this as FileConfig); + } + + Map toMap() { + return FileConfigMapper.ensureInitialized() + .encodeMap(this as FileConfig); + } + + FileConfigCopyWith get copyWith => + _FileConfigCopyWithImpl(this as FileConfig, $identity, $identity); + @override + String toString() { + return FileConfigMapper.ensureInitialized() + .stringifyValue(this as FileConfig); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (runtimeType == other.runtimeType && + FileConfigMapper.ensureInitialized() + .isValueEqual(this as FileConfig, other)); + } + + @override + int get hashCode { + return FileConfigMapper.ensureInitialized().hashValue(this as FileConfig); + } +} + +extension FileConfigValueCopy<$R, $Out> + on ObjectCopyWith<$R, FileConfig, $Out> { + FileConfigCopyWith<$R, FileConfig, $Out> get $asFileConfig => + $base.as((v, t, t2) => _FileConfigCopyWithImpl(v, t, t2)); +} + +abstract class FileConfigCopyWith<$R, $In extends FileConfig, $Out> + implements BaseConfigCopyWith<$R, $In, $Out> { + @override + $R call( + {String? cachePath, + bool? useGitCache, + String? gitCachePath, + String? flutterUrl, + bool? priviledgedAccess, + bool? runPubGetOnSdkChanges, + bool? updateVscodeSettings, + bool? updateGitIgnore}); + FileConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _FileConfigCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, FileConfig, $Out> + implements FileConfigCopyWith<$R, FileConfig, $Out> { + _FileConfigCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + FileConfigMapper.ensureInitialized(); + @override + $R call( + {Object? cachePath = $none, + Object? useGitCache = $none, + Object? gitCachePath = $none, + Object? flutterUrl = $none, + Object? priviledgedAccess = $none, + Object? runPubGetOnSdkChanges = $none, + Object? updateVscodeSettings = $none, + Object? updateGitIgnore = $none}) => + $apply(FieldCopyWithData({ + if (cachePath != $none) #cachePath: cachePath, + if (useGitCache != $none) #useGitCache: useGitCache, + if (gitCachePath != $none) #gitCachePath: gitCachePath, + if (flutterUrl != $none) #flutterUrl: flutterUrl, + if (priviledgedAccess != $none) #priviledgedAccess: priviledgedAccess, + if (runPubGetOnSdkChanges != $none) + #runPubGetOnSdkChanges: runPubGetOnSdkChanges, + if (updateVscodeSettings != $none) + #updateVscodeSettings: updateVscodeSettings, + if (updateGitIgnore != $none) #updateGitIgnore: updateGitIgnore + })); + @override + FileConfig $make(CopyWithData data) => FileConfig( + cachePath: data.get(#cachePath, or: $value.cachePath), + useGitCache: data.get(#useGitCache, or: $value.useGitCache), + gitCachePath: data.get(#gitCachePath, or: $value.gitCachePath), + flutterUrl: data.get(#flutterUrl, or: $value.flutterUrl), + priviledgedAccess: + data.get(#priviledgedAccess, or: $value.priviledgedAccess), + runPubGetOnSdkChanges: + data.get(#runPubGetOnSdkChanges, or: $value.runPubGetOnSdkChanges), + updateVscodeSettings: + data.get(#updateVscodeSettings, or: $value.updateVscodeSettings), + updateGitIgnore: data.get(#updateGitIgnore, or: $value.updateGitIgnore)); + + @override + FileConfigCopyWith<$R2, FileConfig, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t) => + _FileConfigCopyWithImpl($value, $cast, t); +} + +class AppConfigMapper extends ClassMapperBase { + AppConfigMapper._(); + + static AppConfigMapper? _instance; + static AppConfigMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = AppConfigMapper._()); + FileConfigMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'AppConfig'; + + static bool? _$disableUpdateCheck(AppConfig v) => v.disableUpdateCheck; + static const Field _f$disableUpdateCheck = + Field('disableUpdateCheck', _$disableUpdateCheck); + static DateTime? _$lastUpdateCheck(AppConfig v) => v.lastUpdateCheck; + static const Field _f$lastUpdateCheck = + Field('lastUpdateCheck', _$lastUpdateCheck); + static String? _$cachePath(AppConfig v) => v.cachePath; + static const Field _f$cachePath = + Field('cachePath', _$cachePath); + static bool? _$useGitCache(AppConfig v) => v.useGitCache; + static const Field _f$useGitCache = + Field('useGitCache', _$useGitCache); + static String? _$gitCachePath(AppConfig v) => v.gitCachePath; + static const Field _f$gitCachePath = + Field('gitCachePath', _$gitCachePath); + static String? _$flutterUrl(AppConfig v) => v.flutterUrl; + static const Field _f$flutterUrl = + Field('flutterUrl', _$flutterUrl); + static bool? _$priviledgedAccess(AppConfig v) => v.priviledgedAccess; + static const Field _f$priviledgedAccess = + Field('priviledgedAccess', _$priviledgedAccess); + static bool? _$runPubGetOnSdkChanges(AppConfig v) => v.runPubGetOnSdkChanges; + static const Field _f$runPubGetOnSdkChanges = + Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges); + static bool? _$updateVscodeSettings(AppConfig v) => v.updateVscodeSettings; + static const Field _f$updateVscodeSettings = + Field('updateVscodeSettings', _$updateVscodeSettings); + static bool? _$updateGitIgnore(AppConfig v) => v.updateGitIgnore; + static const Field _f$updateGitIgnore = + Field('updateGitIgnore', _$updateGitIgnore); + + @override + final MappableFields fields = const { + #disableUpdateCheck: _f$disableUpdateCheck, + #lastUpdateCheck: _f$lastUpdateCheck, + #cachePath: _f$cachePath, + #useGitCache: _f$useGitCache, + #gitCachePath: _f$gitCachePath, + #flutterUrl: _f$flutterUrl, + #priviledgedAccess: _f$priviledgedAccess, + #runPubGetOnSdkChanges: _f$runPubGetOnSdkChanges, + #updateVscodeSettings: _f$updateVscodeSettings, + #updateGitIgnore: _f$updateGitIgnore, + }; + + static AppConfig _instantiate(DecodingData data) { + return AppConfig( + disableUpdateCheck: data.dec(_f$disableUpdateCheck), + lastUpdateCheck: data.dec(_f$lastUpdateCheck), + cachePath: data.dec(_f$cachePath), + useGitCache: data.dec(_f$useGitCache), + gitCachePath: data.dec(_f$gitCachePath), + flutterUrl: data.dec(_f$flutterUrl), + priviledgedAccess: data.dec(_f$priviledgedAccess), + runPubGetOnSdkChanges: data.dec(_f$runPubGetOnSdkChanges), + updateVscodeSettings: data.dec(_f$updateVscodeSettings), + updateGitIgnore: data.dec(_f$updateGitIgnore)); + } + + @override + final Function instantiate = _instantiate; + + static AppConfig fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static AppConfig fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin AppConfigMappable { + String toJson() { + return AppConfigMapper.ensureInitialized() + .encodeJson(this as AppConfig); + } + + Map toMap() { + return AppConfigMapper.ensureInitialized() + .encodeMap(this as AppConfig); + } + + AppConfigCopyWith get copyWith => + _AppConfigCopyWithImpl(this as AppConfig, $identity, $identity); + @override + String toString() { + return AppConfigMapper.ensureInitialized() + .stringifyValue(this as AppConfig); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (runtimeType == other.runtimeType && + AppConfigMapper.ensureInitialized() + .isValueEqual(this as AppConfig, other)); + } + + @override + int get hashCode { + return AppConfigMapper.ensureInitialized().hashValue(this as AppConfig); + } +} + +extension AppConfigValueCopy<$R, $Out> on ObjectCopyWith<$R, AppConfig, $Out> { + AppConfigCopyWith<$R, AppConfig, $Out> get $asAppConfig => + $base.as((v, t, t2) => _AppConfigCopyWithImpl(v, t, t2)); +} + +abstract class AppConfigCopyWith<$R, $In extends AppConfig, $Out> + implements FileConfigCopyWith<$R, $In, $Out> { + @override + $R call( + {bool? disableUpdateCheck, + DateTime? lastUpdateCheck, + String? cachePath, + bool? useGitCache, + String? gitCachePath, + String? flutterUrl, + bool? priviledgedAccess, + bool? runPubGetOnSdkChanges, + bool? updateVscodeSettings, + bool? updateGitIgnore}); + AppConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _AppConfigCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, AppConfig, $Out> + implements AppConfigCopyWith<$R, AppConfig, $Out> { + _AppConfigCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + AppConfigMapper.ensureInitialized(); + @override + $R call( + {Object? disableUpdateCheck = $none, + Object? lastUpdateCheck = $none, + Object? cachePath = $none, + Object? useGitCache = $none, + Object? gitCachePath = $none, + Object? flutterUrl = $none, + Object? priviledgedAccess = $none, + Object? runPubGetOnSdkChanges = $none, + Object? updateVscodeSettings = $none, + Object? updateGitIgnore = $none}) => + $apply(FieldCopyWithData({ + if (disableUpdateCheck != $none) + #disableUpdateCheck: disableUpdateCheck, + if (lastUpdateCheck != $none) #lastUpdateCheck: lastUpdateCheck, + if (cachePath != $none) #cachePath: cachePath, + if (useGitCache != $none) #useGitCache: useGitCache, + if (gitCachePath != $none) #gitCachePath: gitCachePath, + if (flutterUrl != $none) #flutterUrl: flutterUrl, + if (priviledgedAccess != $none) #priviledgedAccess: priviledgedAccess, + if (runPubGetOnSdkChanges != $none) + #runPubGetOnSdkChanges: runPubGetOnSdkChanges, + if (updateVscodeSettings != $none) + #updateVscodeSettings: updateVscodeSettings, + if (updateGitIgnore != $none) #updateGitIgnore: updateGitIgnore + })); + @override + AppConfig $make(CopyWithData data) => AppConfig( + disableUpdateCheck: + data.get(#disableUpdateCheck, or: $value.disableUpdateCheck), + lastUpdateCheck: data.get(#lastUpdateCheck, or: $value.lastUpdateCheck), + cachePath: data.get(#cachePath, or: $value.cachePath), + useGitCache: data.get(#useGitCache, or: $value.useGitCache), + gitCachePath: data.get(#gitCachePath, or: $value.gitCachePath), + flutterUrl: data.get(#flutterUrl, or: $value.flutterUrl), + priviledgedAccess: + data.get(#priviledgedAccess, or: $value.priviledgedAccess), + runPubGetOnSdkChanges: + data.get(#runPubGetOnSdkChanges, or: $value.runPubGetOnSdkChanges), + updateVscodeSettings: + data.get(#updateVscodeSettings, or: $value.updateVscodeSettings), + updateGitIgnore: data.get(#updateGitIgnore, or: $value.updateGitIgnore)); + + @override + AppConfigCopyWith<$R2, AppConfig, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t) => + _AppConfigCopyWithImpl($value, $cast, t); +} + +class ProjectConfigMapper extends ClassMapperBase { + ProjectConfigMapper._(); + + static ProjectConfigMapper? _instance; + static ProjectConfigMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ProjectConfigMapper._()); + FileConfigMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'ProjectConfig'; + + static String? _$flutterSdkVersion(ProjectConfig v) => v.flutterSdkVersion; + static const Field _f$flutterSdkVersion = + Field('flutterSdkVersion', _$flutterSdkVersion); + static Map? _$flavors(ProjectConfig v) => v.flavors; + static const Field> _f$flavors = + Field('flavors', _$flavors); + static String? _$cachePath(ProjectConfig v) => v.cachePath; + static const Field _f$cachePath = + Field('cachePath', _$cachePath); + static bool? _$useGitCache(ProjectConfig v) => v.useGitCache; + static const Field _f$useGitCache = + Field('useGitCache', _$useGitCache); + static String? _$gitCachePath(ProjectConfig v) => v.gitCachePath; + static const Field _f$gitCachePath = + Field('gitCachePath', _$gitCachePath); + static String? _$flutterUrl(ProjectConfig v) => v.flutterUrl; + static const Field _f$flutterUrl = + Field('flutterUrl', _$flutterUrl); + static bool? _$priviledgedAccess(ProjectConfig v) => v.priviledgedAccess; + static const Field _f$priviledgedAccess = + Field('priviledgedAccess', _$priviledgedAccess); + static bool? _$runPubGetOnSdkChanges(ProjectConfig v) => + v.runPubGetOnSdkChanges; + static const Field _f$runPubGetOnSdkChanges = + Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges); + static bool? _$updateVscodeSettings(ProjectConfig v) => + v.updateVscodeSettings; + static const Field _f$updateVscodeSettings = + Field('updateVscodeSettings', _$updateVscodeSettings); + static bool? _$updateGitIgnore(ProjectConfig v) => v.updateGitIgnore; + static const Field _f$updateGitIgnore = + Field('updateGitIgnore', _$updateGitIgnore); + + @override + final MappableFields fields = const { + #flutterSdkVersion: _f$flutterSdkVersion, + #flavors: _f$flavors, + #cachePath: _f$cachePath, + #useGitCache: _f$useGitCache, + #gitCachePath: _f$gitCachePath, + #flutterUrl: _f$flutterUrl, + #priviledgedAccess: _f$priviledgedAccess, + #runPubGetOnSdkChanges: _f$runPubGetOnSdkChanges, + #updateVscodeSettings: _f$updateVscodeSettings, + #updateGitIgnore: _f$updateGitIgnore, + }; + + static ProjectConfig _instantiate(DecodingData data) { + return ProjectConfig( + flutterSdkVersion: data.dec(_f$flutterSdkVersion), + flavors: data.dec(_f$flavors), + cachePath: data.dec(_f$cachePath), + useGitCache: data.dec(_f$useGitCache), + gitCachePath: data.dec(_f$gitCachePath), + flutterUrl: data.dec(_f$flutterUrl), + priviledgedAccess: data.dec(_f$priviledgedAccess), + runPubGetOnSdkChanges: data.dec(_f$runPubGetOnSdkChanges), + updateVscodeSettings: data.dec(_f$updateVscodeSettings), + updateGitIgnore: data.dec(_f$updateGitIgnore)); + } + + @override + final Function instantiate = _instantiate; + + static ProjectConfig fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static ProjectConfig fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin ProjectConfigMappable { + String toJson() { + return ProjectConfigMapper.ensureInitialized() + .encodeJson(this as ProjectConfig); + } + + Map toMap() { + return ProjectConfigMapper.ensureInitialized() + .encodeMap(this as ProjectConfig); + } + + ProjectConfigCopyWith + get copyWith => _ProjectConfigCopyWithImpl( + this as ProjectConfig, $identity, $identity); + @override + String toString() { + return ProjectConfigMapper.ensureInitialized() + .stringifyValue(this as ProjectConfig); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (runtimeType == other.runtimeType && + ProjectConfigMapper.ensureInitialized() + .isValueEqual(this as ProjectConfig, other)); + } + + @override + int get hashCode { + return ProjectConfigMapper.ensureInitialized() + .hashValue(this as ProjectConfig); + } +} + +extension ProjectConfigValueCopy<$R, $Out> + on ObjectCopyWith<$R, ProjectConfig, $Out> { + ProjectConfigCopyWith<$R, ProjectConfig, $Out> get $asProjectConfig => + $base.as((v, t, t2) => _ProjectConfigCopyWithImpl(v, t, t2)); +} + +abstract class ProjectConfigCopyWith<$R, $In extends ProjectConfig, $Out> + implements FileConfigCopyWith<$R, $In, $Out> { + MapCopyWith<$R, String, String, ObjectCopyWith<$R, String, String>>? + get flavors; + @override + $R call( + {String? flutterSdkVersion, + Map? flavors, + String? cachePath, + bool? useGitCache, + String? gitCachePath, + String? flutterUrl, + bool? priviledgedAccess, + bool? runPubGetOnSdkChanges, + bool? updateVscodeSettings, + bool? updateGitIgnore}); + ProjectConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _ProjectConfigCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, ProjectConfig, $Out> + implements ProjectConfigCopyWith<$R, ProjectConfig, $Out> { + _ProjectConfigCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + ProjectConfigMapper.ensureInitialized(); + @override + MapCopyWith<$R, String, String, ObjectCopyWith<$R, String, String>>? + get flavors => $value.flavors != null + ? MapCopyWith( + $value.flavors!, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(flavors: v)) + : null; + @override + $R call( + {Object? flutterSdkVersion = $none, + Object? flavors = $none, + Object? cachePath = $none, + Object? useGitCache = $none, + Object? gitCachePath = $none, + Object? flutterUrl = $none, + Object? priviledgedAccess = $none, + Object? runPubGetOnSdkChanges = $none, + Object? updateVscodeSettings = $none, + Object? updateGitIgnore = $none}) => + $apply(FieldCopyWithData({ + if (flutterSdkVersion != $none) #flutterSdkVersion: flutterSdkVersion, + if (flavors != $none) #flavors: flavors, + if (cachePath != $none) #cachePath: cachePath, + if (useGitCache != $none) #useGitCache: useGitCache, + if (gitCachePath != $none) #gitCachePath: gitCachePath, + if (flutterUrl != $none) #flutterUrl: flutterUrl, + if (priviledgedAccess != $none) #priviledgedAccess: priviledgedAccess, + if (runPubGetOnSdkChanges != $none) + #runPubGetOnSdkChanges: runPubGetOnSdkChanges, + if (updateVscodeSettings != $none) + #updateVscodeSettings: updateVscodeSettings, + if (updateGitIgnore != $none) #updateGitIgnore: updateGitIgnore + })); + @override + ProjectConfig $make(CopyWithData data) => ProjectConfig( + flutterSdkVersion: + data.get(#flutterSdkVersion, or: $value.flutterSdkVersion), + flavors: data.get(#flavors, or: $value.flavors), + cachePath: data.get(#cachePath, or: $value.cachePath), + useGitCache: data.get(#useGitCache, or: $value.useGitCache), + gitCachePath: data.get(#gitCachePath, or: $value.gitCachePath), + flutterUrl: data.get(#flutterUrl, or: $value.flutterUrl), + priviledgedAccess: + data.get(#priviledgedAccess, or: $value.priviledgedAccess), + runPubGetOnSdkChanges: + data.get(#runPubGetOnSdkChanges, or: $value.runPubGetOnSdkChanges), + updateVscodeSettings: + data.get(#updateVscodeSettings, or: $value.updateVscodeSettings), + updateGitIgnore: data.get(#updateGitIgnore, or: $value.updateGitIgnore)); + + @override + ProjectConfigCopyWith<$R2, ProjectConfig, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t) => + _ProjectConfigCopyWithImpl($value, $cast, t); +} diff --git a/lib/src/runner.dart b/lib/src/runner.dart index c4383799..e16b8945 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -25,7 +25,7 @@ import 'utils/constants.dart'; import 'utils/context.dart'; import 'utils/deprecation_util.dart'; import 'utils/exceptions.dart'; -import 'version.g.dart'; +import 'version.dart'; /// Command Runner for FVM class FvmCommandRunner extends CommandRunner { diff --git a/lib/src/services/config_repository.dart b/lib/src/services/config_repository.dart index f930b489..941061ad 100644 --- a/lib/src/services/config_repository.dart +++ b/lib/src/services/config_repository.dart @@ -1,5 +1,7 @@ import 'dart:io'; +import 'package:path/path.dart' as path; + import '../models/config_model.dart'; import '../utils/constants.dart'; import '../utils/extensions.dart'; @@ -12,7 +14,15 @@ const String flutterGitUrl = 'FLUTTER_GIT_URL'; class ConfigRepository { const ConfigRepository._(); - static AppConfig loadFile() { + static AppConfig load({AppConfig? overrides}) { + final appConfig = loadAppConfig(); + final envConfig = _loadEnvironment(); + final projectConfig = _loadProjectConfig(); + + return appConfig.merge(envConfig).merge(projectConfig).merge(overrides); + } + + static AppConfig loadAppConfig() { final appConfig = AppConfig.loadFromPath(_configPath); if (appConfig != null) return appConfig; @@ -25,6 +35,25 @@ class ConfigRepository { _configPath.file.write(jsonContents); } + static ProjectConfig? _loadProjectConfig({Directory? directory}) { + // Get directory, defined root or current + directory ??= Directory.current; + + // Checks if the directory is root + final isRootDir = path.rootPrefix(directory.path) == directory.path; + + // Gets project from directory + final projectConfig = ProjectConfig.loadFromPath(directory.path); + + // If project has a config return it + if (projectConfig != null) return projectConfig; + + // Return working directory if has reached root + if (isRootDir) return null; + + return _loadProjectConfig(directory: directory.parent); + } + static void update({ String? cachePath, bool? useGitCache, @@ -32,57 +61,51 @@ class ConfigRepository { String? flutterUrl, bool? disableUpdateCheck, DateTime? lastUpdateCheck, + bool? priviledgedAccess, }) { - final currentConfig = loadFile(); + final currentConfig = loadAppConfig(); final newConfig = currentConfig.copyWith( cachePath: cachePath, - useGitCache: useGitCache, - gitCachePath: gitCachePath, - flutterUrl: flutterUrl, disableUpdateCheck: disableUpdateCheck, + flutterUrl: flutterUrl, + gitCachePath: gitCachePath, lastUpdateCheck: lastUpdateCheck, + priviledgedAccess: priviledgedAccess, + useGitCache: useGitCache, ); save(newConfig); } - static Config loadEnv() { + static EnvConfig _loadEnvironment() { final environments = Platform.environment; - final config = Config.empty(); + var config = EnvConfig.empty(); // Default to Flutter's environment variable if present; can still be overridden if (environments.containsKey(flutterGitUrl)) { - config.flutterUrl = environments[flutterGitUrl]; + config = config.copyWith(flutterUrl: environments[flutterGitUrl]); } - for (final variable in ConfigKeys.values) { - final value = environments[variable.envKey]; + for (final envVar in ConfigKeys.values) { + final value = environments[envVar.envKey]; final legacyFvmHome = environments['FVM_HOME']; - if (variable == ConfigKeys.cachePath) { - config.cachePath = value ?? legacyFvmHome; + if (envVar == ConfigKeys.cachePath) { + config = config.copyWith(cachePath: value ?? legacyFvmHome); } if (value == null) continue; - if (variable == ConfigKeys.useGitCache) { - config.useGitCache = stringToBool(value); - } - - if (variable == ConfigKeys.gitCachePath) { - config.gitCachePath = value; - } - - if (variable == ConfigKeys.flutterUrl) { - config.flutterUrl = value; + if (envVar == ConfigKeys.useGitCache) { + config = config.copyWith(useGitCache: stringToBool(value)); } - if (variable == ConfigKeys.priviledgedAccess) { - config.priviledgedAccess = stringToBool(value); + if (envVar == ConfigKeys.gitCachePath) { + config = config.copyWith(gitCachePath: value); } - if (variable == ConfigKeys.runPubGetOnSdkChanges) { - config.runPubGetOnSdkChanges = stringToBool(value); + if (envVar == ConfigKeys.flutterUrl) { + config = config.copyWith(flutterUrl: value); } } diff --git a/lib/src/services/project_service.dart b/lib/src/services/project_service.dart index 016dd00e..818d045b 100644 --- a/lib/src/services/project_service.dart +++ b/lib/src/services/project_service.dart @@ -84,12 +84,12 @@ class ProjectService extends ContextService { String? flutterSdkVersion, bool? updateVscodeSettings, }) { - final newConfig = project.config ?? ProjectConfig(); + final newConfig = project.config ?? ProjectConfig.empty(); final config = newConfig.copyWith( + flavors: flavors, flutterSdkVersion: flutterSdkVersion, updateVscodeSettings: updateVscodeSettings, - flavors: flavors, ); // Update flavors diff --git a/lib/src/utils/context.dart b/lib/src/utils/context.dart index 5225f42b..5e8f6068 100644 --- a/lib/src/utils/context.dart +++ b/lib/src/utils/context.dart @@ -56,14 +56,8 @@ class FVMContext { }) { workingDirectory ??= Directory.current.path; - // Load config from file in config path - - final envConfig = ConfigRepository.loadEnv(); - - final appConfig = ConfigRepository.loadFile().mergeConfig(envConfig); - - // Merge config from file with env config - final config = appConfig.merge(configOverrides); + // Load all configs + final config = ConfigRepository.load(overrides: configOverrides); final level = isTest ? Level.warning : Level.info; @@ -96,13 +90,7 @@ class FVMContext { this.isTest = false, }) : _config = config; - AppConfig get config { - // TODO: Need to optimize this - // For now optimizing for correctness - final projectConfig = ProjectService(this).findAncestor().config; - - return _config.mergeConfig(projectConfig); - } + AppConfig get config => _config; /// Environment variables Map get environment => Platform.environment; diff --git a/lib/src/utils/deprecation_util.dart b/lib/src/utils/deprecation_util.dart index 8db92a7b..6c2e79cf 100644 --- a/lib/src/utils/deprecation_util.dart +++ b/lib/src/utils/deprecation_util.dart @@ -24,7 +24,7 @@ void deprecationWorkflow() { final settings = jsonDecode(payload); final settingsCachePath = settings['cachePath'] as String?; if (settingsCachePath != null && settingsCachePath != fvmDir) { - var appConfig = ConfigRepository.loadFile(); + var appConfig = ConfigRepository.loadAppConfig(); appConfig = appConfig.copyWith(cachePath: fvmDir); ConfigRepository.save(appConfig); legacySettingsFile.deleteSync(recursive: true); diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 00000000..deba512e --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1,2 @@ +// Generated code. Do not modify. +const packageVersion = '3.0.12'; diff --git a/lib/src/version.g.dart b/lib/src/version.g.dart deleted file mode 100644 index 5e8ece4c..00000000 --- a/lib/src/version.g.dart +++ /dev/null @@ -1,3 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -const packageVersion = '3.0.12'; diff --git a/pubspec.lock b/pubspec.lock index 3430c4fc..f5665535 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,6 +17,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.13.0" + ansicolor: + dependency: transitive + description: + name: ansicolor + sha256: "8bf17a8ff6ea17499e40a2d2542c2f481cd7615760c6d34065cb22bfd22e6880" + url: "https://pub.dev" + source: hosted + version: "2.0.2" archive: dependency: transitive description: @@ -49,6 +57,86 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + url: "https://pub.dev" + source: hosted + version: "4.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21" + url: "https://pub.dev" + source: hosted + version: "2.4.8" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" + url: "https://pub.dev" + source: hosted + version: "7.3.0" + build_verify: + dependency: "direct main" + description: + name: build_verify + sha256: abbb9b9eda076854ac1678d284c053a5ec608e64da741d0801f56d4bbea27e23 + url: "https://pub.dev" + source: hosted + version: "3.1.0" + build_version: + dependency: "direct main" + description: + name: build_version + sha256: "4e8eafbf722eac3bd60c8d38f108c04bd69b80100f8792b32be3407725c7fa6a" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e + url: "https://pub.dev" + source: hosted + version: "8.9.1" characters: dependency: transitive description: @@ -97,6 +185,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" collection: dependency: transitive description: @@ -145,6 +241,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + dart_mappable: + dependency: "direct main" + description: + name: dart_mappable + sha256: "7b6d38ae95f1ae8ffa65df9a5464f14b56c2de94699a035202ca4cd3a0ba249e" + url: "https://pub.dev" + source: hosted + version: "4.2.0" + dart_mappable_builder: + dependency: "direct dev" + description: + name: dart_mappable_builder + sha256: "98c058f7e80a98ea42d357d888ed1648d96bedac8b16872b58fc7024faefcdfe" + url: "https://pub.dev" + source: hosted + version: "4.2.0" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + url: "https://pub.dev" + source: hosted + version: "2.3.2" date_format: dependency: "direct main" description: @@ -169,6 +289,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.4" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" frontend_server_client: dependency: transitive description: @@ -193,6 +321,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" grinder: dependency: "direct dev" description: @@ -481,6 +617,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" source_map_stack_trace: dependency: transitive description: @@ -521,6 +665,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" string_scanner: dependency: transitive description: @@ -569,6 +721,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" tint: dependency: "direct main" description: @@ -577,6 +737,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" + type_plus: + dependency: transitive + description: + name: type_plus + sha256: "2e33cfac2e129297d5874567bdf7587502ec359881e9318551e014d91b02f84a" + url: "https://pub.dev" + source: hosted + version: "2.1.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e1b1282a..827df0ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,9 @@ dependencies: stack_trace: ^1.11.1 pubspec: ^2.3.0 jsonc: ^0.0.3 + dart_mappable: ^4.2.0 + build_verify: ^3.1.0 + build_version: ^2.1.1 dev_dependencies: cli_pkg: ^2.5.0 @@ -37,4 +40,6 @@ dev_dependencies: crypto: ^3.0.3 http: ^1.1.0 dart_code_metrics_presets: ^2.9.0 + build_runner: ^2.4.8 + dart_mappable_builder: ^4.2.0 diff --git a/test/ensure_build_test.dart b/test/ensure_build_test.dart new file mode 100644 index 00000000..df5b8253 --- /dev/null +++ b/test/ensure_build_test.dart @@ -0,0 +1,6 @@ +import 'package:build_verify/build_verify.dart'; +import 'package:test/test.dart'; + +void main() { + test('ensure_build', expectBuildClean); +} diff --git a/test/utils/helpers_test.dart b/test/utils/helpers_test.dart index a7923f3e..67319107 100644 --- a/test/utils/helpers_test.dart +++ b/test/utils/helpers_test.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:fvm/src/utils/helpers.dart'; -import 'package:fvm/src/version.g.dart'; +import 'package:fvm/src/version.dart'; import 'package:path/path.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; diff --git a/tool/grind.dart b/tool/grind.dart index f25c3c83..312f500b 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -5,8 +5,6 @@ import 'package:cli_pkg/cli_pkg.dart' as pkg; import 'package:fvm/src/utils/http.dart'; import 'package:grinder/grinder.dart'; import 'package:path/path.dart' as path; -import 'package:pub_semver/pub_semver.dart'; -import 'package:pubspec/pubspec.dart'; import '../test/testing_helpers/prepare_test_environment.dart'; import 'homebrew.dart'; @@ -29,39 +27,6 @@ void main(List args) { grind(args); } -@Task('Builds the version file') -Future buildVersion() async { - final args = context.invocation.arguments; - final versionArg = args.getOption('version'); - - final pubspec = await PubSpec.load(Directory.current); - Version? version = pubspec.version; - - if (versionArg != null) { - version = Version.parse(versionArg); - } - - if (version != pubspec.version) { - var newPubSpec = pubspec.copy(version: version); - await newPubSpec.save(Directory.current); - } - - final versionFile = File( - path.join(Directory.current.path, 'lib', 'src', 'version.g.dart'), - ); - - if (!versionFile.existsSync()) { - versionFile.createSync(recursive: true); - } - - String fileContent = '// GENERATED CODE - DO NOT MODIFY BY HAND\n\n'; - fileContent += "const packageVersion = '$version';\n"; - - versionFile.writeAsStringSync(fileContent); - - log('Version $version written to version.g.dart'); -} - @Task('Get all releases') Future getReleases() async { String owner = 'leoafarias'; @@ -88,7 +53,6 @@ Future getReleases() async { } @Task('Prepare test environment') -@Depends(buildVersion) void testSetup() { final testDir = Directory(getTempTestDir()); if (testDir.existsSync()) { From 765df6c16f1f2ac391e528748d19f0086a108de4 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 14:47:04 -0500 Subject: [PATCH 07/10] Clena up config command --- lib/src/commands/config_command.dart | 47 +++++++--------------------- lib/src/models/config_model.dart | 13 ++++---- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/lib/src/commands/config_command.dart b/lib/src/commands/config_command.dart index 7adcafba..c2658a38 100644 --- a/lib/src/commands/config_command.dart +++ b/lib/src/commands/config_command.dart @@ -33,43 +33,18 @@ class ConfigCommand extends BaseCommand { final currentConfig = ConfigRepository.loadAppConfig(); var updatedConfig = currentConfig; - // TODO: Consolidate redundant code - - if (wasParsed(ConfigKeys.flutterUrl.paramKey)) { - final flutterRepo = stringArg(ConfigKeys.flutterUrl.paramKey); - logger.info('Setting flutter repo to: ${yellow.wrap(flutterRepo)}'); - // current.flutterUrl = flutterRepo; - updatedConfig = currentConfig.copyWith(flutterUrl: flutterRepo); - } - - if (wasParsed(ConfigKeys.gitCachePath.paramKey)) { - final gitCachePath = stringArg(ConfigKeys.gitCachePath.paramKey); - logger.info('Setting git cache path to: ${yellow.wrap(gitCachePath)}'); - // currentConfig.gitCachePath = gitCachePath; - updatedConfig = currentConfig.copyWith(gitCachePath: gitCachePath); - } - - if (wasParsed(ConfigKeys.useGitCache.paramKey)) { - final gitCache = boolArg(ConfigKeys.useGitCache.paramKey); - logger.info( - 'Setting use git cache to: ${yellow.wrap(gitCache.toString())}', - ); - updatedConfig = currentConfig.copyWith(useGitCache: gitCache); - } - - if (wasParsed(ConfigKeys.cachePath.paramKey)) { - final cachePath = stringArg(ConfigKeys.cachePath.paramKey); - logger.info('Setting fvm path to: ${yellow.wrap(cachePath)}'); - updatedConfig = currentConfig.copyWith(cachePath: cachePath); + void updateConfigKey(ConfigKeys key, T value) { + if (wasParsed(key.paramKey)) { + final updatedMap = AppConfig.fromMap({key.name: value}); + logger.info( + 'Setting ${key.paramKey} to: ${yellow.wrap(value.toString())}', + ); + updatedConfig = updatedConfig.merge(updatedMap); + } } - if (wasParsed(ConfigKeys.priviledgedAccess.paramKey)) { - final priviledgedAccess = boolArg(ConfigKeys.priviledgedAccess.paramKey); - logger.info( - 'Setting priviledged access to: ${yellow.wrap(priviledgedAccess.toString())}', - ); - updatedConfig = - currentConfig.copyWith(priviledgedAccess: priviledgedAccess); + for (var key in ConfigKeys.values) { + updateConfigKey(key, argResults![key.paramKey]); } // Save @@ -78,7 +53,7 @@ class ConfigCommand extends BaseCommand { final updateProgress = logger.progress('Saving settings'); // Update settings try { - ConfigRepository.save(currentConfig); + ConfigRepository.save(updatedConfig); } catch (error) { updateProgress.fail('Failed to save settings'); rethrow; diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 7c7d53ae..7e187870 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -28,7 +28,7 @@ enum ConfigKeys { final String description; - ChangeCase get _recase => ChangeCase(toString()); + ChangeCase get _recase => ChangeCase(name); String get envKey => 'FVM_${_recase.constantCase}'; @@ -41,14 +41,13 @@ enum ConfigKeys { ConfigKeys.cachePath: () { argParser.addOption( ConfigKeys.cachePath.paramKey, - help: 'Path where $kPackageName will cache versions', + help: ConfigKeys.cachePath.description, ); }, ConfigKeys.useGitCache: () { argParser.addFlag( ConfigKeys.useGitCache.paramKey, - help: - 'Enable/Disable git cache globally, which is used for faster version installs.', + help: ConfigKeys.useGitCache.description, defaultsTo: true, negatable: true, ); @@ -56,19 +55,19 @@ enum ConfigKeys { ConfigKeys.gitCachePath: () { argParser.addOption( ConfigKeys.gitCachePath.paramKey, - help: 'Path where local Git reference cache is stored', + help: ConfigKeys.gitCachePath.description, ); }, ConfigKeys.flutterUrl: () { argParser.addOption( ConfigKeys.flutterUrl.paramKey, - help: 'Flutter repository Git URL to clone from', + help: ConfigKeys.flutterUrl.description, ); }, ConfigKeys.priviledgedAccess: () { argParser.addFlag( ConfigKeys.priviledgedAccess.paramKey, - help: 'Enable/Disable priviledged access for FVM', + help: ConfigKeys.priviledgedAccess.description, defaultsTo: true, negatable: true, ); From a78e53e3ed273d8550881d4640d0f84cacdf0b89 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 16:16:20 -0500 Subject: [PATCH 08/10] Update fix --- lib/src/commands/config_command.dart | 2 + lib/src/models/config_model.dart | 82 +++++++++++-------------- lib/src/models/config_model.mapper.dart | 44 +++++++------ lib/src/runner.dart | 7 ++- lib/src/services/config_repository.dart | 23 ++++--- lib/src/utils/deprecation_util.dart | 33 ---------- lib/src/version.dart | 2 +- pubspec.lock | 4 +- pubspec.yaml | 7 ++- test/src/models/config_model_test.dart | 27 ++++++++ 10 files changed, 116 insertions(+), 115 deletions(-) create mode 100644 test/src/models/config_model_test.dart diff --git a/lib/src/commands/config_command.dart b/lib/src/commands/config_command.dart index c2658a38..8656e87e 100644 --- a/lib/src/commands/config_command.dart +++ b/lib/src/commands/config_command.dart @@ -39,6 +39,8 @@ class ConfigCommand extends BaseCommand { logger.info( 'Setting ${key.paramKey} to: ${yellow.wrap(value.toString())}', ); + + logger.info(updatedMap.toString()); updatedConfig = updatedConfig.merge(updatedMap); } } diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 7e187870..8c17d789 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -159,7 +159,7 @@ class FileConfig extends BaseConfig with FileConfigMappable { } } -@MappableClass() +@MappableClass(ignoreNull: true) class AppConfig extends FileConfig with AppConfigMappable { /// Disables update notification @@ -171,16 +171,16 @@ class AppConfig extends FileConfig with AppConfigMappable { /// Constructor const AppConfig({ - required this.disableUpdateCheck, - required this.lastUpdateCheck, - required super.cachePath, - required super.useGitCache, - required super.gitCachePath, - required super.flutterUrl, - required super.priviledgedAccess, - required super.runPubGetOnSdkChanges, - required super.updateVscodeSettings, - required super.updateGitIgnore, + this.disableUpdateCheck, + this.lastUpdateCheck, + super.cachePath, + super.useGitCache, + super.gitCachePath, + super.flutterUrl, + super.priviledgedAccess, + super.runPubGetOnSdkChanges, + super.updateVscodeSettings, + super.updateGitIgnore, }); static AppConfig empty() { @@ -208,55 +208,47 @@ class AppConfig extends FileConfig with AppConfigMappable { AppConfig merge(BaseConfig? config) { if (config == null) return this; + AppConfig newConfig; if (config is EnvConfig) { - return copyWith( - cachePath: config.cachePath, + newConfig = AppConfig( disableUpdateCheck: disableUpdateCheck, - flutterUrl: config.flutterUrl, - gitCachePath: config.gitCachePath, + cachePath: config.cachePath, useGitCache: config.useGitCache, + gitCachePath: config.gitCachePath, + flutterUrl: config.flutterUrl, ); } if (config is ProjectConfig) { - return copyWith( + newConfig = AppConfig( cachePath: config.cachePath, - flutterUrl: config.flutterUrl, + useGitCache: config.useGitCache, gitCachePath: config.gitCachePath, + flutterUrl: config.flutterUrl, priviledgedAccess: config.priviledgedAccess, runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, - updateGitIgnore: config.updateGitIgnore, updateVscodeSettings: config.updateVscodeSettings, - useGitCache: config.useGitCache, + updateGitIgnore: config.updateGitIgnore, ); } if (config is AppConfig) { - return copyWith( - cachePath: config.cachePath, - disableUpdateCheck: config.disableUpdateCheck, - flutterUrl: config.flutterUrl, - gitCachePath: config.gitCachePath, - lastUpdateCheck: config.lastUpdateCheck, - priviledgedAccess: config.priviledgedAccess, - runPubGetOnSdkChanges: config.runPubGetOnSdkChanges, - updateGitIgnore: config.updateGitIgnore, - updateVscodeSettings: config.updateVscodeSettings, - useGitCache: config.useGitCache, - ); + return copyWith.$merge(config); } - return copyWith( + newConfig = AppConfig( cachePath: config.cachePath, - flutterUrl: config.flutterUrl, - gitCachePath: config.gitCachePath, useGitCache: config.useGitCache, + gitCachePath: config.gitCachePath, + flutterUrl: config.flutterUrl, ); + + return copyWith.$merge(newConfig); } } /// Project config -@MappableClass() +@MappableClass(ignoreNull: true) class ProjectConfig extends FileConfig with ProjectConfigMappable { final String? flutterSdkVersion; final Map? flavors; @@ -265,16 +257,16 @@ class ProjectConfig extends FileConfig with ProjectConfigMappable { /// Constructor const ProjectConfig({ - required this.flutterSdkVersion, - required this.flavors, - required super.cachePath, - required super.useGitCache, - required super.gitCachePath, - required super.flutterUrl, - required super.priviledgedAccess, - required super.runPubGetOnSdkChanges, - required super.updateVscodeSettings, - required super.updateGitIgnore, + this.flutterSdkVersion, + this.flavors, + super.cachePath, + super.useGitCache, + super.gitCachePath, + super.flutterUrl, + super.priviledgedAccess, + super.runPubGetOnSdkChanges, + super.updateVscodeSettings, + super.updateGitIgnore, }); static ProjectConfig empty() { diff --git a/lib/src/models/config_model.mapper.dart b/lib/src/models/config_model.mapper.dart index 6b77670c..88ca6b4d 100644 --- a/lib/src/models/config_model.mapper.dart +++ b/lib/src/models/config_model.mapper.dart @@ -470,34 +470,34 @@ class AppConfigMapper extends ClassMapperBase { static bool? _$disableUpdateCheck(AppConfig v) => v.disableUpdateCheck; static const Field _f$disableUpdateCheck = - Field('disableUpdateCheck', _$disableUpdateCheck); + Field('disableUpdateCheck', _$disableUpdateCheck, opt: true); static DateTime? _$lastUpdateCheck(AppConfig v) => v.lastUpdateCheck; static const Field _f$lastUpdateCheck = - Field('lastUpdateCheck', _$lastUpdateCheck); + Field('lastUpdateCheck', _$lastUpdateCheck, opt: true); static String? _$cachePath(AppConfig v) => v.cachePath; static const Field _f$cachePath = - Field('cachePath', _$cachePath); + Field('cachePath', _$cachePath, opt: true); static bool? _$useGitCache(AppConfig v) => v.useGitCache; static const Field _f$useGitCache = - Field('useGitCache', _$useGitCache); + Field('useGitCache', _$useGitCache, opt: true); static String? _$gitCachePath(AppConfig v) => v.gitCachePath; static const Field _f$gitCachePath = - Field('gitCachePath', _$gitCachePath); + Field('gitCachePath', _$gitCachePath, opt: true); static String? _$flutterUrl(AppConfig v) => v.flutterUrl; static const Field _f$flutterUrl = - Field('flutterUrl', _$flutterUrl); + Field('flutterUrl', _$flutterUrl, opt: true); static bool? _$priviledgedAccess(AppConfig v) => v.priviledgedAccess; static const Field _f$priviledgedAccess = - Field('priviledgedAccess', _$priviledgedAccess); + Field('priviledgedAccess', _$priviledgedAccess, opt: true); static bool? _$runPubGetOnSdkChanges(AppConfig v) => v.runPubGetOnSdkChanges; static const Field _f$runPubGetOnSdkChanges = - Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges); + Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges, opt: true); static bool? _$updateVscodeSettings(AppConfig v) => v.updateVscodeSettings; static const Field _f$updateVscodeSettings = - Field('updateVscodeSettings', _$updateVscodeSettings); + Field('updateVscodeSettings', _$updateVscodeSettings, opt: true); static bool? _$updateGitIgnore(AppConfig v) => v.updateGitIgnore; static const Field _f$updateGitIgnore = - Field('updateGitIgnore', _$updateGitIgnore); + Field('updateGitIgnore', _$updateGitIgnore, opt: true); @override final MappableFields fields = const { @@ -512,6 +512,8 @@ class AppConfigMapper extends ClassMapperBase { #updateVscodeSettings: _f$updateVscodeSettings, #updateGitIgnore: _f$updateGitIgnore, }; + @override + final bool ignoreNull = true; static AppConfig _instantiate(DecodingData data) { return AppConfig( @@ -669,36 +671,36 @@ class ProjectConfigMapper extends ClassMapperBase { static String? _$flutterSdkVersion(ProjectConfig v) => v.flutterSdkVersion; static const Field _f$flutterSdkVersion = - Field('flutterSdkVersion', _$flutterSdkVersion); + Field('flutterSdkVersion', _$flutterSdkVersion, opt: true); static Map? _$flavors(ProjectConfig v) => v.flavors; static const Field> _f$flavors = - Field('flavors', _$flavors); + Field('flavors', _$flavors, opt: true); static String? _$cachePath(ProjectConfig v) => v.cachePath; static const Field _f$cachePath = - Field('cachePath', _$cachePath); + Field('cachePath', _$cachePath, opt: true); static bool? _$useGitCache(ProjectConfig v) => v.useGitCache; static const Field _f$useGitCache = - Field('useGitCache', _$useGitCache); + Field('useGitCache', _$useGitCache, opt: true); static String? _$gitCachePath(ProjectConfig v) => v.gitCachePath; static const Field _f$gitCachePath = - Field('gitCachePath', _$gitCachePath); + Field('gitCachePath', _$gitCachePath, opt: true); static String? _$flutterUrl(ProjectConfig v) => v.flutterUrl; static const Field _f$flutterUrl = - Field('flutterUrl', _$flutterUrl); + Field('flutterUrl', _$flutterUrl, opt: true); static bool? _$priviledgedAccess(ProjectConfig v) => v.priviledgedAccess; static const Field _f$priviledgedAccess = - Field('priviledgedAccess', _$priviledgedAccess); + Field('priviledgedAccess', _$priviledgedAccess, opt: true); static bool? _$runPubGetOnSdkChanges(ProjectConfig v) => v.runPubGetOnSdkChanges; static const Field _f$runPubGetOnSdkChanges = - Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges); + Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges, opt: true); static bool? _$updateVscodeSettings(ProjectConfig v) => v.updateVscodeSettings; static const Field _f$updateVscodeSettings = - Field('updateVscodeSettings', _$updateVscodeSettings); + Field('updateVscodeSettings', _$updateVscodeSettings, opt: true); static bool? _$updateGitIgnore(ProjectConfig v) => v.updateGitIgnore; static const Field _f$updateGitIgnore = - Field('updateGitIgnore', _$updateGitIgnore); + Field('updateGitIgnore', _$updateGitIgnore, opt: true); @override final MappableFields fields = const { @@ -713,6 +715,8 @@ class ProjectConfigMapper extends ClassMapperBase { #updateVscodeSettings: _f$updateVscodeSettings, #updateGitIgnore: _f$updateGitIgnore, }; + @override + final bool ignoreNull = true; static ProjectConfig _instantiate(DecodingData data) { return ProjectConfig( diff --git a/lib/src/runner.dart b/lib/src/runner.dart index e16b8945..76837472 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -62,9 +62,12 @@ class FvmCommandRunner extends CommandRunner { /// user. Future _checkForUpdates() async { try { + final lastUpdateCheck = ctx.lastUpdateCheck ?? DateTime.now(); if (ctx.updateCheckDisabled) return null; - final oneDayAgo = DateTime.now().subtract(const Duration(days: 1)); - if (ctx.lastUpdateCheck?.isBefore(oneDayAgo) ?? false) { + final oneDay = lastUpdateCheck.add(const Duration(days: 1)); + + print(DateTime.now().isBefore(oneDay)); + if (DateTime.now().isBefore(oneDay)) { return null; } diff --git a/lib/src/services/config_repository.dart b/lib/src/services/config_repository.dart index 941061ad..60d17808 100644 --- a/lib/src/services/config_repository.dart +++ b/lib/src/services/config_repository.dart @@ -7,6 +7,7 @@ import '../utils/constants.dart'; import '../utils/extensions.dart'; import '../utils/helpers.dart'; import '../utils/pretty_json.dart'; +import 'logger_service.dart'; const String flutterGitUrl = 'FLUTTER_GIT_URL'; @@ -24,13 +25,17 @@ class ConfigRepository { static AppConfig loadAppConfig() { final appConfig = AppConfig.loadFromPath(_configPath); - if (appConfig != null) return appConfig; + if (appConfig == null) { + save(AppConfig.empty()); + } - return AppConfig.empty(); + return AppConfig.loadFromPath(_configPath)!; } static void save(AppConfig config) { final jsonContents = prettyJson(config.toMap()); + logger.warn('Saving config to $_configPath'); + print(jsonContents); _configPath.file.write(jsonContents); } @@ -56,24 +61,24 @@ class ConfigRepository { static void update({ String? cachePath, - bool? useGitCache, String? gitCachePath, String? flutterUrl, bool? disableUpdateCheck, DateTime? lastUpdateCheck, bool? priviledgedAccess, + bool? useGitCache, }) { final currentConfig = loadAppConfig(); - final newConfig = currentConfig.copyWith( - cachePath: cachePath, + final newConfig = AppConfig( disableUpdateCheck: disableUpdateCheck, - flutterUrl: flutterUrl, - gitCachePath: gitCachePath, lastUpdateCheck: lastUpdateCheck, - priviledgedAccess: priviledgedAccess, + cachePath: cachePath, useGitCache: useGitCache, + gitCachePath: gitCachePath, + flutterUrl: flutterUrl, + priviledgedAccess: priviledgedAccess, ); - save(newConfig); + save(currentConfig.copyWith.$merge(newConfig)); } static EnvConfig _loadEnvironment() { diff --git a/lib/src/utils/deprecation_util.dart b/lib/src/utils/deprecation_util.dart index 6c2e79cf..d2022dd7 100644 --- a/lib/src/utils/deprecation_util.dart +++ b/lib/src/utils/deprecation_util.dart @@ -1,45 +1,12 @@ -import 'dart:convert'; import 'dart:io'; import 'package:mason_logger/mason_logger.dart'; -import 'package:path/path.dart'; import '../models/config_model.dart'; -import '../services/config_repository.dart'; import '../services/logger_service.dart'; -import 'constants.dart'; -import 'context.dart'; void deprecationWorkflow() { _warnDeprecatedEnvVars(); - final fvmDir = ctx.fvmDir; - final legacySettingsFile = File(join(fvmDir, '.settings')); - - if (!legacySettingsFile.existsSync()) { - return; - } - - final payload = legacySettingsFile.readAsStringSync(); - try { - final settings = jsonDecode(payload); - final settingsCachePath = settings['cachePath'] as String?; - if (settingsCachePath != null && settingsCachePath != fvmDir) { - var appConfig = ConfigRepository.loadAppConfig(); - appConfig = appConfig.copyWith(cachePath: fvmDir); - ConfigRepository.save(appConfig); - legacySettingsFile.deleteSync(recursive: true); - logger.success( - 'We have moved the settings file ${legacySettingsFile.path}' - 'Your settings have been migrated to $kAppConfigFile' - 'Your cachePath is now $settingsCachePath. FVM will exit now. Please run the command again.', - ); - // Exit to prevent execution with wrong cache path - exit(ExitCode.success.code); - } - } catch (_) { - logger.warn('Could not parse legacy settings file'); - legacySettingsFile.deleteSync(recursive: true); - } } // TODO: Removed on future version of the app diff --git a/lib/src/version.dart b/lib/src/version.dart index deba512e..a28987a6 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '3.0.12'; +const packageVersion = '3.0.10'; diff --git a/pubspec.lock b/pubspec.lock index f5665535..fb25e9b6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -106,7 +106,7 @@ packages: source: hosted version: "7.3.0" build_verify: - dependency: "direct main" + dependency: "direct dev" description: name: build_verify sha256: abbb9b9eda076854ac1678d284c053a5ec608e64da741d0801f56d4bbea27e23 @@ -114,7 +114,7 @@ packages: source: hosted version: "3.1.0" build_version: - dependency: "direct main" + dependency: "direct dev" description: name: build_version sha256: "4e8eafbf722eac3bd60c8d38f108c04bd69b80100f8792b32be3407725c7fa6a" diff --git a/pubspec.yaml b/pubspec.yaml index 827df0ea..2c7ee21d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: fvm description: A simple cli to manage Flutter SDK versions per project. Support channels, releases, and local cache for fast switching between versions. -version: 3.0.12 +version: 3.0.10 homepage: https://github.com/leoafarias/fvm environment: @@ -29,8 +29,7 @@ dependencies: pubspec: ^2.3.0 jsonc: ^0.0.3 dart_mappable: ^4.2.0 - build_verify: ^3.1.0 - build_version: ^2.1.1 + dev_dependencies: cli_pkg: ^2.5.0 @@ -42,4 +41,6 @@ dev_dependencies: dart_code_metrics_presets: ^2.9.0 build_runner: ^2.4.8 dart_mappable_builder: ^4.2.0 + build_verify: ^3.1.0 + build_version: ^2.1.1 diff --git a/test/src/models/config_model_test.dart b/test/src/models/config_model_test.dart new file mode 100644 index 00000000..19b0135f --- /dev/null +++ b/test/src/models/config_model_test.dart @@ -0,0 +1,27 @@ +import 'package:fvm/src/models/config_model.dart'; +import 'package:test/test.dart'; + +void main() { + group('person test', () { + test( + '', + () { + final appConfig = AppConfig( + cachePath: 'cachePath', + flutterUrl: 'flutterUrl', + useGitCache: true, + ); + + final newConfig = appConfig.copyWith( + cachePath: 'newCachePath', + flutterUrl: 'newFlutterUrl', + useGitCache: null, + ); + + expect(newConfig.cachePath, 'newCachePath'); + expect(newConfig.flutterUrl, 'newFlutterUrl'); + expect(newConfig.useGitCache, true); + }, + ); + }); +} From 55622c54b8865a0633ebc584944096b1de778649 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 16:23:39 -0500 Subject: [PATCH 09/10] Remove model test --- docs/next.config.js | 5 +++++ test/src/models/config_model_test.dart | 27 -------------------------- 2 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 test/src/models/config_model_test.dart diff --git a/docs/next.config.js b/docs/next.config.js index c15c3b37..61814697 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -23,6 +23,11 @@ module.exports = withNextra({ destination: "/documentation/getting-started/faq", permanent: true, }, + { + source: "/docs/guides/global_version", + destination: "/documentation/guides/global-configuration", + permanent: true, + }, ]; }, }); diff --git a/test/src/models/config_model_test.dart b/test/src/models/config_model_test.dart deleted file mode 100644 index 19b0135f..00000000 --- a/test/src/models/config_model_test.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:fvm/src/models/config_model.dart'; -import 'package:test/test.dart'; - -void main() { - group('person test', () { - test( - '', - () { - final appConfig = AppConfig( - cachePath: 'cachePath', - flutterUrl: 'flutterUrl', - useGitCache: true, - ); - - final newConfig = appConfig.copyWith( - cachePath: 'newCachePath', - flutterUrl: 'newFlutterUrl', - useGitCache: null, - ); - - expect(newConfig.cachePath, 'newCachePath'); - expect(newConfig.flutterUrl, 'newFlutterUrl'); - expect(newConfig.useGitCache, true); - }, - ); - }); -} From e8ac7257e31b773195877e0bc873d4065b380c66 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 29 Feb 2024 16:25:37 -0500 Subject: [PATCH 10/10] Remove print statement --- lib/src/runner.dart | 1 - lib/src/services/config_repository.dart | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 76837472..c63086f0 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -66,7 +66,6 @@ class FvmCommandRunner extends CommandRunner { if (ctx.updateCheckDisabled) return null; final oneDay = lastUpdateCheck.add(const Duration(days: 1)); - print(DateTime.now().isBefore(oneDay)); if (DateTime.now().isBefore(oneDay)) { return null; } diff --git a/lib/src/services/config_repository.dart b/lib/src/services/config_repository.dart index 60d17808..12d78ecc 100644 --- a/lib/src/services/config_repository.dart +++ b/lib/src/services/config_repository.dart @@ -35,7 +35,6 @@ class ConfigRepository { static void save(AppConfig config) { final jsonContents = prettyJson(config.toMap()); logger.warn('Saving config to $_configPath'); - print(jsonContents); _configPath.file.write(jsonContents); }