From 2344bae85a990a1cdc04a6d35e6e0087be792812 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Wed, 20 Sep 2023 18:58:10 -0400 Subject: [PATCH] wip --- .github/actions/prepare/action.yml | 2 +- .github/actions/test/action.yml | 2 +- bin/compile.dart | 58 ++++++++++++++++++++++++++++++ bin/flutter_select.dart | 20 ----------- pubspec.yaml | 2 +- 5 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 bin/compile.dart delete mode 100644 bin/flutter_select.dart diff --git a/.github/actions/prepare/action.yml b/.github/actions/prepare/action.yml index 437bf0ca..31592fc0 100644 --- a/.github/actions/prepare/action.yml +++ b/.github/actions/prepare/action.yml @@ -32,7 +32,7 @@ runs: shell: bash - name: Build version - run: dart pub global run grinder:grind build-version + run: dart pub global run grinder:grinder build-version shell: bash - name: Analyze diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 2bf04466..bbf53296 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -9,5 +9,5 @@ runs: shell: bash - name: Run tests - run: dart pub global run grinder:grind test + run: dart pub global run grinder:grinder test shell: bash \ No newline at end of file diff --git a/bin/compile.dart b/bin/compile.dart new file mode 100644 index 00000000..23d555ac --- /dev/null +++ b/bin/compile.dart @@ -0,0 +1,58 @@ +import 'dart:io'; + +Future main() async { + const package = 'fvm'; // Your package name + const destination = + '/usr/local/bin'; // system location for user installed binaries + + // Identify the operating system + var os = Platform.operatingSystem; + + if (os != 'macos' && os != 'linux') { + print('Unsupported OS. Only MacOS and Linux are supported.'); + return; + } + + // Get temporary directory + var tempDir = await Directory.systemTemp.createTemp('fvm-compile'); + + var tempFile = File('${tempDir.path}/$package-$os'); + + // Compile the package to native executable + print('Compiling package...'); + final compileResult = await Process.run( + 'dart', + ['compile', 'exe', 'bin/fvm.dart', '-o', tempFile.path], + ); + + // Error checking for compile process + if (compileResult.exitCode != 0) { + print('Error occurred in compilation:\n ${compileResult.stderr}'); + return; + } + + print('Compilation successful.'); + print('Moving compiled package to destination...'); + + // Move the compiled executable to desired directory + + // Make sure your Dart application has the necessary permissions for this operation + if (await tempFile.exists()) { + await tempFile.rename('$destination/$package'); + print('Executable moved successfully'); + } else { + print('Failed moving the binary. File does not exist.'); + } + + // Clean up the temp directory + await tempDir.delete(); + + // Deactivate current globally activated version of FVM + final deactivateResult = + await Process.run('dart', ['pub', 'global', 'deactivate', 'fvm']); + if (deactivateResult.exitCode == 0) { + print('Deactivated current global version of FVM successfully'); + } else { + print('Error during the deactivation of the global FVM version'); + } +} diff --git a/bin/flutter_select.dart b/bin/flutter_select.dart deleted file mode 100644 index 0597a8d2..00000000 --- a/bin/flutter_select.dart +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env dart - -import 'dart:io'; - -import 'package:fvm/src/runner.dart'; - -Future main(List args) async { - await _flushThenExit(await FvmCommandRunner().run(args)); -} - -/// Flushes the stdout and stderr streams, then exits the program with the given -/// status code. -/// -/// This returns a Future that will never complete, since the program will have -/// exited already. This is useful to prevent Future chains from proceeding -/// after you've decided to exit. -Future _flushThenExit(int status) { - return Future.wait([stdout.close(), stderr.close()]) - .then((_) => exit(status)); -} diff --git a/pubspec.yaml b/pubspec.yaml index 92eecbd6..cf0d9265 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: executables: fvm: fvm - flutter-select: flutter_select + fvm-compile: compile dependencies: args: ^2.4.2