diff --git a/bin/main.dart b/bin/main.dart index 9fac323fb7..8c79e97abb 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -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 arguments) { + print(introMessage('0.8.0')); flutter_launcher_icons.createIconsFromArguments(arguments); } diff --git a/lib/android.dart b/lib/android.dart index 5280dfcce2..21ce21916c 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -30,12 +30,12 @@ List androidIcons = [ void createDefaultIcons( Map 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'; @@ -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); @@ -65,7 +65,7 @@ bool isAndroidIconNameCorrectFormat(String iconName) { void createAdaptiveIcons( Map 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 = @@ -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); } } @@ -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); } } diff --git a/lib/constants.dart b/lib/constants.dart index ffaf02fd2a..cdda3b8423 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -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) + ════════════════════════════════════════════ + '''; \ No newline at end of file diff --git a/lib/custom_exceptions.dart b/lib/custom_exceptions.dart index 17e05974f3..0a77f34888 100644 --- a/lib/custom_exceptions.dart +++ b/lib/custom_exceptions.dart @@ -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); } } @@ -16,9 +16,7 @@ class InvalidConfigException implements Exception { @override String toString() { - return '*** ERROR ***\n' - 'InvalidConfigException\n' - '$message'; + return generateError(this, message); } } @@ -28,8 +26,6 @@ class NoConfigFoundException implements Exception { @override String toString() { - return '*** ERROR ***\n' - 'NoConfigFoundException\n' - '$message'; + return generateError(this, message); } } diff --git a/lib/ios.dart b/lib/ios.dart index 7921434f91..2f86bf92a7 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -37,7 +37,7 @@ void createIcons(Map 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); } @@ -48,7 +48,7 @@ void createIcons(Map 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); } @@ -59,7 +59,7 @@ void createIcons(Map 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); } diff --git a/lib/main.dart b/lib/main.dart index 851fff08c4..e9371ff4f3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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; @@ -56,16 +57,21 @@ Future createIconsFromArguments(List 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 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'); } } } diff --git a/lib/utils.dart b/lib/utils.dart index c2b634d7d1..1bdf6af69b 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -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'; +} \ No newline at end of file