Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit 6d7506d

Browse files
committed
linux support, reformat code, and many more
1 parent e734710 commit 6d7506d

12 files changed

Lines changed: 930 additions & 742 deletions

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Flutter Installer
22

3-
[![GitHub issues](https://img.shields.io/github/issues/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/issues) [![GitHub forks](https://img.shields.io/github/forks/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/network) [![GitHub stars](https://img.shields.io/github/stars/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/stargazers) [![GitHub license](https://img.shields.io/github/license/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/blob/master/LICENSE)
3+
[![GitHub issues](https://img.shields.io/github/issues/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/issues)
4+
[![GitHub forks](https://img.shields.io/github/forks/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/network)
5+
[![GitHub stars](https://img.shields.io/github/stars/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/stargazers)
6+
[![GitHub license](https://img.shields.io/github/license/daffaalam/flutter_installer_cli)](https://github.com/daffaalam/flutter_installer_cli/blob/master/LICENSE)
47

5-
Installer for Flutter SDK, including Android SDK and Java SDK if not installed (automatic detection). Currently only for Windows. MacOS and Linux are under development.
8+
Installation toolkit for Flutter SDK, including Android SDK and Java SDK if not installed (automatic detection). Currently only for Windows and Linux. MacOS are under development.
69

710
## How to run
811

9-
Please remember the [system requirements](https://flutter.dev/docs/get-started/install/windows#system-requirements) needed before running this application.
12+
Please remember the system requirements ([windows](https://flutter.dev/docs/get-started/install/windows#system-requirements)/[linux](https://flutter.dev/docs/get-started/install/linux#system-requirements)) needed before running this application.
1013

11-
Download **[here](https://github.com/daffaalam/flutter_installer_cli/releases/latest)** and run right away.
14+
**Download [here](https://github.com/daffaalam/flutter_installer_cli/releases/latest), extract and run right away.**
1215

1316
By default it will take the latest flutter version from the stable channel. If you want to use another version, use the `channel` and `version` flags. Use the version name from https://flutter.dev/docs/development/tools/sdk/releases.
1417

@@ -33,6 +36,7 @@ If the version and channel do not find a match, it will retrieve the latest this
3336

3437
## Features
3538

39+
- [x] Windows and Linux support.
3640
- [x] Detects whether Android Studio and or Visual Studio Code is already installed.
3741
- [x] Detects whether Android SDK, Java SDK and Flutter SDK are installed.
3842
- [x] Check the latest versions of Android SDK, Java SDK, and Flutter SDK.
@@ -43,20 +47,20 @@ If the version and channel do not find a match, it will retrieve the latest this
4347
## TODO
4448

4549
- [ ] low - Language improvement (I'm very bad at English).
46-
- [ ] high - Implementation to Linux and MacOS.
50+
- [ ] high - Implementation to MacOS.
4751
- [ ] low - Pretty and simple code.
4852
- [ ] high - Implementation to the GUI (flutter) version.
4953
- [ ] high - Can choose a custom installation path.
5054

5155
## Running the tests
5256

53-
1. Create a new virtual machine (Windows 7, 8, 10) with VirtualBox or everything.
54-
2. Run it from Command Prompt or PowerShell, don't run it from double click, so you can see the crash message before the program exits.
57+
1. Create a new virtual machine (Linux or Windows) with VirtualBox or everything.
58+
2. Run it from Command Prompt, PowerShell, or Terminal, don't run it from double click, so you can see the crash message before the program exits.
5559

5660
## Deployment
5761

5862
1. Clone or download this [repository](https://github.com/daffaalam/flutter_installer_cli).
59-
2. Install `Dart` from https://dart.dev/get-dart or https://gekorm.com/dart-windows/.
63+
2. Install `Dart` from https://dart.dev/get-dart.
6064
3. Run on project: `dart2native bin/flutter_installer_cli.dart`.
6165

6266
## Other
@@ -69,4 +73,4 @@ When contributing to this repository, please first discuss the change you wish t
6973

7074
## License
7175

72-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
76+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

bin/flutter_installer_cli.dart

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,54 @@
11
import 'dart:io';
22

33
import 'package:process_run/process_run.dart';
4-
import 'package:process_run/shell.dart';
54
import 'package:process_run/which.dart';
65

7-
import 'tools/function.dart';
6+
import 'src/install/install.dart';
7+
import 'src/tool.dart';
88

99
void main(List<String> args) async {
1010
try {
11-
environment.addAll(Platform.environment);
12-
1311
parseArgs(args);
1412

15-
await run('chcp 437 > nul', []);
13+
showText(' START ');
1614

17-
var powerShell = await checkPowerShell();
18-
if (!powerShell && Platform.isWindows) {
19-
stdout.writeln(
20-
'Can not find PowerShell 5.0 or newer. Please install first to continue.\n'
21-
'https://www.microsoft.com/en-us/download/confirmation.aspx?id=54616',
22-
);
23-
stdin.readLineSync();
24-
exit(0);
25-
}
15+
await logNewRun();
2616

27-
showText(' START ');
17+
if (Platform.isWindows) {
18+
await run('chcp 437 > nul', []);
19+
var powerShell = await checkPowerShell();
20+
if (!powerShell) {
21+
stdout.writeln(
22+
'Can not find PowerShell 5.0 or newer. Please install first to continue.\n'
23+
'https://www.microsoft.com/en-us/download/confirmation.aspx?id=54616',
24+
);
25+
stdin.readLineSync();
26+
exit(0);
27+
}
28+
}
2829

2930
await checkLatestVersion();
3031

31-
var operatingSystem = Platform.operatingSystem;
3232
var flutterPath = await which('flutter');
33-
var dartPath = await which('dart');
34-
var javaPath = await which('java');
35-
var androidPath = await which('sdkmanager');
36-
var vscodePath = await which('code');
37-
var gitPath = await which('git');
38-
3933
if (flutterPath == null) {
40-
var winDisk = Platform.isWindows ? userHomePath.split('\\')[0] : '';
41-
installationPath = Platform.isWindows ? '$winDisk\\' : '~/';
42-
installationPath += 'Development';
43-
stdout.writeln('\nFlutter will be installed in $installationPath\n');
44-
var exists = await Directory(installationPath).exists();
45-
if (!exists) await Directory(installationPath).create(recursive: true);
46-
var studio = await checkAndroidStudio();
47-
var later = false;
48-
if (studio == null) {
49-
later = await promptConfirm(
50-
'Android Studio is not installed. Do you want to install the full package (Flutter without Android Studio)?',
51-
);
52-
stdout.write('\n');
53-
}
54-
if (later) {
55-
stdout.writeln(
56-
'This process might require downloading ~1.5 GB for the first time\n',
57-
);
58-
await withOutAndroidStudio(
59-
javaPath: javaPath,
60-
androidPath: androidPath,
61-
operatingSystem: operatingSystem,
62-
);
63-
} else {
64-
stdout.writeln(
65-
'This process might require downloading ~900 MB for the first time\n',
66-
);
67-
}
68-
await installFlutter(
69-
operatingSystem: operatingSystem,
70-
);
71-
if (studio != null) {
72-
await androidStudioInstallExtensions(
73-
studio: studio,
74-
);
75-
}
76-
if (vscodePath != null) {
77-
await vscodeInstallExtensions();
78-
}
79-
if (gitPath == null) {
80-
await stdout.writeln(
81-
'[GIT] (Optional) You might need git for versioning, install from https://git-scm.com/downloads.',
82-
);
83-
}
84-
stdout.write(
85-
'\nPlease exit this window and open new Terminal or Command Prompt and run `flutter doctor -v`.\n',
86-
);
34+
await installFullPackage();
8735
} else {
36+
var dartPath = await which('dart');
8837
if (dartPath == null) {
8938
var path = Directory(flutterPath).parent.path;
9039
await setPathEnvironment(
9140
title: 'DART',
92-
newPath: '$path\\cache\\dart-sdk\\bin',
41+
newPath: '$path/cache/dart-sdk/bin',
9342
);
9443
}
95-
await run(
96-
'flutter',
97-
['upgrade'],
98-
verbose: true,
99-
);
44+
await run('flutter', ['upgrade'], verbose: true);
10045
}
10146
showText(' FINISH ');
10247
stdin.readLineSync();
10348
exit(0);
10449
} catch (e, s) {
10550
await errorLog(e, s);
51+
stdin.readLineSync();
52+
exit(2);
10653
}
10754
}

bin/model/android_studio.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'package:meta/meta.dart';
33
class AndroidStudio {
44
String home;
55
String config;
6+
String build;
67

78
AndroidStudio({
89
@required this.home,
910
@required this.config,
11+
@required this.build,
1012
});
1113
}

bin/src/config.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:pub_semver/pub_semver.dart';
2+
import 'package:sentry/sentry.dart';
3+
4+
Version version = Version.parse('0.3.0');
5+
bool verboseShow = false;
6+
bool isDebug = false;
7+
String installationPath = '';
8+
String flutterChannel = '';
9+
String flutterVersion = '';
10+
Map<String, String> environment = <String, String>{};
11+
String githubRepos = 'https://github.com/daffaalam/flutter_installer_cli';
12+
SentryClient sentryClient = SentryClient(
13+
dsn: '' // TODO : remove value before upload to public
14+
'',
15+
);

bin/src/install/install.dart

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import 'dart:io';
2+
3+
import 'package:meta/meta.dart';
4+
import 'package:process_run/shell.dart';
5+
import 'package:process_run/which.dart';
6+
7+
import '../config.dart';
8+
import '../tool.dart';
9+
import 'install_android.dart';
10+
import 'install_flutter.dart';
11+
import 'install_ide.dart';
12+
import 'install_java.dart';
13+
14+
Future<void> installFullPackage() async {
15+
if (Platform.isWindows) {
16+
installationPath = userHomePath.split('\\')[0];
17+
} else {
18+
installationPath = userHomePath;
19+
}
20+
installationPath += '/Development';
21+
installationPath = fixPathPlatform(installationPath);
22+
stdout.writeln('\nFlutter will be installed in $installationPath\n');
23+
var exists = await Directory(installationPath).exists();
24+
if (!exists) await Directory(installationPath).create(recursive: true);
25+
var fullPackage = true;
26+
var studio = await checkAndroidStudio();
27+
if (studio == null) {
28+
fullPackage = await promptConfirm(
29+
'Android Studio is not installed. Do you want to install the full package (Flutter without Android Studio)?',
30+
);
31+
}
32+
if (fullPackage) {
33+
stdout.writeln(
34+
'\nThis process might require downloading ~1.7 GB for the first time.\n',
35+
);
36+
var javaPath = await which('java');
37+
var androidPath = await which('sdkmanager');
38+
if (androidPath != null) {
39+
var allowTools = await checkAndroidTools(
40+
toolsPath: Directory(androidPath).parent.path,
41+
);
42+
if (!allowTools) {
43+
stdout.writeln(
44+
'[ANDROID] Please install Android Tools 26.1.1 or earlier.',
45+
);
46+
}
47+
}
48+
await installWithOutAndroidStudio(
49+
javaPath: javaPath,
50+
androidPath: androidPath,
51+
);
52+
} else {
53+
stdout.writeln(
54+
'\nThis process might require downloading ~1 GB for the first time.\n',
55+
);
56+
}
57+
await installFlutter();
58+
if (studio != null) {
59+
await androidStudioInstallExtensions(
60+
studio: studio,
61+
);
62+
}
63+
var vscodePath = await which('code');
64+
if (vscodePath != null) {
65+
await vscodeInstallExtensions();
66+
}
67+
var gitPath = await which('git');
68+
if (gitPath == null) {
69+
await stdout.writeln(
70+
'[GIT]${!Platform.isWindows ? ' (REQUIRED) ' : ' '}You might need git for versioning, install from https://git-scm.com/downloads.',
71+
);
72+
}
73+
stdout.write(
74+
'\nPlease exit this window and open new Terminal or Command Prompt and run `flutter doctor -v`.\n',
75+
);
76+
}
77+
78+
Future<void> installWithOutAndroidStudio({
79+
@required String javaPath,
80+
@required String androidPath,
81+
}) async {
82+
if (javaPath == null) {
83+
await installJava();
84+
} else {
85+
var javaVersion = await checkJavaVersion();
86+
if (javaVersion != 8) {
87+
stdout.writeln(
88+
'[JAVA] Java $javaVersion already installed, but this version is not recommended, '
89+
'please use version 8 or uninstall this java and use the default from Android Studio.',
90+
);
91+
}
92+
}
93+
if (androidPath == null) {
94+
await installAndroid();
95+
} else {
96+
await updateAndroid(
97+
toolsPath: Directory(androidPath).parent.path,
98+
);
99+
}
100+
}

0 commit comments

Comments
 (0)