From 175ec16e269cc7a5b8fcf30d4ec55f4d784adfd5 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Mon, 15 Jun 2020 15:01:10 -0400 Subject: [PATCH 01/11] Updated CI for publishing --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9aa2365e..8aed620d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout uses: actions/checkout@v1 - name: Publish - uses: sakebook/actions-flutter-pub-publisher@v1.2.0 + uses: sakebook/actions-flutter-pub-publisher@v1.3.0 with: credential: ${{ secrets.CREDENTIAL_JSON }} flutter_package: false From 56d11b23f4da7203fdd293151379968ae336d16c Mon Sep 17 00:00:00 2001 From: leoafarias Date: Mon, 15 Jun 2020 18:43:30 -0400 Subject: [PATCH 02/11] Can install while using the `use` command --- lib/commands/install.dart | 10 ++++------ lib/commands/use.dart | 26 +++++++++++++++++--------- lib/utils/version_installer.dart | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 lib/utils/version_installer.dart diff --git a/lib/commands/install.dart b/lib/commands/install.dart index f671fccc..d66e348e 100644 --- a/lib/commands/install.dart +++ b/lib/commands/install.dart @@ -3,6 +3,7 @@ import 'package:fvm/exceptions.dart'; import 'package:fvm/utils/flutter_tools.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:fvm/utils/logger.dart'; +import 'package:fvm/utils/version_installer.dart'; import 'package:io/ansi.dart'; /// Installs Flutter SDK @@ -25,14 +26,11 @@ class InstallCommand extends Command { throw ExceptionMissingChannelVersion(); } final version = argResults.arguments[0].toLowerCase(); - final isChannel = isValidFlutterChannel(version); final progress = logger.progress(green.wrap('Downloading $version')); - if (isChannel) { - await flutterChannelClone(version); - } else { - await flutterVersionClone(version); - } + + await installFlutterVersion(version); + finishProgress(progress); } } diff --git a/lib/commands/use.dart b/lib/commands/use.dart index e14d5183..89cdf35b 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -1,7 +1,9 @@ import 'package:args/command_runner.dart'; +import 'package:console/console.dart'; import 'package:fvm/utils/flutter_tools.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:fvm/utils/logger.dart'; +import 'package:fvm/utils/version_installer.dart'; import 'package:io/ansi.dart'; /// Use an installed SDK version @@ -28,15 +30,21 @@ class UseCommand extends Command { final isValidInstall = await isValidFlutterInstall(version); if (!isValidInstall) { - final instruction = yellow.wrap('fvm install first.'); - throw Exception( - 'Flutter $version is not installed. Please run $instruction'); + print('Flutter $version is not installed.'); + var inputConfirm = await readInput('Would you like to install it? y/N: '); + + if (inputConfirm.contains('y')) { + final installProgress = logger.progress('Installing $version'); + await installFlutterVersion(version); + finishProgress(installProgress); + + await linkProjectFlutterDir(version); + logger.stdout(green.wrap('$version is active')); + } else { + print('Done'); + } + } else { + logger.stdout(green.wrap('$version is active')); } - - final progress = logger.progress('Activating $version'); - - await linkProjectFlutterDir(version); - logger.stdout(green.wrap('$version is active')); - finishProgress(progress); } } diff --git a/lib/utils/version_installer.dart b/lib/utils/version_installer.dart new file mode 100644 index 00000000..7c733e15 --- /dev/null +++ b/lib/utils/version_installer.dart @@ -0,0 +1,17 @@ +import 'package:fvm/exceptions.dart'; +import 'package:fvm/utils/flutter_tools.dart'; +import 'package:fvm/utils/helpers.dart'; + +Future installFlutterVersion(String flutterVersion) async { + if (flutterVersion == null) { + throw ExceptionMissingChannelVersion(); + } + final version = flutterVersion.toLowerCase(); + final isChannel = isValidFlutterChannel(version); + + if (isChannel) { + await flutterChannelClone(version); + } else { + await flutterVersionClone(version); + } +} From 6183244a9b4f66be165d19eef96d6781ef3e87a8 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Tue, 16 Jun 2020 07:54:49 -0400 Subject: [PATCH 03/11] Clean up, and better use command experience --- .gitignore | 1 + coverage/lcov.info | 358 ------------------------------- coverage_badge.svg | 6 +- lib/commands/install.dart | 1 - lib/commands/remove.dart | 2 +- lib/commands/use.dart | 13 +- lib/utils/flutter_tools.dart | 13 +- lib/utils/helpers.dart | 11 +- lib/utils/version_installer.dart | 3 +- pubspec.yaml | 2 +- test/fvm_test.dart | 18 +- test/utils/helpers_test.dart | 22 +- 12 files changed, 40 insertions(+), 410 deletions(-) delete mode 100644 coverage/lcov.info diff --git a/.gitignore b/.gitignore index 4282cef4..afcd3a9d 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ fvm .project .settings/ .vscode/ +coverage/lcov.info diff --git a/coverage/lcov.info b/coverage/lcov.info deleted file mode 100644 index a6dbbd0a..00000000 --- a/coverage/lcov.info +++ /dev/null @@ -1,358 +0,0 @@ -SF:lib/utils/helpers.dart -DA:9,1 -DA:10,3 -DA:13,1 -DA:14,3 -DA:17,2 -DA:21,1 -DA:22,2 -DA:26,1 -DA:27,3 -DA:31,1 -DA:36,2 -DA:37,2 -DA:39,3 -DA:40,0 -DA:41,0 -DA:42,0 -DA:47,1 -DA:48,2 -DA:50,7 -DA:51,1 -DA:52,1 -DA:53,2 -DA:61,1 -DA:63,1 -DA:68,1 -DA:70,3 -DA:72,2 -DA:74,0 -DA:77,0 -DA:78,0 -LF:30 -LH:24 -end_of_record -SF:lib/constants.dart -DA:5,3 -DA:11,0 -DA:14,3 -DA:17,6 -DA:20,1 -DA:22,1 -DA:23,1 -DA:24,1 -DA:25,0 -DA:26,0 -DA:27,0 -DA:28,0 -DA:31,1 -DA:35,4 -DA:38,1 -DA:39,2 -DA:41,1 -DA:43,3 -DA:47,3 -LF:19 -LH:14 -end_of_record -SF:lib/exceptions.dart -DA:4,0 -DA:5,0 -DA:6,0 -DA:16,0 -DA:17,0 -DA:18,0 -DA:27,1 -DA:28,0 -DA:29,0 -DA:38,1 -DA:40,0 -DA:41,0 -DA:50,0 -DA:52,0 -DA:53,0 -DA:62,1 -DA:64,0 -DA:65,0 -DA:73,1 -DA:75,0 -DA:77,0 -LF:21 -LH:4 -end_of_record -SF:lib/utils/logger.dart -DA:4,3 -DA:7,1 -DA:8,1 -LF:3 -LH:3 -end_of_record -SF:lib/utils/config_utils.dart -DA:12,1 -DA:13,1 -DA:17,1 -DA:18,1 -DA:24,1 -DA:25,2 -DA:26,2 -DA:29,3 -DA:30,0 -DA:31,0 -DA:32,0 -DA:35,1 -DA:36,2 -DA:38,1 -DA:41,1 -DA:42,2 -DA:43,2 -DA:45,4 -DA:49,1 -DA:50,2 -DA:51,1 -DA:55,1 -DA:56,2 -DA:60,1 -DA:61,1 -DA:62,1 -DA:63,0 -DA:64,1 -DA:65,2 -DA:66,1 -DA:73,1 -DA:74,3 -DA:75,3 -DA:80,1 -DA:81,1 -DA:87,1 -DA:88,1 -DA:90,0 -DA:91,0 -DA:99,1 -DA:100,1 -DA:101,3 -DA:102,2 -DA:103,2 -DA:106,1 -LF:45 -LH:39 -end_of_record -SF:lib/commands/install.dart -DA:19,1 -DA:22,1 -DA:23,2 -DA:24,3 -DA:25,1 -DA:27,4 -DA:28,1 -DA:30,4 -DA:32,2 -DA:34,2 -DA:36,1 -LF:11 -LH:11 -end_of_record -SF:lib/commands/runner.dart -DA:6,1 -DA:7,1 -DA:10,2 -DA:11,1 -DA:13,1 -DA:15,1 -LF:6 -LH:6 -end_of_record -SF:lib/commands/config.dart -DA:8,1 -DA:11,0 -DA:15,1 -DA:16,1 -DA:17,1 -DA:19,1 -DA:23,1 -DA:24,2 -DA:26,2 -DA:29,2 -DA:30,2 -DA:31,1 -DA:32,3 -DA:34,0 -LF:14 -LH:12 -end_of_record -SF:lib/commands/flutter.dart -DA:22,1 -DA:25,0 -DA:26,0 -DA:28,0 -DA:29,0 -DA:33,0 -DA:35,0 -DA:36,0 -DA:37,0 -LF:9 -LH:1 -end_of_record -SF:lib/commands/list.dart -DA:18,1 -DA:21,1 -DA:22,2 -DA:24,1 -DA:25,0 -DA:28,1 -DA:29,2 -DA:30,1 -DA:32,3 -DA:35,2 -DA:36,2 -LF:11 -LH:10 -end_of_record -SF:lib/commands/remove.dart -DA:17,1 -DA:18,1 -DA:19,1 -DA:20,1 -DA:28,1 -DA:29,4 -DA:31,2 -DA:34,0 -DA:37,3 -DA:39,2 -DA:40,1 -DA:41,0 -LF:12 -LH:10 -end_of_record -SF:lib/commands/use.dart -DA:18,1 -DA:21,1 -DA:22,3 -DA:23,0 -DA:24,0 -DA:26,3 -DA:28,2 -DA:31,0 -DA:32,0 -DA:33,0 -DA:36,3 -DA:38,2 -DA:39,4 -DA:40,1 -LF:14 -LH:9 -end_of_record -SF:lib/commands/version.dart -DA:6,1 -DA:9,0 -DA:12,1 -DA:14,1 -LF:4 -LH:3 -end_of_record -SF:lib/utils/flutter_tools.dart -DA:10,0 -DA:12,0 -DA:16,0 -DA:18,0 -DA:19,0 -DA:21,0 -DA:22,0 -DA:29,1 -DA:30,4 -DA:32,1 -DA:33,2 -DA:37,2 -DA:41,2 -DA:43,2 -DA:44,1 -DA:45,1 -DA:47,2 -DA:48,0 -DA:53,1 -DA:55,3 -DA:56,0 -DA:57,0 -DA:64,1 -DA:65,4 -DA:67,2 -DA:70,2 -DA:74,2 -DA:76,2 -DA:77,1 -DA:78,1 -DA:80,2 -DA:81,0 -DA:93,1 -DA:94,4 -DA:95,2 -DA:96,0 -DA:98,3 -DA:101,1 -DA:102,3 -DA:105,3 -DA:106,3 -DA:110,2 -DA:111,0 -DA:114,2 -DA:119,1 -DA:121,4 -DA:123,2 -DA:124,0 -DA:127,2 -DA:129,1 -DA:130,2 -DA:131,1 -DA:133,2 -DA:134,2 -DA:142,1 -DA:143,4 -DA:144,2 -DA:145,2 -DA:150,1 -DA:151,4 -DA:152,3 -DA:153,3 -DA:155,2 -DA:160,4 -DA:161,2 -DA:162,1 -DA:163,2 -DA:171,1 -DA:174,3 -DA:175,0 -DA:178,4 -DA:180,1 -DA:181,2 -DA:182,4 -DA:184,3 -DA:188,1 -DA:190,0 -DA:191,0 -DA:196,1 -DA:197,4 -DA:198,1 -DA:199,3 -LF:82 -LH:65 -end_of_record -SF:lib/fvm.dart -DA:15,1 -DA:16,1 -DA:18,2 -DA:19,2 -DA:20,2 -DA:21,2 -DA:22,2 -DA:23,2 -DA:24,2 -DA:26,3 -DA:27,0 -DA:28,0 -DA:30,0 -DA:31,0 -DA:32,0 -DA:36,0 -DA:37,2 -LF:17 -LH:11 -end_of_record diff --git a/coverage_badge.svg b/coverage_badge.svg index e5ba3eed..473230f4 100644 --- a/coverage_badge.svg +++ b/coverage_badge.svg @@ -8,13 +8,13 @@ - + coverage coverage - 74% - 74% + 73% + 73% diff --git a/lib/commands/install.dart b/lib/commands/install.dart index d66e348e..f13e7167 100644 --- a/lib/commands/install.dart +++ b/lib/commands/install.dart @@ -1,7 +1,6 @@ import 'package:args/command_runner.dart'; import 'package:fvm/exceptions.dart'; import 'package:fvm/utils/flutter_tools.dart'; -import 'package:fvm/utils/helpers.dart'; import 'package:fvm/utils/logger.dart'; import 'package:fvm/utils/version_installer.dart'; import 'package:io/ansi.dart'; diff --git a/lib/commands/remove.dart b/lib/commands/remove.dart index 0d0d72a6..2595f7d8 100644 --- a/lib/commands/remove.dart +++ b/lib/commands/remove.dart @@ -28,7 +28,7 @@ class RemoveCommand extends Command { void run() async { final version = argResults.arguments[0].toLowerCase(); - final isValidInstall = await isValidFlutterInstall(version); + final isValidInstall = await isSdkInstalled(version); if (!isValidInstall) { throw Exception('Flutter SDK: $version is not installed'); diff --git a/lib/commands/use.dart b/lib/commands/use.dart index 89cdf35b..bd0369cb 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -1,6 +1,5 @@ import 'package:args/command_runner.dart'; import 'package:console/console.dart'; -import 'package:fvm/utils/flutter_tools.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:fvm/utils/logger.dart'; import 'package:fvm/utils/version_installer.dart'; @@ -27,21 +26,19 @@ class UseCommand extends Command { } final version = argResults.arguments[0]; - final isValidInstall = await isValidFlutterInstall(version); + final isInstalled = await isSdkInstalled(version); - if (!isValidInstall) { + if (!isInstalled) { print('Flutter $version is not installed.'); - var inputConfirm = await readInput('Would you like to install it? y/N: '); + var inputConfirm = await readInput('Would you like to install it? Y/n: '); - if (inputConfirm.contains('y')) { + // Install if input is 'y' + if (!inputConfirm.contains('n')) { final installProgress = logger.progress('Installing $version'); await installFlutterVersion(version); finishProgress(installProgress); - await linkProjectFlutterDir(version); logger.stdout(green.wrap('$version is active')); - } else { - print('Done'); } } else { logger.stdout(green.wrap('$version is active')); diff --git a/lib/utils/flutter_tools.dart b/lib/utils/flutter_tools.dart index fbfd09f1..882cedf9 100644 --- a/lib/utils/flutter_tools.dart +++ b/lib/utils/flutter_tools.dart @@ -12,10 +12,9 @@ Future processRunner(String cmd, List args, final manager = ProcessManager(); try { - var spawn = - await manager.spawn(cmd, args, workingDirectory: workingDirectory); + var pr = await manager.spawn(cmd, args, workingDirectory: workingDirectory); - if (await spawn.exitCode != 0) { + if (await pr.exitCode != 0) { throw Exception('Could not run command $cmd: $args'); } await sharedStdIn.terminate(); @@ -29,14 +28,12 @@ Future processRunner(String cmd, List args, Future flutterChannelClone(String channel) async { final channelDirectory = Directory(path.join(kVersionsDir.path, channel)); - if (!isValidFlutterChannel(channel)) { + if (!isFlutterChannel(channel)) { throw ExceptionNotValidChannel('"$channel" is not a valid channel'); } // If it's installed correctly just return and use cached - if (await checkInstalledCorrectly(channel)) { - return; - } + if (await checkInstalledCorrectly(channel)) return; await channelDirectory.create(recursive: true); @@ -64,7 +61,7 @@ Future checkIfGitExists() async { Future flutterVersionClone(String version) async { final versionDirectory = Directory(path.join(kVersionsDir.path, version)); - version = await coerceValidFlutterVersion(version); + version = await inferFlutterVersion(version); // If it's installed correctly just return and use cached if (await checkInstalledCorrectly(version)) { diff --git a/lib/utils/helpers.dart b/lib/utils/helpers.dart index b4084654..688b4e55 100644 --- a/lib/utils/helpers.dart +++ b/lib/utils/helpers.dart @@ -6,7 +6,7 @@ import 'package:path/path.dart' as path; import 'package:fvm/utils/flutter_tools.dart'; /// Returns true if it's a valid Flutter version number -Future coerceValidFlutterVersion(String version) async { +Future inferFlutterVersion(String version) async { if ((await flutterListAllSdks()).contains(version)) { return version; } @@ -18,12 +18,12 @@ Future coerceValidFlutterVersion(String version) async { } /// Returns true if it's a valid Flutter channel -bool isValidFlutterChannel(String channel) { +bool isFlutterChannel(String channel) { return kFlutterChannels.contains(channel); } /// Returns true it's a valid installed version -Future isValidFlutterInstall(String version) async { +Future isSdkInstalled(String version) async { return (await flutterListInstalledSdks()).contains(version); } @@ -60,9 +60,8 @@ Future isCurrentVersion(String version) async { /// [levels] how many levels you would like to go up to search for a version Future projectFlutterLink([Directory dir, int levels = 20]) async { // If there are no levels exit - if (levels == 0) { - return null; - } + if (levels == 0) return null; + Link link; dir ??= kWorkingDirectory; diff --git a/lib/utils/version_installer.dart b/lib/utils/version_installer.dart index 7c733e15..87f41079 100644 --- a/lib/utils/version_installer.dart +++ b/lib/utils/version_installer.dart @@ -7,11 +7,12 @@ Future installFlutterVersion(String flutterVersion) async { throw ExceptionMissingChannelVersion(); } final version = flutterVersion.toLowerCase(); - final isChannel = isValidFlutterChannel(version); + final isChannel = isFlutterChannel(version); if (isChannel) { await flutterChannelClone(version); } else { await flutterVersionClone(version); } + await linkProjectFlutterDir(version); } diff --git a/pubspec.yaml b/pubspec.yaml index d80032ad..328eb152 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ executables: dependencies: args: ^1.5.3 - cli_util: ^0.1.3+2 + cli_util: ^0.2.0 # file_utils: ^0.1.3 console: ^3.1.0 io: ^0.3.3 diff --git a/test/fvm_test.dart b/test/fvm_test.dart index 8b13adf7..fdca557d 100644 --- a/test/fvm_test.dart +++ b/test/fvm_test.dart @@ -7,7 +7,6 @@ import 'package:test/test.dart'; import 'package:path/path.dart' as path; import 'package:fvm/constants.dart'; import 'package:fvm/utils/flutter_tools.dart'; - import 'test_helpers.dart'; final testPath = '$fvmHome/test_path'; @@ -16,12 +15,8 @@ const channel = 'master'; const release = '1.8.0'; void main() { - setUpAll(() async { - await fvmSetUpAll(); - }); - tearDownAll(() async { - await fvmTearDownAll(); - }); + setUpAll(fvmSetUpAll); + tearDownAll(fvmTearDownAll); group('Channel Flow', () { test('Install without version', () async { final args = ['install']; @@ -46,7 +41,7 @@ void main() { expect(correct, true, reason: 'Not Installed Correctly'); expect(existingChannel, channel); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } }); @@ -54,7 +49,7 @@ void main() { try { await fvmRunner(['list']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); @@ -69,12 +64,11 @@ void main() { final channelBin = path.join(kVersionsDir.path, channel, 'bin', 'flutter'); - ; expect(targetBin == channelBin, true); expect(linkExists, true); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } }); @@ -82,7 +76,7 @@ void main() { try { await fvmRunner(['remove', channel, '--verbose']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); diff --git a/test/utils/helpers_test.dart b/test/utils/helpers_test.dart index 6d8989cd..60b160b2 100644 --- a/test/utils/helpers_test.dart +++ b/test/utils/helpers_test.dart @@ -3,23 +3,23 @@ import 'package:fvm/utils/helpers.dart'; void main() { test('Is Valid Flutter Version', () async { - expect(await coerceValidFlutterVersion('1.8.0'), 'v1.8.0'); - expect(await coerceValidFlutterVersion('v1.8.0'), 'v1.8.0'); + expect(await inferFlutterVersion('1.8.0'), 'v1.8.0'); + expect(await inferFlutterVersion('v1.8.0'), 'v1.8.0'); - expect(await coerceValidFlutterVersion('1.9.6'), 'v1.9.6'); - expect(await coerceValidFlutterVersion('v1.9.6'), 'v1.9.6'); + expect(await inferFlutterVersion('1.9.6'), 'v1.9.6'); + expect(await inferFlutterVersion('v1.9.6'), 'v1.9.6'); - expect(await coerceValidFlutterVersion('1.10.5'), 'v1.10.5'); - expect(await coerceValidFlutterVersion('v1.10.5'), 'v1.10.5'); + expect(await inferFlutterVersion('1.10.5'), 'v1.10.5'); + expect(await inferFlutterVersion('v1.10.5'), 'v1.10.5'); - expect(await coerceValidFlutterVersion('1.9.1+hotfix.4'), 'v1.9.1+hotfix.4'); - expect(await coerceValidFlutterVersion('v1.9.1+hotfix.4'), 'v1.9.1+hotfix.4'); + expect(await inferFlutterVersion('1.9.1+hotfix.4'), 'v1.9.1+hotfix.4'); + expect(await inferFlutterVersion('v1.9.1+hotfix.4'), 'v1.9.1+hotfix.4'); - expect(await coerceValidFlutterVersion('1.17.0-dev.3.1'), '1.17.0-dev.3.1'); + expect(await inferFlutterVersion('1.17.0-dev.3.1'), '1.17.0-dev.3.1'); }); test('Not Valid Flutter Version', () async { - expect(coerceValidFlutterVersion('1.8.0.2'), throws); - expect(coerceValidFlutterVersion('v1.17.0-dev.3.1'), throws); + expect(inferFlutterVersion('1.8.0.2'), throwsA(anything)); + expect(inferFlutterVersion('v1.17.0-dev.3.1'), throwsA(anything)); }); } From 9dfe287bc093972edc0710bd0b74e9e425640420 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Tue, 16 Jun 2020 07:59:57 -0400 Subject: [PATCH 04/11] TODO: notes --- lib/commands/use.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/commands/use.dart b/lib/commands/use.dart index eed669d8..1cdaffdf 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -39,6 +39,7 @@ class UseCommand extends Command { final isInstalled = await isSdkInstalled(version); + // TODO: Fix installed conditional if (!isInstalled) { print('Flutter $version is not installed.'); var inputConfirm = await readInput('Would you like to install it? Y/n: '); From 3d8c4c0c78c6cc7809546fb8786916ed82b3937c Mon Sep 17 00:00:00 2001 From: leoafarias Date: Tue, 16 Jun 2020 09:36:19 -0400 Subject: [PATCH 05/11] Linter fixes --- test/fvm_test.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/fvm_test.dart b/test/fvm_test.dart index 2fde0e4d..9f9a62d3 100644 --- a/test/fvm_test.dart +++ b/test/fvm_test.dart @@ -84,7 +84,7 @@ void main() { expect(targetDir == channelDir, true); expect(linkExists, true); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } }); @@ -112,7 +112,7 @@ void main() { expect(correct, true, reason: 'Not Installed Correctly'); expect(existingRelease, 'v$release'); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); @@ -131,7 +131,7 @@ void main() { expect(targetBin == releaseBin, true); expect(linkExists, true); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } }); @@ -139,7 +139,7 @@ void main() { try { await fvmRunner(['list', '--verbose']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); @@ -149,7 +149,7 @@ void main() { try { await fvmRunner(['remove', release, '--verbose']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); @@ -161,7 +161,7 @@ void main() { try { await fvmRunner(['config', '--cache-path', testPath]); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(testPath, kVersionsDir.path); }); @@ -170,7 +170,7 @@ void main() { try { await fvmRunner(['config', '--ls']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); }); @@ -181,7 +181,7 @@ void main() { try { await fvmRunner(['version']); } on Exception catch (e) { - fail("Exception thrown, $e"); + fail('Exception thrown, $e'); } expect(true, true); }); From d31a5389583d21b8fe591f30541917e249996155 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Wed, 17 Jun 2020 06:24:03 -0400 Subject: [PATCH 06/11] Global version and check if its run on flutter project --- lib/commands/install.dart | 6 ------ lib/commands/list.dart | 13 ++++++++++--- lib/commands/use.dart | 19 +++++++++++-------- lib/constants.dart | 5 ++++- lib/utils/flutter_tools.dart | 4 ++-- lib/utils/helpers.dart | 5 +++++ lib/utils/version_installer.dart | 5 ++++- pubspec.yaml | 4 ++-- test/fvm_test.dart | 8 ++++---- 9 files changed, 42 insertions(+), 27 deletions(-) diff --git a/lib/commands/install.dart b/lib/commands/install.dart index f13e7167..afa1c971 100644 --- a/lib/commands/install.dart +++ b/lib/commands/install.dart @@ -1,9 +1,7 @@ import 'package:args/command_runner.dart'; import 'package:fvm/exceptions.dart'; import 'package:fvm/utils/flutter_tools.dart'; -import 'package:fvm/utils/logger.dart'; import 'package:fvm/utils/version_installer.dart'; -import 'package:io/ansi.dart'; /// Installs Flutter SDK class InstallCommand extends Command { @@ -26,10 +24,6 @@ class InstallCommand extends Command { } final version = argResults.arguments[0].toLowerCase(); - final progress = logger.progress(green.wrap('Downloading $version')); - await installFlutterVersion(version); - - finishProgress(progress); } } diff --git a/lib/commands/list.dart b/lib/commands/list.dart index ea3ed7ed..ce0a3d28 100644 --- a/lib/commands/list.dart +++ b/lib/commands/list.dart @@ -1,8 +1,10 @@ +import 'dart:io'; + +import 'package:fvm/constants.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:io/ansi.dart'; import 'package:args/command_runner.dart'; import 'package:fvm/utils/flutter_tools.dart'; -import 'package:fvm/utils/logger.dart'; /// List installed SDK Versions class ListCommand extends Command { @@ -22,14 +24,19 @@ class ListCommand extends Command { final choices = await flutterListInstalledSdks(); if (choices.isEmpty) { - throw Exception('No SDKs have been installed yet.'); + print(cyan.wrap( + 'No SDKs have been installed yet. Flutter SDKs installed outside of fvm will not be displayed.')); + exit(1); } + // Print where versions are stored + print('Versions path: ${yellow.wrap(kVersionsDir.path)}'); + Future printVersions(String version) async { if (await isCurrentVersion(version)) { version = '$version (current)'; } - logger.stdout(green.wrap(version)); + print(cyan.wrap(version)); } for (var choice in choices) { diff --git a/lib/commands/use.dart b/lib/commands/use.dart index 1cdaffdf..2dcb8993 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:args/command_runner.dart'; import 'package:console/console.dart'; import 'package:fvm/constants.dart'; @@ -31,15 +33,20 @@ class UseCommand extends Command { @override Future run() async { + // Check if it's Flutter project + if (!isFlutterProject()) { + throw Exception('Run `use` command on the root of a Flutter project'); + } + if (argResults.rest.isEmpty) { final instruction = yellow.wrap('fvm use '); throw Exception('Please provide a version. $instruction'); } final version = argResults.rest[0]; + final useGlobally = argResults['global'] == true; final isInstalled = await isSdkInstalled(version); - // TODO: Fix installed conditional if (!isInstalled) { print('Flutter $version is not installed.'); var inputConfirm = await readInput('Would you like to install it? Y/n: '); @@ -49,14 +56,12 @@ class UseCommand extends Command { final installProgress = logger.progress('Installing $version'); await installFlutterVersion(version); finishProgress(installProgress); - logger.stdout(green.wrap('$version is active')); + } else { + // If do not install exist + exit(0); } - } else { - logger.stdout(green.wrap('$version is active')); } - final useGlobally = argResults['global'] == true; - if (useGlobally) { await linkProjectFlutterDirGlobally(version); } else { @@ -71,7 +76,5 @@ class UseCommand extends Command { } else { logger.stdout(green.wrap('$version is active')); } - - finishProgress(progress); } } diff --git a/lib/constants.dart b/lib/constants.dart index 67419888..cec357bd 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -14,7 +14,10 @@ final kFvmDirectory = Platform.script.toString(); final kWorkingDirectory = Directory.current; /// Local Project Flutter Link -final kLocalFlutterLink = Link(path.join(kWorkingDirectory.path, 'fvm')); +final kProjectSdkLink = Link(path.join(kWorkingDirectory.path, 'fvm')); + +/// Flutter Project pubspec +final kProjectPubspec = File(path.join(kWorkingDirectory.path, 'pubspec.yaml')); /// FVM Home directory String get fvmHome { diff --git a/lib/utils/flutter_tools.dart b/lib/utils/flutter_tools.dart index 447abb25..452fd21d 100644 --- a/lib/utils/flutter_tools.dart +++ b/lib/utils/flutter_tools.dart @@ -193,10 +193,10 @@ Future> flutterListInstalledSdks() async { Future linkProjectFlutterDir(String version) async { final versionBin = Directory(path.join(kVersionsDir.path, version, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter')); - await linkDir(kLocalFlutterLink, versionBin); + await linkDir(kProjectSdkLink, versionBin); } Future linkProjectFlutterDirGlobally(String version) async { final versionDir = Directory(path.join(kVersionsDir.path, version)); await linkDir(kDefaultFlutterLink, versionDir); -} \ No newline at end of file +} diff --git a/lib/utils/helpers.dart b/lib/utils/helpers.dart index 688b4e55..dffabedd 100644 --- a/lib/utils/helpers.dart +++ b/lib/utils/helpers.dart @@ -22,6 +22,11 @@ bool isFlutterChannel(String channel) { return kFlutterChannels.contains(channel); } +// Checks if its flutter project +bool isFlutterProject() { + return kProjectPubspec.existsSync(); +} + /// Returns true it's a valid installed version Future isSdkInstalled(String version) async { return (await flutterListInstalledSdks()).contains(version); diff --git a/lib/utils/version_installer.dart b/lib/utils/version_installer.dart index 87f41079..6187a862 100644 --- a/lib/utils/version_installer.dart +++ b/lib/utils/version_installer.dart @@ -1,6 +1,8 @@ import 'package:fvm/exceptions.dart'; import 'package:fvm/utils/flutter_tools.dart'; import 'package:fvm/utils/helpers.dart'; +import 'package:fvm/utils/logger.dart'; +import 'package:io/ansi.dart'; Future installFlutterVersion(String flutterVersion) async { if (flutterVersion == null) { @@ -9,10 +11,11 @@ Future installFlutterVersion(String flutterVersion) async { final version = flutterVersion.toLowerCase(); final isChannel = isFlutterChannel(version); + final progress = logger.progress(green.wrap('Downloading $version')); if (isChannel) { await flutterChannelClone(version); } else { await flutterVersionClone(version); } - await linkProjectFlutterDir(version); + finishProgress(progress); } diff --git a/pubspec.yaml b/pubspec.yaml index 328eb152..7d93f850 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: dev_dependencies: pedantic: ^1.8.0 - test: ^1.6.0 - test_coverage: ^0.3.0 + test: ^1.14.0 + test_coverage: ^0.4.1 build_runner: ^1.0.0 build_version: ^2.0.1 diff --git a/test/fvm_test.dart b/test/fvm_test.dart index 9f9a62d3..c5191df2 100644 --- a/test/fvm_test.dart +++ b/test/fvm_test.dart @@ -58,9 +58,9 @@ void main() { test('Use Channel', () async { try { await fvmRunner(['use', channel, '--verbose']); - final linkExists = await kLocalFlutterLink.exists(); + final linkExists = await kProjectSdkLink.exists(); - final targetBin = await kLocalFlutterLink.target(); + final targetBin = await kProjectSdkLink.target(); final channelBin = path.join(kVersionsDir.path, channel, 'bin', 'flutter'); @@ -121,9 +121,9 @@ void main() { test('Use Release', () async { try { await fvmRunner(['use', release, '--verbose']); - final linkExists = await kLocalFlutterLink.exists(); + final linkExists = await kProjectSdkLink.exists(); - final targetBin = await kLocalFlutterLink.target(); + final targetBin = await kProjectSdkLink.target(); final releaseBin = path.join(kVersionsDir.path, release, 'bin', 'flutter'); From 392e09e500221b3360e1b3884acc113b770a1701 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 18 Jun 2020 08:40:11 -0400 Subject: [PATCH 07/11] Project config and flutter sdk link --- lib/commands/config.dart | 4 +-- lib/commands/flutter.dart | 18 ++---------- lib/commands/use.dart | 32 ++++----------------- lib/constants.dart | 16 +++++++++-- lib/utils/flutter_tools.dart | 31 ++++---------------- lib/utils/helpers.dart | 53 ++++++++++++++--------------------- lib/utils/project_config.dart | 37 ++++++++++++++++++++++++ test/fvm_test.dart | 8 +++--- 8 files changed, 91 insertions(+), 108 deletions(-) create mode 100644 lib/utils/project_config.dart diff --git a/lib/commands/config.dart b/lib/commands/config.dart index c400be55..6b773f71 100644 --- a/lib/commands/config.dart +++ b/lib/commands/config.dart @@ -1,7 +1,6 @@ import 'package:args/command_runner.dart'; import 'package:io/ansi.dart'; import 'package:fvm/utils/config_utils.dart'; -import 'package:fvm/utils/logger.dart'; /// Config fvm options. class ConfigCommand extends Command { @@ -14,6 +13,7 @@ class ConfigCommand extends Command { /// Constructor ConfigCommand() { argParser + ..addOption('defaultVersion', abbr: 'd', help: 'Flutter default version') ..addOption('cache-path', abbr: 'c', help: 'Path to store Flutter cached versions') ..addFlag('ls', help: 'Lists all config options'); @@ -29,7 +29,7 @@ class ConfigCommand extends Command { if (argResults['ls'] != null) { final configOptions = ConfigUtils().displayAllConfig(); if (configOptions.isNotEmpty) { - logger.stdout(green.wrap(configOptions)); + print(green.wrap(configOptions)); } else { throw Exception('No configuration has been set'); } diff --git a/lib/commands/flutter.dart b/lib/commands/flutter.dart index 7bc2fe50..bba7c729 100644 --- a/lib/commands/flutter.dart +++ b/lib/commands/flutter.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:args/command_runner.dart'; import 'package:fvm/constants.dart'; import 'package:fvm/utils/flutter_tools.dart'; @@ -23,19 +21,9 @@ class FlutterCommand extends Command { @override Future run() async { - final flutterProjectLink = await projectFlutterLink(); - - if (flutterProjectLink == null || !await flutterProjectLink.exists()) { - throw Exception('No FVM config found. Create with command'); - } - - try { - final targetLink = File(await flutterProjectLink.target()); + final flutterSdkPath = getFlutterSdkExecPath(); - await processRunner(targetLink.path, argResults.arguments, - workingDirectory: kWorkingDirectory.path); - } on Exception { - rethrow; - } + await flutterProcessRunner(flutterSdkPath, argResults.arguments, + workingDirectory: kWorkingDirectory.path); } } diff --git a/lib/commands/use.dart b/lib/commands/use.dart index 2dcb8993..17f4d87a 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -2,13 +2,11 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:console/console.dart'; -import 'package:fvm/constants.dart'; -import 'package:fvm/utils/flutter_tools.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:fvm/utils/logger.dart'; +import 'package:fvm/utils/project_config.dart'; import 'package:fvm/utils/version_installer.dart'; import 'package:io/ansi.dart'; -import 'package:path/path.dart' as path; /// Use an installed SDK version class UseCommand extends Command { @@ -21,15 +19,7 @@ class UseCommand extends Command { final description = 'Which Flutter SDK Version you would like to use'; /// Constructor - UseCommand() { - argParser - ..addFlag( - 'global', - help: - 'Creates a symbolic link to the version specified in /default/', - negatable: false, - ); - } + UseCommand(); @override Future run() async { @@ -43,7 +33,6 @@ class UseCommand extends Command { throw Exception('Please provide a version. $instruction'); } final version = argResults.rest[0]; - final useGlobally = argResults['global'] == true; final isInstalled = await isSdkInstalled(version); @@ -51,7 +40,7 @@ class UseCommand extends Command { print('Flutter $version is not installed.'); var inputConfirm = await readInput('Would you like to install it? Y/n: '); - // Install if input is 'y' + // Install if input is confirmed if (!inputConfirm.contains('n')) { final installProgress = logger.progress('Installing $version'); await installFlutterVersion(version); @@ -62,19 +51,8 @@ class UseCommand extends Command { } } - if (useGlobally) { - await linkProjectFlutterDirGlobally(version); - } else { - await linkProjectFlutterDir(version); - } + updateProjectConfig(version); - if (useGlobally) { - final flutterSDKBinariesPath = path.join(kDefaultFlutterLink.path, 'bin'); - logger.stdout(green.wrap('$version linked succesfully')); - logger.stdout(cyan.wrap( - 'Make sure sure to add $flutterSDKBinariesPath to your PATH environment variable')); - } else { - logger.stdout(green.wrap('$version is active')); - } + print(green.wrap('$version is active')); } } diff --git a/lib/constants.dart b/lib/constants.dart index cec357bd..6032fd89 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -4,6 +4,8 @@ import 'package:fvm/utils/config_utils.dart'; final _configUtils = ConfigUtils(); +const kFvmDirName = '.fvm'; + /// Flutter Repo Address const kFlutterRepo = 'https://github.com/flutter/flutter.git'; @@ -13,11 +15,21 @@ final kFvmDirectory = Platform.script.toString(); /// Working Directory for FVM final kWorkingDirectory = Directory.current; +/// Local Project Directory +final kProjectFvmDir = + Directory(path.join(kWorkingDirectory.path, kFvmDirName)); + +/// Local Project Config +final kProjectFvmConfigJson = + File(path.join(kProjectFvmDir.path, 'fvm_config.json')); + /// Local Project Flutter Link -final kProjectSdkLink = Link(path.join(kWorkingDirectory.path, 'fvm')); +final kProjectFvmSdkSymlink = + Link(path.join(kProjectFvmDir.path, 'flutter_sdk')); /// Flutter Project pubspec -final kProjectPubspec = File(path.join(kWorkingDirectory.path, 'pubspec.yaml')); +final kLocalProjectPubspec = + File(path.join(kWorkingDirectory.path, 'pubspec.yaml')); /// FVM Home directory String get fvmHome { diff --git a/lib/utils/flutter_tools.dart b/lib/utils/flutter_tools.dart index 452fd21d..41bca99b 100644 --- a/lib/utils/flutter_tools.dart +++ b/lib/utils/flutter_tools.dart @@ -7,20 +7,13 @@ import 'package:io/io.dart'; import 'package:fvm/utils/logger.dart'; /// Runs a process -Future processRunner(String cmd, List args, +Future flutterProcessRunner(String cmd, List args, {String workingDirectory}) async { final manager = ProcessManager(); - try { - var pr = await manager.spawn(cmd, args, workingDirectory: workingDirectory); - - if (await pr.exitCode != 0) { - throw Exception('Could not run command $cmd: $args'); - } - await sharedStdIn.terminate(); - } on Exception { - rethrow; - } + var pr = await manager.spawn(cmd, args, workingDirectory: workingDirectory); + final exitCode = await pr.exitCode; + exit(exitCode); } /// Clones Flutter SDK from Channel @@ -79,13 +72,6 @@ Future flutterVersionClone(String version) async { } } -/// Gets Flutter version from project -// Future flutterGetProjectVersion() async { -// final target = await kLocalFlutterLink.target(); -// print(target); -// return await _gitGetVersion(target); -// } - /// Gets SDK Version Future flutterSdkVersion(String branch) async { final branchDirectory = Directory(path.join(kVersionsDir.path, branch)); @@ -189,14 +175,7 @@ Future> flutterListInstalledSdks() async { } } -/// Links Flutter Dir to existsd SDK -Future linkProjectFlutterDir(String version) async { - final versionBin = Directory(path.join(kVersionsDir.path, version, 'bin', - Platform.isWindows ? 'flutter.bat' : 'flutter')); - await linkDir(kProjectSdkLink, versionBin); -} - Future linkProjectFlutterDirGlobally(String version) async { final versionDir = Directory(path.join(kVersionsDir.path, version)); - await linkDir(kDefaultFlutterLink, versionDir); + await createLink(kDefaultFlutterLink, versionDir); } diff --git a/lib/utils/helpers.dart b/lib/utils/helpers.dart index dffabedd..a3d560a3 100644 --- a/lib/utils/helpers.dart +++ b/lib/utils/helpers.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:fvm/constants.dart'; import 'package:fvm/exceptions.dart'; +import 'package:fvm/utils/project_config.dart'; import 'package:path/path.dart' as path; import 'package:fvm/utils/flutter_tools.dart'; @@ -24,7 +25,7 @@ bool isFlutterChannel(String channel) { // Checks if its flutter project bool isFlutterProject() { - return kProjectPubspec.existsSync(); + return kLocalProjectPubspec.existsSync(); } /// Returns true it's a valid installed version @@ -33,15 +34,15 @@ Future isSdkInstalled(String version) async { } /// Moves assets from theme directory into brand-app -Future linkDir( +void createLink( Link source, FileSystemEntity target, ) async { try { - if (await source.exists()) { - await source.delete(); + if (source.existsSync()) { + source.deleteSync(); } - await source.create(target.path); + source.createSync(target.path); } on Exception catch (err) { logVerboseError(err); throw Exception('Sorry could not link ${target.path}'); @@ -50,34 +51,22 @@ Future linkDir( /// Check if it is the current version. Future isCurrentVersion(String version) async { - final link = await projectFlutterLink(); - if (link != null) { - return Uri.file(File(await link.target()).parent.parent.path, - windows: Platform.isWindows) - .pathSegments - .last == - version; - } - return false; + final config = readProjectConfig(); + return version == config.flutterSdkVersion; } -/// The fvm link of the current working directory. -/// [levels] how many levels you would like to go up to search for a version -Future projectFlutterLink([Directory dir, int levels = 20]) async { - // If there are no levels exit - if (levels == 0) return null; - - Link link; - - dir ??= kWorkingDirectory; - - link = Link(path.join(dir.path, 'fvm')); - - if (await link.exists()) { - return link; - } else if (path.rootPrefix(link.path) == dir.path) { - return null; +/// The Flutter SDK Path referenced on FVM +String getFlutterSdkPath() { + try { + final config = readProjectConfig(); + return path.join(kVersionsDir.path, config.flutterSdkVersion); + } on Exception catch (e) { + // TODO: Clean up exception + throw ExceptionCouldNotReadConfig('$e'); } - levels--; - return await projectFlutterLink(dir, levels); +} + +String getFlutterSdkExecPath() { + return path.join(getFlutterSdkPath(), 'bin', + Platform.isWindows ? 'flutter.bat' : 'flutter'); } diff --git a/lib/utils/project_config.dart b/lib/utils/project_config.dart new file mode 100644 index 00000000..c8c22e0e --- /dev/null +++ b/lib/utils/project_config.dart @@ -0,0 +1,37 @@ +import 'dart:convert'; +import 'dart:io'; +import 'package:fvm/constants.dart'; +import 'package:fvm/utils/helpers.dart'; + +class ProjectConfig { + final String flutterSdkVersion; + ProjectConfig(this.flutterSdkVersion); + + ProjectConfig.fromJson(Map json) + : flutterSdkVersion = json['flutterSdkVersion'] as String; + + Map toJson() => {'flutterSdkVersion': flutterSdkVersion}; +} + +void updateProjectConfig(String version) { + if (kProjectFvmConfigJson.existsSync() == false) { + kProjectFvmConfigJson.createSync(recursive: true); + } + saveProjectConfig(ProjectConfig(version)); + updateFlutterSdkBinLink(); +} + +void updateFlutterSdkBinLink() { + final flutterSdk = getFlutterSdkPath(); + createLink(kProjectFvmSdkSymlink, File(flutterSdk)); +} + +ProjectConfig readProjectConfig() { + final jsonString = kProjectFvmConfigJson.readAsStringSync(); + final projectConfigMap = jsonDecode(jsonString) as Map; + return ProjectConfig.fromJson(projectConfigMap); +} + +void saveProjectConfig(ProjectConfig config) { + kProjectFvmConfigJson.writeAsStringSync(jsonEncode(config)); +} diff --git a/test/fvm_test.dart b/test/fvm_test.dart index c5191df2..d2cfb8eb 100644 --- a/test/fvm_test.dart +++ b/test/fvm_test.dart @@ -58,9 +58,9 @@ void main() { test('Use Channel', () async { try { await fvmRunner(['use', channel, '--verbose']); - final linkExists = await kProjectSdkLink.exists(); + final linkExists = await kProjectFvmSdkSymlink.exists(); - final targetBin = await kProjectSdkLink.target(); + final targetBin = await kProjectFvmSdkSymlink.target(); final channelBin = path.join(kVersionsDir.path, channel, 'bin', 'flutter'); @@ -121,9 +121,9 @@ void main() { test('Use Release', () async { try { await fvmRunner(['use', release, '--verbose']); - final linkExists = await kProjectSdkLink.exists(); + final linkExists = await kProjectFvmSdkSymlink.exists(); - final targetBin = await kProjectSdkLink.target(); + final targetBin = await kProjectFvmSdkSymlink.target(); final releaseBin = path.join(kVersionsDir.path, release, 'bin', 'flutter'); From 28587822231c2107ea8841cd1b6ef298c4bb79af Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 18 Jun 2020 16:36:06 -0400 Subject: [PATCH 08/11] Refactored commands and fvm config path. --- .gitignore | 1 + README.md | 12 ++++++-- lib/commands/config.dart | 4 +-- lib/commands/flutter.dart | 2 ++ lib/commands/install.dart | 4 +-- lib/commands/list.dart | 13 +++++---- lib/commands/remove.dart | 2 +- lib/constants.dart | 1 + lib/utils/config_utils.dart | 10 ++----- lib/utils/confirm.dart | 8 +++++ lib/utils/flutter_tools.dart | 47 ++++++++++-------------------- lib/utils/guards.dart | 39 +++++++++++++++++++++++++ lib/utils/helpers.dart | 34 +++++++++++++++------ lib/utils/print.dart | 20 +++++++++++++ lib/utils/project_config.dart | 4 ++- test/fvm_test.dart | 26 ++++++++--------- test/utils/flutter_tools_test.dart | 10 +++---- 17 files changed, 157 insertions(+), 80 deletions(-) create mode 100644 lib/utils/confirm.dart create mode 100644 lib/utils/guards.dart create mode 100644 lib/utils/print.dart diff --git a/.gitignore b/.gitignore index afcd3a9d..8e9041b1 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ fvm .settings/ .vscode/ coverage/lcov.info +.fvm diff --git a/README.md b/README.md index 7f474521..38cdf1c5 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Using the remove command will uninstall the SDK version locally. This will impac ### List Installed Versions -List all the versions that are installed on your machine. +List all the versions that are installed on your machine. This command will also output where FVM stores the SDK versions. ```bash > fvm list @@ -107,7 +107,7 @@ This will run `flutter run` command using the local project SDK. If no FVM confi FVM creates a symbolic link within your project called **fvm** which links to the installed version of the SDK. ```bash -> ./fvm run +> .fvm/flutter/bin run ``` This will run `flutter run` command using the local project SDK. @@ -127,6 +127,14 @@ Add the following to your settings.json. This will list list all Flutter SDKs in ] ``` +#### Android Studio + +copy the path of fvm symbolic link in your root project directory. +example {fvm-path}/versions/beta/bin/flutter +in the Android Studio menĂ¹ open Languages & Frameworks -> Flutter or search for Flutter and change Flutter SDK path to the previous path +Apply the changes +You now can Run and Debug with the selected versions of Flutter. + [Add your IDE instructions here](https://github.com/leoafarias/fvm/issues) ## Working with this repo diff --git a/lib/commands/config.dart b/lib/commands/config.dart index 6b773f71..09b05e29 100644 --- a/lib/commands/config.dart +++ b/lib/commands/config.dart @@ -1,5 +1,5 @@ import 'package:args/command_runner.dart'; -import 'package:io/ansi.dart'; +import 'package:fvm/utils/print.dart'; import 'package:fvm/utils/config_utils.dart'; /// Config fvm options. @@ -29,7 +29,7 @@ class ConfigCommand extends Command { if (argResults['ls'] != null) { final configOptions = ConfigUtils().displayAllConfig(); if (configOptions.isNotEmpty) { - print(green.wrap(configOptions)); + Print.success(configOptions); } else { throw Exception('No configuration has been set'); } diff --git a/lib/commands/flutter.dart b/lib/commands/flutter.dart index bba7c729..faa403ae 100644 --- a/lib/commands/flutter.dart +++ b/lib/commands/flutter.dart @@ -1,6 +1,7 @@ import 'package:args/command_runner.dart'; import 'package:fvm/constants.dart'; import 'package:fvm/utils/flutter_tools.dart'; +import 'package:fvm/utils/guards.dart'; import 'package:fvm/utils/helpers.dart'; import 'package:args/args.dart'; @@ -21,6 +22,7 @@ class FlutterCommand extends Command { @override Future run() async { + Guards.isFlutterProject(); final flutterSdkPath = getFlutterSdkExecPath(); await flutterProcessRunner(flutterSdkPath, argResults.arguments, diff --git a/lib/commands/install.dart b/lib/commands/install.dart index afa1c971..344b57da 100644 --- a/lib/commands/install.dart +++ b/lib/commands/install.dart @@ -1,6 +1,6 @@ import 'package:args/command_runner.dart'; import 'package:fvm/exceptions.dart'; -import 'package:fvm/utils/flutter_tools.dart'; +import 'package:fvm/utils/guards.dart'; import 'package:fvm/utils/version_installer.dart'; /// Installs Flutter SDK @@ -18,7 +18,7 @@ class InstallCommand extends Command { @override void run() async { - await checkIfGitExists(); + Guards.isGitInstalled(); if (argResults.arguments.isEmpty) { throw ExceptionMissingChannelVersion(); } diff --git a/lib/commands/list.dart b/lib/commands/list.dart index ce0a3d28..26fd11ee 100644 --- a/lib/commands/list.dart +++ b/lib/commands/list.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:fvm/constants.dart'; import 'package:fvm/utils/helpers.dart'; +import 'package:fvm/utils/print.dart'; import 'package:io/ansi.dart'; import 'package:args/command_runner.dart'; import 'package:fvm/utils/flutter_tools.dart'; @@ -21,22 +22,22 @@ class ListCommand extends Command { @override Future run() async { - final choices = await flutterListInstalledSdks(); + final choices = flutterListInstalledSdks(); if (choices.isEmpty) { - print(cyan.wrap( - 'No SDKs have been installed yet. Flutter SDKs installed outside of fvm will not be displayed.')); - exit(1); + Print.info( + 'No SDKs have been installed yet. Flutter SDKs installed outside of fvm will not be displayed.'); + exit(0); } // Print where versions are stored print('Versions path: ${yellow.wrap(kVersionsDir.path)}'); Future printVersions(String version) async { - if (await isCurrentVersion(version)) { + if (isCurrentVersion(version)) { version = '$version (current)'; } - print(cyan.wrap(version)); + Print.info(version); } for (var choice in choices) { diff --git a/lib/commands/remove.dart b/lib/commands/remove.dart index 2595f7d8..f87a284a 100644 --- a/lib/commands/remove.dart +++ b/lib/commands/remove.dart @@ -28,7 +28,7 @@ class RemoveCommand extends Command { void run() async { final version = argResults.arguments[0].toLowerCase(); - final isValidInstall = await isSdkInstalled(version); + final isValidInstall = await isFlutterVersionInstalled(version); if (!isValidInstall) { throw Exception('Flutter SDK: $version is not installed'); diff --git a/lib/constants.dart b/lib/constants.dart index 6032fd89..97074bf5 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -60,6 +60,7 @@ Directory get kVersionsDir { /// Where Default Flutter SDK is stored Link get kDefaultFlutterLink => Link(path.join(fvmHome, 'default')); +String get kDefaultFlutterPath => path.join(kDefaultFlutterLink.path, 'bin'); /// Flutter Channels final kFlutterChannels = ['master', 'stable', 'dev', 'beta']; diff --git a/lib/utils/config_utils.dart b/lib/utils/config_utils.dart index 109c9c3a..a4f6a0c5 100644 --- a/lib/utils/config_utils.dart +++ b/lib/utils/config_utils.dart @@ -70,19 +70,15 @@ class ConfigUtils { } /// Removes Config file - Future removeConfig() async { - if (await kConfigFile.exists()) { - await kConfigFile.delete(); - } + void removeConfig() { + if (kConfigFile.existsSync()) kConfigFile.deleteSync(); } /// get flutter stored path. String getStoredPath() { final path = getValue(kConfigFlutterStoredKey); - if (path == null) { - return null; - } + if (path == null) return null; final type = FileSystemEntity.typeSync(path, followLinks: true); if (type == FileSystemEntityType.directory) { diff --git a/lib/utils/confirm.dart b/lib/utils/confirm.dart new file mode 100644 index 00000000..7553e801 --- /dev/null +++ b/lib/utils/confirm.dart @@ -0,0 +1,8 @@ +import 'package:console/console.dart'; + +/// Displays notice for confirmation +Future confirm(String message) async { + final response = await readInput('$message Y/n: '); + // Return true unless 'n' + return !response.contains('n'); +} diff --git a/lib/utils/flutter_tools.dart b/lib/utils/flutter_tools.dart index 41bca99b..7c375741 100644 --- a/lib/utils/flutter_tools.dart +++ b/lib/utils/flutter_tools.dart @@ -2,9 +2,9 @@ import 'dart:io'; import 'package:fvm/constants.dart'; import 'package:fvm/exceptions.dart'; import 'package:fvm/utils/helpers.dart'; +import 'package:fvm/utils/print.dart'; import 'package:path/path.dart' as path; import 'package:io/io.dart'; -import 'package:fvm/utils/logger.dart'; /// Runs a process Future flutterProcessRunner(String cmd, List args, @@ -26,7 +26,7 @@ Future flutterChannelClone(String channel) async { } // If it's installed correctly just return and use cached - if (await checkInstalledCorrectly(channel)) return; + if (isInstalledCorrectly(channel)) return; await channelDirectory.create(recursive: true); @@ -39,16 +39,6 @@ Future flutterChannelClone(String channel) async { } } -/// Check if Git is installed -Future checkIfGitExists() async { - try { - await Process.run('git', ['--version']); - } on ProcessException { - throw Exception( - 'You need Git Installed to run fvm. Go to https://git-scm.com/downloads'); - } -} - /// Clones Flutter SDK from Version Number /// Returns exists:true if comes from cache or false if its new fetch. Future flutterVersionClone(String version) async { @@ -57,9 +47,7 @@ Future flutterVersionClone(String version) async { version = await inferFlutterVersion(version); // If it's installed correctly just return and use cached - if (await checkInstalledCorrectly(version)) { - return; - } + if (isInstalledCorrectly(version)) return; await versionDirectory.create(recursive: true); @@ -75,7 +63,7 @@ Future flutterVersionClone(String version) async { /// Gets SDK Version Future flutterSdkVersion(String branch) async { final branchDirectory = Directory(path.join(kVersionsDir.path, branch)); - if (!await branchDirectory.exists()) { + if (!branchDirectory.existsSync()) { throw Exception('Could not get version from SDK that is not installed'); } return await _gitGetVersion(branchDirectory.path); @@ -122,28 +110,25 @@ Future> flutterListAllSdks() async { } /// Removes a Version of Flutter SDK -Future flutterSdkRemove(String version) async { +void flutterSdkRemove(String version) { final versionDir = Directory(path.join(kVersionsDir.path, version)); - if (await versionDir.exists()) { - await versionDir.delete(recursive: true); + if (versionDir.existsSync()) { + versionDir.deleteSync(recursive: true); } } /// Check if version is from git -Future checkInstalledCorrectly(String version) async { +bool isInstalledCorrectly(String version) { final versionDir = Directory(path.join(kVersionsDir.path, version)); final gitDir = Directory(path.join(versionDir.path, '.github')); final flutterBin = Directory(path.join(versionDir.path, 'bin')); // Check if version directory exists - if (!await versionDir.exists()) { - return false; - } + if (!versionDir.existsSync()) return false; // Check if version directory is from git - if (!await gitDir.exists() || !await flutterBin.exists()) { - logger.stdout( - '$version exists but was not setup correctly. Doing cleanup...'); - await flutterSdkRemove(version); + if (!gitDir.existsSync() || !flutterBin.existsSync()) { + print('$version exists but was not setup correctly. Doing cleanup...'); + flutterSdkRemove(version); return false; } @@ -151,18 +136,18 @@ Future checkInstalledCorrectly(String version) async { } /// Lists Installed Flutter SDK Version -Future> flutterListInstalledSdks() async { +List flutterListInstalledSdks() { try { // Returns empty array if directory does not exist - if (!await kVersionsDir.exists()) { + if (!kVersionsDir.existsSync()) { return []; } - final versions = await kVersionsDir.list().toList(); + final versions = kVersionsDir.listSync().toList(); var installedVersions = []; for (var version in versions) { - if (await FileSystemEntity.type(version.path) == + if (FileSystemEntity.typeSync(version.path) == FileSystemEntityType.directory) { installedVersions.add(path.basename(version.path)); } diff --git a/lib/utils/guards.dart b/lib/utils/guards.dart new file mode 100644 index 00000000..081becc1 --- /dev/null +++ b/lib/utils/guards.dart @@ -0,0 +1,39 @@ +// Checks if its flutter project +import 'dart:io'; + +import 'package:fvm/constants.dart'; +import 'package:fvm/exceptions.dart'; +import 'package:fvm/utils/helpers.dart'; + +/// Guards +class Guards { + /// Checks if its on the root of a Flutter project + static void isFlutterProject() { + final isFlutter = kLocalProjectPubspec.existsSync(); + if (!isFlutter) { + throw Exception('Run this FVM command at the root of a Flutter project'); + } + } + + /// Check if Git is installed + static void isGitInstalled() { + try { + Process.runSync('git', ['--version']); + } on ProcessException { + throw Exception( + 'You need Git Installed to run fvm. Go to https://git-scm.com/downloads'); + } + } + + /// Make sure version is valid + static Future isFlutterVersion(String version) async { + // Check if its a channel + if (isFlutterChannel(version)) return; + // Check if ts a version + final flutterVersion = await inferFlutterVersion(version); + if (flutterVersion == null) { + throw ExceptionNotValidVersion( + '"$version" is not a valid Flutter SDK version'); + } + } +} diff --git a/lib/utils/helpers.dart b/lib/utils/helpers.dart index a3d560a3..c923dfc9 100644 --- a/lib/utils/helpers.dart +++ b/lib/utils/helpers.dart @@ -2,17 +2,22 @@ import 'dart:io'; import 'package:fvm/constants.dart'; import 'package:fvm/exceptions.dart'; +import 'package:fvm/utils/confirm.dart'; +import 'package:fvm/utils/logger.dart'; +import 'package:fvm/utils/print.dart'; import 'package:fvm/utils/project_config.dart'; +import 'package:fvm/utils/version_installer.dart'; import 'package:path/path.dart' as path; import 'package:fvm/utils/flutter_tools.dart'; /// Returns true if it's a valid Flutter version number Future inferFlutterVersion(String version) async { - if ((await flutterListAllSdks()).contains(version)) { + final versions = await flutterListAllSdks(); + if ((versions).contains(version)) { return version; } final prefixedVersion = 'v$version'; - if ((await flutterListAllSdks()).contains(prefixedVersion)) { + if ((versions).contains(prefixedVersion)) { return prefixedVersion; } throw ExceptionNotValidVersion('"$version" is not a valid version'); @@ -23,14 +28,25 @@ bool isFlutterChannel(String channel) { return kFlutterChannels.contains(channel); } -// Checks if its flutter project -bool isFlutterProject() { - return kLocalProjectPubspec.existsSync(); +/// Returns true it's a valid installed version +bool isFlutterVersionInstalled(String version) { + return (flutterListInstalledSdks()).contains(version); } -/// Returns true it's a valid installed version -Future isSdkInstalled(String version) async { - return (await flutterListInstalledSdks()).contains(version); +/// Checks if version is installed, and installs or exits +Future checkAndInstallVersion(String version) async { + if (isFlutterVersionInstalled(version)) return null; + Print.info('Flutter $version is not installed.'); + + // Install if input is confirmed + if (await confirm('Would you like to install it?')) { + final installProgress = logger.progress('Installing $version'); + await installFlutterVersion(version); + finishProgress(installProgress); + } else { + // If do not install exist + exit(0); + } } /// Moves assets from theme directory into brand-app @@ -50,7 +66,7 @@ void createLink( } /// Check if it is the current version. -Future isCurrentVersion(String version) async { +bool isCurrentVersion(String version) { final config = readProjectConfig(); return version == config.flutterSdkVersion; } diff --git a/lib/utils/print.dart b/lib/utils/print.dart new file mode 100644 index 00000000..9127d09a --- /dev/null +++ b/lib/utils/print.dart @@ -0,0 +1,20 @@ +import 'package:io/ansi.dart'; + +class Print { + /// Prints sucess message + static void success(String message) { + print(green.wrap(message)); + } + + static void warning(String message) { + print(yellow.wrap(message)); + } + + static void info(String message) { + print(cyan.wrap(message)); + } + + static void error(String message) { + print(red.wrap(message)); + } +} diff --git a/lib/utils/project_config.dart b/lib/utils/project_config.dart index c8c22e0e..380193ad 100644 --- a/lib/utils/project_config.dart +++ b/lib/utils/project_config.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:fvm/constants.dart'; import 'package:fvm/utils/helpers.dart'; +import 'package:fvm/utils/print.dart'; class ProjectConfig { final String flutterSdkVersion; @@ -13,12 +14,13 @@ class ProjectConfig { Map toJson() => {'flutterSdkVersion': flutterSdkVersion}; } -void updateProjectConfig(String version) { +void setAsProjectVersion(String version) { if (kProjectFvmConfigJson.existsSync() == false) { kProjectFvmConfigJson.createSync(recursive: true); } saveProjectConfig(ProjectConfig(version)); updateFlutterSdkBinLink(); + Print.success('Project now uses Flutter: $version'); } void updateFlutterSdkBinLink() { diff --git a/test/fvm_test.dart b/test/fvm_test.dart index d2cfb8eb..3ff876b0 100644 --- a/test/fvm_test.dart +++ b/test/fvm_test.dart @@ -32,8 +32,8 @@ void main() { try { await fvmRunner(['install', channel, '--verbose']); final existingChannel = await flutterSdkVersion(channel); - final correct = await checkInstalledCorrectly(channel); - final installedVersions = await flutterListInstalledSdks(); + final correct = isInstalledCorrectly(channel); + final installedVersions = flutterListInstalledSdks(); final installExists = installedVersions.contains(channel); @@ -58,12 +58,11 @@ void main() { test('Use Channel', () async { try { await fvmRunner(['use', channel, '--verbose']); - final linkExists = await kProjectFvmSdkSymlink.exists(); + final linkExists = kProjectFvmSdkSymlink.existsSync(); - final targetBin = await kProjectFvmSdkSymlink.target(); + final targetBin = kProjectFvmSdkSymlink.targetSync(); - final channelBin = - path.join(kVersionsDir.path, channel, 'bin', 'flutter'); + final channelBin = path.join(kVersionsDir.path, channel); expect(targetBin == channelBin, true); expect(linkExists, true); @@ -75,9 +74,9 @@ void main() { test('Use Flutter SDK globally', () async { try { await fvmRunner(['use', channel, '--global']); - final linkExists = await kDefaultFlutterLink.exists(); + final linkExists = kDefaultFlutterLink.existsSync(); - final targetDir = await kDefaultFlutterLink.target(); + final targetDir = kDefaultFlutterLink.targetSync(); final channelDir = path.join(kVersionsDir.path, channel); @@ -103,8 +102,8 @@ void main() { try { await fvmRunner(['install', release, '--verbose']); final existingRelease = await flutterSdkVersion(release); - final correct = await checkInstalledCorrectly(release); - final installedVersions = await flutterListInstalledSdks(); + final correct = isInstalledCorrectly(release); + final installedVersions = flutterListInstalledSdks(); final installExists = installedVersions.contains(release); @@ -121,12 +120,11 @@ void main() { test('Use Release', () async { try { await fvmRunner(['use', release, '--verbose']); - final linkExists = await kProjectFvmSdkSymlink.exists(); + final linkExists = kProjectFvmSdkSymlink.existsSync(); - final targetBin = await kProjectFvmSdkSymlink.target(); + final targetBin = kProjectFvmSdkSymlink.targetSync(); - final releaseBin = - path.join(kVersionsDir.path, release, 'bin', 'flutter'); + final releaseBin = path.join(kVersionsDir.path, release); expect(targetBin == releaseBin, true); expect(linkExists, true); diff --git a/test/utils/flutter_tools_test.dart b/test/utils/flutter_tools_test.dart index edda14c9..aa370c8f 100644 --- a/test/utils/flutter_tools_test.dart +++ b/test/utils/flutter_tools_test.dart @@ -13,9 +13,9 @@ void main() { try { await flutterChannelClone(invalidChannel); - fail("Exception not thrown"); + fail('Exception not thrown'); } on Exception catch (e) { - expect(e, TypeMatcher()); + expect(e, const TypeMatcher()); } }); @@ -24,16 +24,16 @@ void main() { try { await flutterVersionClone(invalidVersion); - fail("Exception not thrown"); + fail('Exception not thrown'); } on Exception catch (e) { - expect(e, TypeMatcher()); + expect(e, const TypeMatcher()); } }); test('Checks that install is not correct', () async { final invalidVersionName = 'INVALID_VERSION'; final dir = Directory(path.join(kVersionsDir.path, invalidVersionName)); await dir.create(recursive: true); - final correct = await checkInstalledCorrectly(invalidVersionName); + final correct = isInstalledCorrectly(invalidVersionName); expect(correct, false); }); }); From 605f3b6672f0fad9ea40aed0766daf9b30b61380 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 18 Jun 2020 16:36:15 -0400 Subject: [PATCH 09/11] Implemented global functionality --- lib/commands/use.dart | 63 +++++++++++++++++------------------- lib/utils/flutter_tools.dart | 8 +++-- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/commands/use.dart b/lib/commands/use.dart index 17f4d87a..f67cdeb3 100644 --- a/lib/commands/use.dart +++ b/lib/commands/use.dart @@ -1,12 +1,9 @@ -import 'dart:io'; - import 'package:args/command_runner.dart'; -import 'package:console/console.dart'; +import 'package:fvm/constants.dart'; +import 'package:fvm/utils/flutter_tools.dart'; +import 'package:fvm/utils/guards.dart'; import 'package:fvm/utils/helpers.dart'; -import 'package:fvm/utils/logger.dart'; import 'package:fvm/utils/project_config.dart'; -import 'package:fvm/utils/version_installer.dart'; -import 'package:io/ansi.dart'; /// Use an installed SDK version class UseCommand extends Command { @@ -19,40 +16,38 @@ class UseCommand extends Command { final description = 'Which Flutter SDK Version you would like to use'; /// Constructor - UseCommand(); + UseCommand() { + argParser + ..addFlag( + 'global', + help: + 'Sets version as the global version.\nMake sure Flutter PATH env is set to: $kDefaultFlutterPath', + negatable: false, + ); + } @override Future run() async { - // Check if it's Flutter project - if (!isFlutterProject()) { - throw Exception('Run `use` command on the root of a Flutter project'); - } + final useGlobally = argResults['global'] == true; + final version = argResults.rest[0]; if (argResults.rest.isEmpty) { - final instruction = yellow.wrap('fvm use '); - throw Exception('Please provide a version. $instruction'); + throw Exception('Please provide a version. fvm use '); } - final version = argResults.rest[0]; - - final isInstalled = await isSdkInstalled(version); - - if (!isInstalled) { - print('Flutter $version is not installed.'); - var inputConfirm = await readInput('Would you like to install it? Y/n: '); - - // Install if input is confirmed - if (!inputConfirm.contains('n')) { - final installProgress = logger.progress('Installing $version'); - await installFlutterVersion(version); - finishProgress(installProgress); - } else { - // If do not install exist - exit(0); - } + // Make sure is valid Flutter version + await Guards.isFlutterVersion(version); + // If project use check that is Flutter project + if (!useGlobally) Guards.isFlutterProject(); + + // Make sure version is installed + await checkAndInstallVersion(version); + + if (useGlobally) { + // Sets version as the global + setAsGlobalVersion(version); + } else { + // Updates the project config with version + setAsProjectVersion(version); } - - updateProjectConfig(version); - - print(green.wrap('$version is active')); } } diff --git a/lib/utils/flutter_tools.dart b/lib/utils/flutter_tools.dart index 7c375741..6cb31438 100644 --- a/lib/utils/flutter_tools.dart +++ b/lib/utils/flutter_tools.dart @@ -160,7 +160,11 @@ List flutterListInstalledSdks() { } } -Future linkProjectFlutterDirGlobally(String version) async { +void setAsGlobalVersion(String version) { final versionDir = Directory(path.join(kVersionsDir.path, version)); - await createLink(kDefaultFlutterLink, versionDir); + createLink(kDefaultFlutterLink, versionDir); + + Print.success('The global Flutter version is now $version'); + Print.success( + 'Make sure sure to add $kDefaultFlutterPath to your PATH environment variable'); } From 27667dd28692e36ffaa22bb000d39faeecc3e242 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 18 Jun 2020 18:26:02 -0400 Subject: [PATCH 10/11] Docs and updated coverage --- README.md | 28 +++++++++++++++++----------- coverage_badge.svg | 6 +++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 38cdf1c5..a839d574 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ You can use different Flutter SDK versions per project. To do that you have to g > fvm use ``` -If you want to use a specific version by default in your machine, you can specify the flag `--global` to the `use` command. A symbolic link to the Flutter version will be created in the `fvm` home folder, which you could then add to your PATH environment variable as follows: `/default/bin` +If you want to use a specific version by default in your machine, you can specify the flag `--global` to the `use` command. A symbolic link to the Flutter version will be created in the `fvm` home folder, which you could then add to your PATH environment variable as follows: `FVM_HOME/default/bin`. Use `fvm use --help`, thsi will give you the exact path you need to configure. ### Remove a SDK Version @@ -116,24 +116,30 @@ As an example calling `fvm flutter run` is the equivalent of calling `flutter ru ### Configure Your IDE +In some situations you might have to restart your IDE and the Flutter debugger to make sure it uses the new version. + #### VSCode -Add the following to your settings.json. This will list list all Flutter SDKs installed when using VSCode when using `Flutter: Change SDK` +Add the following to your settings.json. This will list list all Flutter SDKs installed when using VSCode when using `Flutter: Change SDK`. -```json +Use `fvm list` to show you the path to the versions. -"dart.flutterSdkPaths": [ - "/Users/leofarias/fvm/versions" -] +```json +{ + "dart.flutterSdkPaths": [ + // List all versions installd by FVM + "/Users/usr/fvm/versions" + // Or add the version symlink for dynamic switch + ".fvm/flutter_sdk" + ] +} ``` #### Android Studio -copy the path of fvm symbolic link in your root project directory. -example {fvm-path}/versions/beta/bin/flutter -in the Android Studio menĂ¹ open Languages & Frameworks -> Flutter or search for Flutter and change Flutter SDK path to the previous path -Apply the changes -You now can Run and Debug with the selected versions of Flutter. +Copy the **_absolute_** path of fvm symbolic link in your root project directory. Example: `/absolute/path-to-your-project/.fvm/flutter_sdk` + +In the Android Studio menu open `Languages & Frameworks -> Flutter` or search for Flutter and change Flutter SDK path. Apply the changes. You now can Run and Debug with the selected versions of Flutter. [Add your IDE instructions here](https://github.com/leoafarias/fvm/issues) diff --git a/coverage_badge.svg b/coverage_badge.svg index 473230f4..a6f4e712 100644 --- a/coverage_badge.svg +++ b/coverage_badge.svg @@ -8,13 +8,13 @@ - + coverage coverage - 73% - 73% + 75% + 75% From ac11f6a433ad6a25063d1b8c1e291ce0625ddf25 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 18 Jun 2020 18:34:10 -0400 Subject: [PATCH 11/11] Changelog and version bump --- CHANGELOG.md | 8 ++++++++ pubspec.yaml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 658b424e..853cf56b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.8.0 + +- Implemented `--global` flag to set a specific version globally. +- Changed project configuration to allow for versioning. +- Refactoring and project clean-up +- Better user experience +- Improved error messages + ## 0.7.2 - Better compatibility with flutter commands. diff --git a/pubspec.yaml b/pubspec.yaml index 7d93f850..f0c76365 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ 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: 0.7.2 +version: 0.8.0 homepage: https://github.com/leoafarias/fvm environment: