Skip to content

Commit

Permalink
improved terminal output (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark O'Sullivan <[email protected]>
  • Loading branch information
MarkOSullivan94 and Mark O'Sullivan authored Aug 23, 2020
1 parent 5300dbf commit 29def4c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter_launcher_icons/constants.dart';
import 'package:flutter_launcher_icons/main.dart' as flutter_launcher_icons;

void main(List<String> arguments) {
print(introMessage('0.8.0'));
flutter_launcher_icons.createIconsFromArguments(arguments);
}
15 changes: 7 additions & 8 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ List<AndroidIconTemplate> androidIcons = <AndroidIconTemplate>[

void createDefaultIcons(
Map<String, dynamic> flutterLauncherIconsConfig, String flavor) {
print('Creating default icons Android');
printStatus('Creating default icons Android');
final String filePath = getAndroidIconPath(flutterLauncherIconsConfig);
final Image image = decodeImage(File(filePath).readAsBytesSync());
final File androidManifestFile = File(constants.androidManifestFile);
if (isCustomAndroidFile(flutterLauncherIconsConfig)) {
print('Adding a new Android launcher icon');
printStatus('Adding a new Android launcher icon');
final String iconName = getNewIconName(flutterLauncherIconsConfig);
isAndroidIconNameCorrectFormat(iconName);
final String iconPath = '$iconName.png';
Expand All @@ -44,7 +44,7 @@ void createDefaultIcons(
}
overwriteAndroidManifestWithNewLauncherIcon(iconName, androidManifestFile);
} else {
print('Overwriting the default Android launcher icon with a new icon');
printStatus('Overwriting the default Android launcher icon with a new icon');
for (AndroidIconTemplate template in androidIcons) {
overwriteExistingIcons(
template, image, constants.androidFileName, flavor);
Expand All @@ -65,7 +65,7 @@ bool isAndroidIconNameCorrectFormat(String iconName) {

void createAdaptiveIcons(
Map<String, dynamic> flutterLauncherIconsConfig, String flavor) {
print('Creating adaptive icons Android');
printStatus('Creating adaptive icons Android');

// Retrieve the necessary Flutter Launcher Icons configuration from the pubspec.yaml file
final String backgroundConfig =
Expand Down Expand Up @@ -101,11 +101,11 @@ void createAdaptiveIcons(
void updateColorsXmlFile(String backgroundConfig, String flavor) {
final File colorsXml = File(constants.androidColorsFile(flavor));
if (colorsXml.existsSync()) {
print('Updating colors.xml with color for adaptive icon background');
printStatus('Updating colors.xml with color for adaptive icon background');
updateColorsFile(colorsXml, backgroundConfig);
} else {
print('No colors.xml file found in your Android project');
print('Creating colors.xml file and adding it to your Android project');
printStatus('No colors.xml file found in your Android project');
printStatus('Creating colors.xml file and adding it to your Android project');
createNewColorsFile(backgroundConfig, flavor);
}
}
Expand Down Expand Up @@ -291,7 +291,6 @@ int minSdk() {
if (line.contains('minSdkVersion')) {
// remove anything from the line that is not a digit
final String minSdk = line.replaceAll(RegExp(r'[^\d]'), '');
print('Android minSdkVersion = $minSdk');
return int.parse(minSdk);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ const String errorMissingRegularAndroid =
const String errorIncorrectIconName =
'The icon name must contain only lowercase a-z, 0-9, or underscore: '
'E.g. "ic_my_new_icon"';

String introMessage(String currentVersion) => '''
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v$currentVersion)
════════════════════════════════════════════
''';
14 changes: 5 additions & 9 deletions lib/custom_exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter_launcher_icons/utils.dart';

class InvalidAndroidIconNameException implements Exception {
const InvalidAndroidIconNameException([this.message]);
final String message;

@override
String toString() {
return '*** ERROR ***\n'
'InvalidAndroidIconNameException\n'
'$message';
return generateError(this, message);
}
}

Expand All @@ -16,9 +16,7 @@ class InvalidConfigException implements Exception {

@override
String toString() {
return '*** ERROR ***\n'
'InvalidConfigException\n'
'$message';
return generateError(this, message);
}
}

Expand All @@ -28,8 +26,6 @@ class NoConfigFoundException implements Exception {

@override
String toString() {
return '*** ERROR ***\n'
'NoConfigFoundException\n'
'$message';
return generateError(this, message);
}
}
6 changes: 3 additions & 3 deletions lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void createIcons(Map<String, dynamic> config, String flavor) {
final dynamic iosConfig = config['ios'];
if (flavor != null) {
final String catalogName = 'AppIcon-$flavor';
print('Building iOS launcher icon for $flavor');
printStatus('Building iOS launcher icon for $flavor');
for (IosIconTemplate template in iosIcons) {
saveNewIcons(template, image, catalogName);
}
Expand All @@ -48,7 +48,7 @@ void createIcons(Map<String, dynamic> config, String flavor) {
// If the IOS configuration is a string then the user has specified a new icon to be created
// and for the old icon file to be kept
final String newIconName = iosConfig;
print('Adding new iOS launcher icon');
printStatus('Adding new iOS launcher icon');
for (IosIconTemplate template in iosIcons) {
saveNewIcons(template, image, newIconName);
}
Expand All @@ -59,7 +59,7 @@ void createIcons(Map<String, dynamic> config, String flavor) {
// Otherwise the user wants the new icon to use the default icons name and
// update config file to use it
else {
print('Overwriting default iOS launcher icon with new icon');
printStatus('Overwriting default iOS launcher icon with new icon');
for (IosIconTemplate template in iosIcons) {
overwriteDefaultIcons(template, image);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:math';

import 'package:args/args.dart';
import 'package:flutter_launcher_icons/utils.dart';
import 'package:yaml/yaml.dart';
import 'package:flutter_launcher_icons/android.dart' as android_launcher_icons;
import 'package:flutter_launcher_icons/ios.dart' as ios_launcher_icons;
Expand Down Expand Up @@ -56,16 +57,21 @@ Future<void> createIconsFromArguments(List<String> arguments) async {
} catch (e) {
stderr.writeln(e);
exit(2);
} finally {
print('\n✓ Successfully generated launcher icons');
}
} else {
try {
for (var flavor in flavors) {
for (String flavor in flavors) {
print('\nFlavor: $flavor');
final Map<String, dynamic> yamlConfig = loadConfigFile(flavorConfigFile(flavor), flavorConfigFile(flavor));
await createIconsFromConfig(yamlConfig, flavor);
}
} catch (e) {
stderr.writeln(e);
exit(2);
} finally {
print('\n✓ Successfully generated launcher icons for flavors');
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ Image createResizedImage(int iconSize, Image image) {
);
}
}

void printStatus(String message) {
print('• $message');
}

String generateError(Exception e, String error) {
return '\n✗ ERROR: ${(e).runtimeType.toString()} \n$error';
}

0 comments on commit 29def4c

Please sign in to comment.