-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathcompile.dart
60 lines (46 loc) · 1.72 KB
/
compile.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'dart:io';
Future<void> 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/main.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');
}
}