diff --git a/CHANGELOG.md b/CHANGELOG.md index 436698f8ff..a5e9d356ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.13.1 (15th April 2023) + +- Can now use `flutter_launcher_icons` instead of `flutter_icons` [#478](https://github.com/fluttercommunity/flutter_launcher_icons/pull/478) + + ## 0.13.0 (7th April 2023) - Fix remove alpha for iOS [#464](https://github.com/fluttercommunity/flutter_launcher_icons/pull/464) diff --git a/README.md b/README.md index 0521d9f95f..768bed85a8 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ An example is shown below. More complex examples [can be found in the example pr ```yaml dev_dependencies: - flutter_launcher_icons: "^0.13.0" + flutter_launcher_icons: "^0.13.1" -flutter_icons: +flutter_launcher_icons: android: "launcher_icon" ios: true image_path: "assets/icon/icon.png" diff --git a/example/default_example/.metadata b/example/default_example/.metadata index f1a97ba1df..87fe9740e7 100644 --- a/example/default_example/.metadata +++ b/example/default_example/.metadata @@ -1,10 +1,45 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: ce40de69b7b4f89c66d19c8dbd3bd86ae30f1bc6 - channel: dev + revision: f72efea43c3013323d1b95cff571f3c1caa37583 + channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: android + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: ios + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: linux + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: macos + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: web + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + - platform: windows + create_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + base_revision: f72efea43c3013323d1b95cff571f3c1caa37583 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/default_example/pubspec.yaml b/example/default_example/pubspec.yaml index acefef0da7..549e2d9df9 100644 --- a/example/default_example/pubspec.yaml +++ b/example/default_example/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: flutter_launcher_icons: path: ../.. -flutter_icons: +flutter_launcher_icons: # image_path: "assets/images/icon-128x128.png" image_path_android: "assets/images/icon-710x599-android.png" image_path_ios: "assets/images/icon-1024x1024.png" diff --git a/lib/abs/icon_generator.dart b/lib/abs/icon_generator.dart index 8d8288b384..96c8871395 100644 --- a/lib/abs/icon_generator.dart +++ b/lib/abs/icon_generator.dart @@ -1,6 +1,9 @@ import 'dart:io'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; +import 'package:flutter_launcher_icons/config/macos_config.dart'; +import 'package:flutter_launcher_icons/config/web_config.dart'; +import 'package:flutter_launcher_icons/config/windows_config.dart'; import 'package:flutter_launcher_icons/logger.dart'; /// A base class to generate icons @@ -34,7 +37,7 @@ abstract class IconGenerator { /// Provides easy access to user arguments and configuration class IconGeneratorContext { /// Contains configuration from configuration file - final FlutterLauncherIconsConfig config; + final Config config; /// A logger final FLILogger logger; @@ -65,7 +68,7 @@ class IconGeneratorContext { /// Generates Icon for given platforms void generateIconsFor({ - required FlutterLauncherIconsConfig config, + required Config config, required String? flavor, required String prefixPath, required FLILogger logger, diff --git a/lib/android.dart b/lib/android.dart index f055d6ca43..cd2d184e31 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -5,7 +5,7 @@ import 'dart:io'; import 'package:flutter_launcher_icons/constants.dart'; import 'package:flutter_launcher_icons/constants.dart' as constants; import 'package:flutter_launcher_icons/custom_exceptions.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/utils.dart' as utils; import 'package:flutter_launcher_icons/xml_templates.dart' as xml_template; import 'package:image/image.dart'; @@ -35,12 +35,12 @@ List androidIcons = [ ]; void createDefaultIcons( - FlutterLauncherIconsConfig flutterLauncherIconsConfig, + Config config, String? flavor, ) { utils.printStatus('Creating default icons Android'); // TODO(p-mazhnik): support prefixPath - final String? filePath = flutterLauncherIconsConfig.getImagePathAndroid(); + final String? filePath = config.getImagePathAndroid(); if (filePath == null) { throw const InvalidConfigException(errorMissingImagePath); } @@ -49,9 +49,9 @@ void createDefaultIcons( return; } final File androidManifestFile = File(constants.androidManifestFile); - if (flutterLauncherIconsConfig.isCustomAndroidFile) { + if (config.isCustomAndroidFile) { utils.printStatus('Adding a new Android launcher icon'); - final String iconName = flutterLauncherIconsConfig.android; + final String iconName = config.android; isAndroidIconNameCorrectFormat(iconName); final String iconPath = '$iconName.png'; for (AndroidIconTemplate template in androidIcons) { @@ -89,16 +89,16 @@ bool isAndroidIconNameCorrectFormat(String iconName) { } void createAdaptiveIcons( - FlutterLauncherIconsConfig flutterLauncherIconsConfig, + Config config, String? flavor, ) { utils.printStatus('Creating adaptive icons Android'); // Retrieve the necessary Flutter Launcher Icons configuration from the pubspec.yaml file final String? backgroundConfig = - flutterLauncherIconsConfig.adaptiveIconBackground; + config.adaptiveIconBackground; final String? foregroundImagePath = - flutterLauncherIconsConfig.adaptiveIconForeground; + config.adaptiveIconForeground; if (backgroundConfig == null || foregroundImagePath == null) { throw const InvalidConfigException(errorMissingImagePath); } @@ -120,12 +120,12 @@ void createAdaptiveIcons( // Create adaptive icon background if (isAdaptiveIconConfigPngFile(backgroundConfig)) { _createAdaptiveBackgrounds( - flutterLauncherIconsConfig, + config, backgroundConfig, flavor, ); } else { - createAdaptiveIconMipmapXmlFile(flutterLauncherIconsConfig, flavor); + createAdaptiveIconMipmapXmlFile(config, flavor); updateColorsXmlFile(backgroundConfig, flavor); } } @@ -156,13 +156,13 @@ void updateColorsXmlFile(String backgroundConfig, String? flavor) { /// Creates the xml file required for the adaptive launcher icon /// FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml void createAdaptiveIconMipmapXmlFile( - FlutterLauncherIconsConfig flutterLauncherIconsConfig, + Config config, String? flavor, ) { - if (flutterLauncherIconsConfig.isCustomAndroidFile) { + if (config.isCustomAndroidFile) { File( constants.androidAdaptiveXmlFolder(flavor) + - flutterLauncherIconsConfig.android + + config.android + '.xml', ).create(recursive: true).then((File adaptiveIcon) { adaptiveIcon.writeAsString(xml_template.icLauncherXml); @@ -180,7 +180,7 @@ void createAdaptiveIconMipmapXmlFile( /// creates adaptive background using png image void _createAdaptiveBackgrounds( - FlutterLauncherIconsConfig flutterLauncherIconsConfig, + Config config, String adaptiveIconBackgroundImagePath, String? flavor, ) { @@ -203,10 +203,10 @@ void _createAdaptiveBackgrounds( // Creates the xml file required for the adaptive launcher icon // FILE LOCATED HERE: res/mipmap-anydpi/{icon-name-from-yaml-config}.xml - if (flutterLauncherIconsConfig.isCustomAndroidFile) { + if (config.isCustomAndroidFile) { File( constants.androidAdaptiveXmlFolder(flavor) + - flutterLauncherIconsConfig.android + + config.android + '.xml', ).create(recursive: true).then((File adaptiveIcon) { adaptiveIcon.writeAsString(xml_template.icLauncherDrawableBackgroundXml); diff --git a/lib/config/config.dart b/lib/config/config.dart new file mode 100644 index 0000000000..ed19847d92 --- /dev/null +++ b/lib/config/config.dart @@ -0,0 +1,200 @@ +import 'dart:io'; + +import 'package:checked_yaml/checked_yaml.dart' as yaml; +import 'package:flutter_launcher_icons/config/macos_config.dart'; +import 'package:flutter_launcher_icons/config/web_config.dart'; +import 'package:flutter_launcher_icons/config/windows_config.dart'; +import 'package:flutter_launcher_icons/constants.dart' as constants; +import 'package:flutter_launcher_icons/custom_exceptions.dart'; +import 'package:flutter_launcher_icons/utils.dart' as utils; +import 'package:json_annotation/json_annotation.dart'; +import 'package:path/path.dart' as path; + +part 'config.g.dart'; + +/// A model representing the flutter_launcher_icons configuration +@JsonSerializable( + anyMap: true, + checked: true, +) +class Config { + /// Creates an instance of [Config] + const Config({ + this.imagePath, + this.android = false, + this.ios = false, + this.imagePathAndroid, + this.imagePathIOS, + this.adaptiveIconForeground, + this.adaptiveIconBackground, + this.minSdkAndroid = constants.androidDefaultAndroidMinSDK, + this.removeAlphaIOS = false, + this.webConfig, + this.windowsConfig, + this.macOSConfig, + }); + + + /// Creates [Config] for given [flavor] and [prefixPath] + static Config? loadConfigFromFlavor( + String flavor, + String prefixPath, + ) { + return _getConfigFromPubspecYaml( + prefix: prefixPath, + pathToPubspecYamlFile: utils.flavorConfigFile(flavor), + ); + } + + /// Loads flutter launcher icons configs from given [filePath] + static Config? loadConfigFromPath(String filePath, String prefixPath) { + return _getConfigFromPubspecYaml( + prefix: prefixPath, + pathToPubspecYamlFile: filePath, + ); + } + + /// Loads flutter launcher icons config from `pubspec.yaml` file + static Config? loadConfigFromPubSpec(String prefix) { + return _getConfigFromPubspecYaml( + prefix: prefix, + pathToPubspecYamlFile: constants.pubspecFilePath, + ); + } + + static Config? _getConfigFromPubspecYaml({ + required String pathToPubspecYamlFile, + required String prefix, + }) { + final configFile = File(path.join(prefix, pathToPubspecYamlFile)); + if (!configFile.existsSync()) { + return null; + } + final configContent = configFile.readAsStringSync(); + try { + return yaml.checkedYamlDecode( + configContent, + (Map? json) { + if (json != null) { + // if we have flutter_icons configuration ... + if (json['flutter_icons'] != null) { + stderr.writeln('\n⚠ Warning: flutter_icons has been deprecated ' + 'please use flutter_launcher_icons instead in your yaml files'); + return Config.fromJson(json['flutter_icons']); + } + // if we have flutter_launcher_icons configuration ... + if (json['flutter_launcher_icons'] != null) { + return Config.fromJson(json['flutter_launcher_icons']); + } + } + return null; + }, + allowNull: true, + ); + } on yaml.ParsedYamlException catch (e) { + throw InvalidConfigException(e.formattedMessage); + } catch (e) { + rethrow; + } + } + + /// Generic image_path + @JsonKey(name: 'image_path') + final String? imagePath; + + /// Returns true or path if android config is enabled + final dynamic android; // path or bool + + /// Returns true or path if ios config is enabled + final dynamic ios; // path or bool + + /// Image path specific to android + @JsonKey(name: 'image_path_android') + final String? imagePathAndroid; + + /// Image path specific to ios + @JsonKey(name: 'image_path_ios') + final String? imagePathIOS; + + /// android adaptive icon foreground image + @JsonKey(name: 'adaptive_icon_foreground') + final String? adaptiveIconForeground; + + /// android adaptive_icon_background image + @JsonKey(name: 'adaptive_icon_background') + final String? adaptiveIconBackground; + + /// Android min_sdk_android + @JsonKey(name: 'min_sdk_android') + final int minSdkAndroid; + + /// IOS remove_alpha_ios + @JsonKey(name: 'remove_alpha_ios') + final bool removeAlphaIOS; + + /// Web platform config + @JsonKey(name: 'web') + final WebConfig? webConfig; + + /// Windows platform config + @JsonKey(name: 'windows') + final WindowsConfig? windowsConfig; + + /// MacOS platform config + @JsonKey(name: 'macos') + final MacOSConfig? macOSConfig; + + /// Creates [Config] icons from [json] + factory Config.fromJson(Map json) => _$ConfigFromJson(json); + + /// whether or not there is configuration for adaptive icons for android + bool get hasAndroidAdaptiveConfig => + isNeedingNewAndroidIcon && + adaptiveIconForeground != null && + adaptiveIconBackground != null; + + /// Checks if contains any platform config + bool get hasPlatformConfig { + return ios != false || + android != false || + webConfig != null || + windowsConfig != null || + macOSConfig != null; + } + + /// Whether or not configuration for generating Web icons exist + bool get hasWebConfig => webConfig != null; + + /// Whether or not configuration for generating Windows icons exist + bool get hasWindowsConfig => windowsConfig != null; + + /// Whether or not configuration for generating MacOS icons exists + bool get hasMacOSConfig => macOSConfig != null; + + /// Check to see if specified Android config is a string or bool + /// String - Generate new launcher icon with the string specified + /// bool - override the default flutter project icon + bool get isCustomAndroidFile => android is String; + + /// if we are needing a new Android icon + bool get isNeedingNewAndroidIcon => android != false; + + /// if we are needing a new iOS icon + bool get isNeedingNewIOSIcon => ios != false; + + /// Method for the retrieval of the Android icon path + /// If image_path_android is found, this will be prioritised over the image_path + /// value. + String? getImagePathAndroid() => imagePathAndroid ?? imagePath; + + // TODO(RatakondalaArun): refactor after Android & iOS configs will be refactored to the new schema + // https://github.com/fluttercommunity/flutter_launcher_icons/issues/394 + /// get the image path for IOS + String? getImagePathIOS() => imagePathIOS ?? imagePath; + + /// Converts config to [Map] + Map toJson() => _$ConfigToJson(this); + + @override + String toString() => 'FlutterLauncherIconsConfig: ${toJson()}'; +} diff --git a/lib/config/config.g.dart b/lib/config/config.g.dart new file mode 100644 index 0000000000..9e18dc1675 --- /dev/null +++ b/lib/config/config.g.dart @@ -0,0 +1,64 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'config.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Config _$ConfigFromJson(Map json) => $checkedCreate( + 'Config', + json, + ($checkedConvert) { + final val = Config( + imagePath: $checkedConvert('image_path', (v) => v as String?), + android: $checkedConvert('android', (v) => v ?? false), + ios: $checkedConvert('ios', (v) => v ?? false), + imagePathAndroid: + $checkedConvert('image_path_android', (v) => v as String?), + imagePathIOS: $checkedConvert('image_path_ios', (v) => v as String?), + adaptiveIconForeground: + $checkedConvert('adaptive_icon_foreground', (v) => v as String?), + adaptiveIconBackground: + $checkedConvert('adaptive_icon_background', (v) => v as String?), + minSdkAndroid: $checkedConvert('min_sdk_android', + (v) => v as int? ?? constants.androidDefaultAndroidMinSDK), + removeAlphaIOS: + $checkedConvert('remove_alpha_ios', (v) => v as bool? ?? false), + webConfig: $checkedConvert( + 'web', (v) => v == null ? null : WebConfig.fromJson(v as Map)), + windowsConfig: $checkedConvert('windows', + (v) => v == null ? null : WindowsConfig.fromJson(v as Map)), + macOSConfig: $checkedConvert('macos', + (v) => v == null ? null : MacOSConfig.fromJson(v as Map)), + ); + return val; + }, + fieldKeyMap: const { + 'imagePath': 'image_path', + 'imagePathAndroid': 'image_path_android', + 'imagePathIOS': 'image_path_ios', + 'adaptiveIconForeground': 'adaptive_icon_foreground', + 'adaptiveIconBackground': 'adaptive_icon_background', + 'minSdkAndroid': 'min_sdk_android', + 'removeAlphaIOS': 'remove_alpha_ios', + 'webConfig': 'web', + 'windowsConfig': 'windows', + 'macOSConfig': 'macos' + }, + ); + +Map _$ConfigToJson(Config instance) => { + 'image_path': instance.imagePath, + 'android': instance.android, + 'ios': instance.ios, + 'image_path_android': instance.imagePathAndroid, + 'image_path_ios': instance.imagePathIOS, + 'adaptive_icon_foreground': instance.adaptiveIconForeground, + 'adaptive_icon_background': instance.adaptiveIconBackground, + 'min_sdk_android': instance.minSdkAndroid, + 'remove_alpha_ios': instance.removeAlphaIOS, + 'web': instance.webConfig, + 'windows': instance.windowsConfig, + 'macos': instance.macOSConfig, + }; diff --git a/lib/config/macos_config.dart b/lib/config/macos_config.dart new file mode 100644 index 0000000000..ee267efb64 --- /dev/null +++ b/lib/config/macos_config.dart @@ -0,0 +1,33 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'macos_config.g.dart'; + +/// The flutter_launcher_icons configuration set for MacOS +@JsonSerializable( + anyMap: true, + checked: true, +) +class MacOSConfig { + /// Specifies weather to generate icons for macos + @JsonKey() + final bool generate; + + /// Image path for macos + @JsonKey(name: 'image_path') + final String? imagePath; + + /// Creates a instance of [MacOSConfig] + const MacOSConfig({ + this.generate = false, + this.imagePath, + }); + + /// Creates [WebConfig] from [json] + factory MacOSConfig.fromJson(Map json) => _$MacOSConfigFromJson(json); + + /// Creates [Map] from [WebConfig] + Map toJson() => _$MacOSConfigToJson(this); + + @override + String toString() => '$runtimeType: ${toJson()}'; +} diff --git a/lib/config/macos_config.g.dart b/lib/config/macos_config.g.dart new file mode 100644 index 0000000000..ee22327acb --- /dev/null +++ b/lib/config/macos_config.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'macos_config.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MacOSConfig _$MacOSConfigFromJson(Map json) => $checkedCreate( + 'MacOSConfig', + json, + ($checkedConvert) { + final val = MacOSConfig( + generate: $checkedConvert('generate', (v) => v as bool? ?? false), + imagePath: $checkedConvert('image_path', (v) => v as String?), + ); + return val; + }, + fieldKeyMap: const {'imagePath': 'image_path'}, + ); + +Map _$MacOSConfigToJson(MacOSConfig instance) => + { + 'generate': instance.generate, + 'image_path': instance.imagePath, + }; diff --git a/lib/config/web_config.dart b/lib/config/web_config.dart new file mode 100644 index 0000000000..d577b51167 --- /dev/null +++ b/lib/config/web_config.dart @@ -0,0 +1,42 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'web_config.g.dart'; + +/// The flutter_launcher_icons configuration set for Web +@JsonSerializable( + anyMap: true, + checked: true, +) +class WebConfig { + /// Specifies weather to generate icons for web + final bool generate; + + /// Image path for web + @JsonKey(name: 'image_path') + final String? imagePath; + + /// manifest.json's background_color + @JsonKey(name: 'background_color') + final String? backgroundColor; + + /// manifest.json's theme_color + @JsonKey(name: 'theme_color') + final String? themeColor; + + /// Creates an instance of [WebConfig] + const WebConfig({ + this.generate = false, + this.imagePath, + this.backgroundColor, + this.themeColor, + }); + + /// Creates [WebConfig] from [json] + factory WebConfig.fromJson(Map json) => _$WebConfigFromJson(json); + + /// Creates [Map] from [WebConfig] + Map toJson() => _$WebConfigToJson(this); + + @override + String toString() => 'WebConfig: ${toJson()}'; +} \ No newline at end of file diff --git a/lib/config/web_config.g.dart b/lib/config/web_config.g.dart new file mode 100644 index 0000000000..d1451c0b35 --- /dev/null +++ b/lib/config/web_config.g.dart @@ -0,0 +1,34 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'web_config.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +WebConfig _$WebConfigFromJson(Map json) => $checkedCreate( + 'WebConfig', + json, + ($checkedConvert) { + final val = WebConfig( + generate: $checkedConvert('generate', (v) => v as bool? ?? false), + imagePath: $checkedConvert('image_path', (v) => v as String?), + backgroundColor: + $checkedConvert('background_color', (v) => v as String?), + themeColor: $checkedConvert('theme_color', (v) => v as String?), + ); + return val; + }, + fieldKeyMap: const { + 'imagePath': 'image_path', + 'backgroundColor': 'background_color', + 'themeColor': 'theme_color' + }, + ); + +Map _$WebConfigToJson(WebConfig instance) => { + 'generate': instance.generate, + 'image_path': instance.imagePath, + 'background_color': instance.backgroundColor, + 'theme_color': instance.themeColor, + }; diff --git a/lib/config/windows_config.dart b/lib/config/windows_config.dart new file mode 100644 index 0000000000..0c94e2e585 --- /dev/null +++ b/lib/config/windows_config.dart @@ -0,0 +1,37 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'windows_config.g.dart'; + +/// The flutter_launcher_icons configuration set for Windows +@JsonSerializable( + anyMap: true, + checked: true, +) +class WindowsConfig { + /// Specifies weather to generate icons for web + final bool generate; + + /// Image path for web + @JsonKey(name: 'image_path') + final String? imagePath; + + /// Size of the icon to generate + @JsonKey(name: 'icon_size') + final int? iconSize; + + /// Creates a instance of [WindowsConfig] + const WindowsConfig({ + this.generate = false, + this.imagePath, + this.iconSize, + }); + + /// Creates [WindowsConfig] from [json] + factory WindowsConfig.fromJson(Map json) => _$WindowsConfigFromJson(json); + + /// Creates [Map] from [WindowsConfig] + Map toJson() => _$WindowsConfigToJson(this); + + @override + String toString() => 'WindowsConfig: ${toJson()}'; +} diff --git a/lib/config/windows_config.g.dart b/lib/config/windows_config.g.dart new file mode 100644 index 0000000000..ef7a20e1ec --- /dev/null +++ b/lib/config/windows_config.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'windows_config.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +WindowsConfig _$WindowsConfigFromJson(Map json) => $checkedCreate( + 'WindowsConfig', + json, + ($checkedConvert) { + final val = WindowsConfig( + generate: $checkedConvert('generate', (v) => v as bool? ?? false), + imagePath: $checkedConvert('image_path', (v) => v as String?), + iconSize: $checkedConvert('icon_size', (v) => v as int?), + ); + return val; + }, + fieldKeyMap: const {'imagePath': 'image_path', 'iconSize': 'icon_size'}, + ); + +Map _$WindowsConfigToJson(WindowsConfig instance) => + { + 'generate': instance.generate, + 'image_path': instance.imagePath, + 'icon_size': instance.iconSize, + }; diff --git a/lib/flutter_launcher_icons_config.dart b/lib/flutter_launcher_icons_config.dart deleted file mode 100644 index 22d1d0e744..0000000000 --- a/lib/flutter_launcher_icons_config.dart +++ /dev/null @@ -1,300 +0,0 @@ -import 'dart:io'; - -import 'package:checked_yaml/checked_yaml.dart' as yaml; -import 'package:json_annotation/json_annotation.dart'; -import 'package:path/path.dart' as path; - -import 'constants.dart' as constants; -import 'custom_exceptions.dart'; -import 'utils.dart' as utils; - -part 'flutter_launcher_icons_config.g.dart'; - -/// A Config parsed from flutter_launcher_config.yaml -@JsonSerializable( - anyMap: true, - checked: true, -) -class FlutterLauncherIconsConfig { - /// Generic imagepath - @JsonKey(name: 'image_path') - final String? imagePath; - - /// Returns true or path if android config is enabled - final dynamic android; // path or bool - - /// Returns true or path if ios config is enabled - final dynamic ios; // path or bool - - /// Image path specific to android - @JsonKey(name: 'image_path_android') - final String? imagePathAndroid; - - /// Image path specific to ios - @JsonKey(name: 'image_path_ios') - final String? imagePathIOS; - - /// android adaptive icon foreground image - @JsonKey(name: 'adaptive_icon_foreground') - final String? adaptiveIconForeground; - - /// android adaptive_icon_background image - @JsonKey(name: 'adaptive_icon_background') - final String? adaptiveIconBackground; - - /// Android min_sdk_android - @JsonKey(name: 'min_sdk_android') - final int minSdkAndroid; - - /// IOS remove_alpha_ios - @JsonKey(name: 'remove_alpha_ios') - final bool removeAlphaIOS; - - /// Web platform config - @JsonKey(name: 'web') - final WebConfig? webConfig; - - /// Windows platform config - @JsonKey(name: 'windows') - final WindowsConfig? windowsConfig; - - /// MacOS platform config - @JsonKey(name: 'macos') - final MacOSConfig? macOSConfig; - - /// Creates an instance of [FlutterLauncherIconsConfig] - const FlutterLauncherIconsConfig({ - this.imagePath, - this.android = false, - this.ios = false, - this.imagePathAndroid, - this.imagePathIOS, - this.adaptiveIconForeground, - this.adaptiveIconBackground, - this.minSdkAndroid = constants.androidDefaultAndroidMinSDK, - this.removeAlphaIOS = false, - this.webConfig, - this.windowsConfig, - this.macOSConfig, - }); - - /// Creates [FlutterLauncherIconsConfig] icons from [json] - factory FlutterLauncherIconsConfig.fromJson(Map json) => - _$FlutterLauncherIconsConfigFromJson(json); - - /// whether or not there is configuration for adaptive icons for android - bool get hasAndroidAdaptiveConfig => - isNeedingNewAndroidIcon && - adaptiveIconForeground != null && - adaptiveIconBackground != null; - - /// Checks if contains any platform config - bool get hasPlatformConfig { - return ios != false || - android != false || - webConfig != null || - windowsConfig != null || - macOSConfig != null; - } - - /// Whether or not configuration for generating Web icons exist - bool get hasWebConfig => webConfig != null; - /// Whether or not configuration for generating Windows icons exist - bool get hasWindowsConfig => windowsConfig != null; - /// Whether or not configuration for generating MacOS icons exists - bool get hasMacOSConfig => macOSConfig != null; - - /// Check to see if specified Android config is a string or bool - /// String - Generate new launcher icon with the string specified - /// bool - override the default flutter project icon - bool get isCustomAndroidFile => android is String; - - /// if we are needing a new Android icon - bool get isNeedingNewAndroidIcon => android != false; - - /// if we are needing a new iOS icon - bool get isNeedingNewIOSIcon => ios != false; - - /// Method for the retrieval of the Android icon path - /// If image_path_android is found, this will be prioritised over the image_path - /// value. - String? getImagePathAndroid() => imagePathAndroid ?? imagePath; - - // TODO(RatakondalaArun): refactor after Android & iOS configs will be refactored to the new schema - // https://github.com/fluttercommunity/flutter_launcher_icons/issues/394 - /// get the image path for IOS - String? getImagePathIOS() => imagePathIOS ?? imagePath; - - /// Converts config to [Map] - Map toJson() => _$FlutterLauncherIconsConfigToJson(this); - - @override - String toString() => 'FlutterLauncherIconsConfig: ${toJson()}'; - - /// Creates [FlutterLauncherIconsConfig] for given [flavor] and [prefixPath] - static FlutterLauncherIconsConfig? loadConfigFromFlavor( - String flavor, - String prefixPath, - ) { - return FlutterLauncherIconsConfig.loadConfigFromPath( - utils.flavorConfigFile(flavor), - prefixPath, - ); - } - - /// Loads flutter launcher icons configs from given [filePath] - static FlutterLauncherIconsConfig? loadConfigFromPath( - String filePath, - String prefixPath, - ) { - final configFile = File(path.join(prefixPath, filePath)); - if (!configFile.existsSync()) { - return null; - } - final configContent = configFile.readAsStringSync(); - try { - return yaml.checkedYamlDecode( - configContent, - (json) { - // TODO(RatakondalaArun): add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373 - return json == null || json['flutter_icons'] == null - ? null - : FlutterLauncherIconsConfig.fromJson(json['flutter_icons']); - }, - allowNull: true, - ); - } on yaml.ParsedYamlException catch (e) { - throw InvalidConfigException(e.formattedMessage); - } catch (e) { - rethrow; - } - } - - /// Loads flutter launcher icons config from `pubspec.yaml` file - static FlutterLauncherIconsConfig? loadConfigFromPubSpec(String prefix) { - try { - final pubspecFile = File(path.join(prefix, constants.pubspecFilePath)); - if (!pubspecFile.existsSync()) { - return null; - } - final pubspecContent = pubspecFile.readAsStringSync(); - return yaml.checkedYamlDecode( - pubspecContent, - (json) { - // TODO(RatakondalaArun): add support for new scheme https://github.com/fluttercommunity/flutter_launcher_icons/issues/373 - return json == null || json['flutter_icons'] == null - ? null - : FlutterLauncherIconsConfig.fromJson(json['flutter_icons']); - }, - allowNull: true, - ); - } on yaml.ParsedYamlException catch (e) { - throw InvalidConfigException(e.formattedMessage); - } catch (e) { - rethrow; - } - } -} - -/// A Configs for Windows -@JsonSerializable( - anyMap: true, - checked: true, -) -class MacOSConfig { - /// Specifies weather to generate icons for macos - @JsonKey() - final bool generate; - - /// Image path for macos - @JsonKey(name: 'image_path') - final String? imagePath; - - /// Creates a instance of [MacOSConfig] - const MacOSConfig({ - this.generate = false, - this.imagePath, - }); - - /// Creates [WebConfig] from [json] - factory MacOSConfig.fromJson(Map json) => _$MacOSConfigFromJson(json); - - /// Creates [Map] from [WebConfig] - Map toJson() => _$MacOSConfigToJson(this); - - @override - String toString() => '$runtimeType: ${toJson()}'; -} - -/// Parse `web` config from `flutter_launcher_icons.yaml` -@JsonSerializable( - anyMap: true, - checked: true, -) -class WebConfig { - /// Specifies weather to generate icons for web - final bool generate; - - /// Image path for web - @JsonKey(name: 'image_path') - final String? imagePath; - - /// manifest.json's background_color - @JsonKey(name: 'background_color') - final String? backgroundColor; - - /// manifest.json's theme_color - @JsonKey(name: 'theme_color') - final String? themeColor; - - /// Creates an instance of [WebConfig] - const WebConfig({ - this.generate = false, - this.imagePath, - this.backgroundColor, - this.themeColor, - }); - - /// Creates [WebConfig] from [json] - factory WebConfig.fromJson(Map json) => _$WebConfigFromJson(json); - - /// Creates [Map] from [WebConfig] - Map toJson() => _$WebConfigToJson(this); - - @override - String toString() => 'WebConfig: ${toJson()}'; -} - -/// A Configs for Windows -@JsonSerializable( - anyMap: true, - checked: true, -) -class WindowsConfig { - /// Specifies weather to generate icons for web - final bool generate; - - /// Image path for web - @JsonKey(name: 'image_path') - final String? imagePath; - - /// Size of the icon to generate - @JsonKey(name: 'icon_size') - final int? iconSize; - - /// Creates a instance of [WindowsConfig] - const WindowsConfig({ - this.generate = false, - this.imagePath, - this.iconSize, - }); - - /// Creates [WindowsConfig] from [json] - factory WindowsConfig.fromJson(Map json) => _$WindowsConfigFromJson(json); - - /// Creates [Map] from [WindowsConfig] - Map toJson() => _$WindowsConfigToJson(this); - - @override - String toString() => 'WindowsConfig: ${toJson()}'; -} diff --git a/lib/flutter_launcher_icons_config.g.dart b/lib/flutter_launcher_icons_config.g.dart deleted file mode 100644 index 5636badb01..0000000000 --- a/lib/flutter_launcher_icons_config.g.dart +++ /dev/null @@ -1,134 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'flutter_launcher_icons_config.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -FlutterLauncherIconsConfig _$FlutterLauncherIconsConfigFromJson(Map json) => - $checkedCreate( - 'FlutterLauncherIconsConfig', - json, - ($checkedConvert) { - final val = FlutterLauncherIconsConfig( - imagePath: $checkedConvert('image_path', (v) => v as String?), - android: $checkedConvert('android', (v) => v ?? false), - ios: $checkedConvert('ios', (v) => v ?? false), - imagePathAndroid: - $checkedConvert('image_path_android', (v) => v as String?), - imagePathIOS: $checkedConvert('image_path_ios', (v) => v as String?), - adaptiveIconForeground: - $checkedConvert('adaptive_icon_foreground', (v) => v as String?), - adaptiveIconBackground: - $checkedConvert('adaptive_icon_background', (v) => v as String?), - minSdkAndroid: $checkedConvert('min_sdk_android', - (v) => v as int? ?? constants.androidDefaultAndroidMinSDK), - removeAlphaIOS: - $checkedConvert('remove_alpha_ios', (v) => v as bool? ?? false), - webConfig: $checkedConvert( - 'web', (v) => v == null ? null : WebConfig.fromJson(v as Map)), - windowsConfig: $checkedConvert('windows', - (v) => v == null ? null : WindowsConfig.fromJson(v as Map)), - macOSConfig: $checkedConvert('macos', - (v) => v == null ? null : MacOSConfig.fromJson(v as Map)), - ); - return val; - }, - fieldKeyMap: const { - 'imagePath': 'image_path', - 'imagePathAndroid': 'image_path_android', - 'imagePathIOS': 'image_path_ios', - 'adaptiveIconForeground': 'adaptive_icon_foreground', - 'adaptiveIconBackground': 'adaptive_icon_background', - 'minSdkAndroid': 'min_sdk_android', - 'removeAlphaIOS': 'remove_alpha_ios', - 'webConfig': 'web', - 'windowsConfig': 'windows', - 'macOSConfig': 'macos' - }, - ); - -Map _$FlutterLauncherIconsConfigToJson( - FlutterLauncherIconsConfig instance) => - { - 'image_path': instance.imagePath, - 'android': instance.android, - 'ios': instance.ios, - 'image_path_android': instance.imagePathAndroid, - 'image_path_ios': instance.imagePathIOS, - 'adaptive_icon_foreground': instance.adaptiveIconForeground, - 'adaptive_icon_background': instance.adaptiveIconBackground, - 'min_sdk_android': instance.minSdkAndroid, - 'remove_alpha_ios': instance.removeAlphaIOS, - 'web': instance.webConfig, - 'windows': instance.windowsConfig, - 'macos': instance.macOSConfig, - }; - -MacOSConfig _$MacOSConfigFromJson(Map json) => $checkedCreate( - 'MacOSConfig', - json, - ($checkedConvert) { - final val = MacOSConfig( - generate: $checkedConvert('generate', (v) => v as bool? ?? false), - imagePath: $checkedConvert('image_path', (v) => v as String?), - ); - return val; - }, - fieldKeyMap: const {'imagePath': 'image_path'}, - ); - -Map _$MacOSConfigToJson(MacOSConfig instance) => - { - 'generate': instance.generate, - 'image_path': instance.imagePath, - }; - -WebConfig _$WebConfigFromJson(Map json) => $checkedCreate( - 'WebConfig', - json, - ($checkedConvert) { - final val = WebConfig( - generate: $checkedConvert('generate', (v) => v as bool? ?? false), - imagePath: $checkedConvert('image_path', (v) => v as String?), - backgroundColor: - $checkedConvert('background_color', (v) => v as String?), - themeColor: $checkedConvert('theme_color', (v) => v as String?), - ); - return val; - }, - fieldKeyMap: const { - 'imagePath': 'image_path', - 'backgroundColor': 'background_color', - 'themeColor': 'theme_color' - }, - ); - -Map _$WebConfigToJson(WebConfig instance) => { - 'generate': instance.generate, - 'image_path': instance.imagePath, - 'background_color': instance.backgroundColor, - 'theme_color': instance.themeColor, - }; - -WindowsConfig _$WindowsConfigFromJson(Map json) => $checkedCreate( - 'WindowsConfig', - json, - ($checkedConvert) { - final val = WindowsConfig( - generate: $checkedConvert('generate', (v) => v as bool? ?? false), - imagePath: $checkedConvert('image_path', (v) => v as String?), - iconSize: $checkedConvert('icon_size', (v) => v as int?), - ); - return val; - }, - fieldKeyMap: const {'imagePath': 'image_path', 'iconSize': 'icon_size'}, - ); - -Map _$WindowsConfigToJson(WindowsConfig instance) => - { - 'generate': instance.generate, - 'image_path': instance.imagePath, - 'icon_size': instance.iconSize, - }; diff --git a/lib/ios.dart b/lib/ios.dart index 7263ceacc3..dc2689a09d 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -5,7 +5,7 @@ import 'dart:io'; import 'package:flutter_launcher_icons/constants.dart'; import 'package:flutter_launcher_icons/custom_exceptions.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/utils.dart'; import 'package:image/image.dart'; @@ -47,7 +47,7 @@ List iosIcons = [ ]; /// create the ios icons -void createIcons(FlutterLauncherIconsConfig config, String? flavor) { +void createIcons(Config config, String? flavor) { // TODO(p-mazhnik): support prefixPath final String? filePath = config.getImagePathIOS(); if (filePath == null) { diff --git a/lib/main.dart b/lib/main.dart index cc8530e21d..dd6037b4f0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,7 +8,7 @@ import 'package:flutter_launcher_icons/android.dart' as android_launcher_icons; import 'package:flutter_launcher_icons/constants.dart' as constants; import 'package:flutter_launcher_icons/constants.dart'; import 'package:flutter_launcher_icons/custom_exceptions.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/ios.dart' as ios_launcher_icons; import 'package:flutter_launcher_icons/logger.dart'; import 'package:flutter_launcher_icons/macos/macos_icon_generator.dart'; @@ -104,7 +104,7 @@ Future createIconsFromArguments(List arguments) async { for (String flavor in flavors) { print('\nFlavor: $flavor'); final flutterLauncherIconsConfigs = - FlutterLauncherIconsConfig.loadConfigFromFlavor(flavor, prefixPath); + Config.loadConfigFromFlavor(flavor, prefixPath); if (flutterLauncherIconsConfigs == null) { throw NoConfigFoundException( 'No configuration found for $flavor flavor.', @@ -127,7 +127,7 @@ Future createIconsFromArguments(List arguments) async { } Future createIconsFromConfig( - FlutterLauncherIconsConfig flutterConfigs, + Config flutterConfigs, FLILogger logger, String prefixPath, [ String? flavor, @@ -168,15 +168,15 @@ Future createIconsFromConfig( ); } -FlutterLauncherIconsConfig? loadConfigFileFromArgResults( +Config? loadConfigFileFromArgResults( ArgResults argResults, ) { final String prefixPath = argResults[prefixOption]; final flutterLauncherIconsConfigs = - FlutterLauncherIconsConfig.loadConfigFromPath( + Config.loadConfigFromPath( argResults[fileOption], prefixPath, ) ?? - FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath); + Config.loadConfigFromPubSpec(prefixPath); return flutterLauncherIconsConfigs; } diff --git a/pubspec.yaml b/pubspec.yaml index 322bfd00c8..f35f8462a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_launcher_icons description: A package which simplifies the task of updating your Flutter app's launcher icon. -version: 0.13.0 +version: 0.13.1 maintainer: Mark O'Sullivan (@MarkOSullivan94) homepage: https://github.com/fluttercommunity/flutter_launcher_icons repository: https://github.com/fluttercommunity/flutter_launcher_icons/ diff --git a/test/abs/icon_generator_test.dart b/test/abs/icon_generator_test.dart index c93f44a463..384ee1bffe 100644 --- a/test/abs/icon_generator_test.dart +++ b/test/abs/icon_generator_test.dart @@ -1,5 +1,5 @@ import 'package:flutter_launcher_icons/abs/icon_generator.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/logger.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -9,16 +9,16 @@ import 'package:test_descriptor/test_descriptor.dart' as d; import 'icon_generator_test.mocks.dart'; -@GenerateMocks([FlutterLauncherIconsConfig, IconGenerator]) +@GenerateMocks([Config, IconGenerator]) void main() { group('#generateIconsFor', () { late String prefixPath; late FLILogger logger; late IconGenerator mockGenerator; - late FlutterLauncherIconsConfig mockFLIConfig; + late Config mockFLIConfig; setUp(() async { prefixPath = path.join(d.sandbox, 'fli_test'); - mockFLIConfig = MockFlutterLauncherIconsConfig(); + mockFLIConfig = MockConfig(); logger = FLILogger(false); mockGenerator = MockIconGenerator(); when(mockGenerator.platformName).thenReturn('Mock'); diff --git a/test/abs/icon_generator_test.mocks.dart b/test/abs/icon_generator_test.mocks.dart index 8b26393b81..51f96e65c9 100644 --- a/test/abs/icon_generator_test.mocks.dart +++ b/test/abs/icon_generator_test.mocks.dart @@ -4,8 +4,7 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:flutter_launcher_icons/abs/icon_generator.dart' as _i2; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart' - as _i3; +import 'package:flutter_launcher_icons/config/config.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -30,12 +29,11 @@ class _FakeIconGeneratorContext_0 extends _i1.SmartFake ); } -/// A class which mocks [FlutterLauncherIconsConfig]. +/// A class which mocks [Config]. /// /// See the documentation for Mockito's code generation for more information. -class MockFlutterLauncherIconsConfig extends _i1.Mock - implements _i3.FlutterLauncherIconsConfig { - MockFlutterLauncherIconsConfig() { +class MockConfig extends _i1.Mock implements _i3.Config { + MockConfig() { _i1.throwOnMissingStub(this); } diff --git a/test/android_test.dart b/test/android_test.dart index 4e8e9bcdfb..0d58810bac 100644 --- a/test/android_test.dart +++ b/test/android_test.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:flutter_launcher_icons/android.dart' as android; import 'package:flutter_launcher_icons/constants.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:test/test.dart'; // unit tests for android.dart @@ -35,7 +35,7 @@ void main() { 'ios': true }; expect( - FlutterLauncherIconsConfig.fromJson(flutterIconsConfig) + Config.fromJson(flutterIconsConfig) .isCustomAndroidFile, isFalse, ); @@ -46,7 +46,7 @@ void main() { 'ios': true }; expect( - FlutterLauncherIconsConfig.fromJson(flutterIconsNewIconConfig) + Config.fromJson(flutterIconsNewIconConfig) .isCustomAndroidFile, isTrue, ); @@ -60,7 +60,7 @@ void main() { 'ios': true }; expect( - FlutterLauncherIconsConfig.fromJson(flutterIconsNewIconConfig) + Config.fromJson(flutterIconsNewIconConfig) .getImagePathAndroid(), equals('assets/images/icon-android.png'), ); diff --git a/test/flutter_launcher_icons_config_test.dart b/test/flutter_launcher_icons_config_test.dart index a65a7cfb46..e008ee322b 100644 --- a/test/flutter_launcher_icons_config_test.dart +++ b/test/flutter_launcher_icons_config_test.dart @@ -1,5 +1,5 @@ import 'package:flutter_launcher_icons/custom_exceptions.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; @@ -20,7 +20,7 @@ void main() { ]).create(); }); test('should return valid configs', () { - final configs = FlutterLauncherIconsConfig.loadConfigFromPath( + final configs = Config.loadConfigFromPath( 'flutter_launcher_icons.yaml', prefixPath, ); @@ -78,7 +78,7 @@ void main() { }); test('should return null when invalid filePath is given', () { - final configs = FlutterLauncherIconsConfig.loadConfigFromPath( + final configs = Config.loadConfigFromPath( 'file_that_dont_exist.yaml', prefixPath, ); @@ -87,7 +87,7 @@ void main() { test('should throw InvalidConfigException when config is invalid', () { expect( - () => FlutterLauncherIconsConfig.loadConfigFromPath( + () => Config.loadConfigFromPath( 'invalid_fli_config.yaml', prefixPath, ), @@ -99,7 +99,7 @@ void main() { test('should return valid configs', () { const String path = 'test/config/test_pubspec.yaml'; final configs = - FlutterLauncherIconsConfig.loadConfigFromPath(path, '.'); + Config.loadConfigFromPath(path, '.'); expect(configs, isNotNull); const String imagePath = 'assets/images/icon-710x599.png'; expect(configs!.imagePath, equals(imagePath)); @@ -133,7 +133,7 @@ void main() { }); test('should return valid configs', () { final configs = - FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath); + Config.loadConfigFromPubSpec(prefixPath); expect(configs, isNotNull); // android configs expect(configs!.android, isTrue); @@ -200,7 +200,7 @@ void main() { }); test('InvalidConfigException when config is invalid', () { expect( - () => FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath), + () => Config.loadConfigFromPubSpec(prefixPath), throwsA(isA()), ); }); @@ -216,7 +216,7 @@ void main() { ]).create(); }); test('should return valid config', () { - final configs = FlutterLauncherIconsConfig.loadConfigFromFlavor( + final configs = Config.loadConfigFromFlavor( 'development', prefixPath, ); diff --git a/test/macos/macos_icon_generator_test.dart b/test/macos/macos_icon_generator_test.dart index 2d4ac33bfe..9af9f65dc6 100644 --- a/test/macos/macos_icon_generator_test.dart +++ b/test/macos/macos_icon_generator_test.dart @@ -1,7 +1,8 @@ import 'dart:io'; import 'package:flutter_launcher_icons/abs/icon_generator.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; +import 'package:flutter_launcher_icons/config/macos_config.dart'; import 'package:flutter_launcher_icons/logger.dart'; import 'package:flutter_launcher_icons/macos/macos_icon_generator.dart'; import 'package:mockito/annotations.dart'; @@ -13,7 +14,7 @@ import 'package:test_descriptor/test_descriptor.dart' as d; import '../templates.dart' as templates; @GenerateNiceMocks([ - MockSpec(), + MockSpec(), MockSpec(), MockSpec(), ]) @@ -23,7 +24,7 @@ void main() { group('MacOSIconGenerator', () { late IconGeneratorContext context; late IconGenerator generator; - late FlutterLauncherIconsConfig mockConfig; + late Config mockConfig; late MacOSConfig mockMacOSConfig; late String prefixPath; late File testImageFile; @@ -37,7 +38,7 @@ void main() { }); setUp(() { prefixPath = path.join(d.sandbox, 'fli_test'); - mockConfig = MockFlutterLauncherIconsConfig(); + mockConfig = MockConfig(); mockMacOSConfig = MockMacOSConfig(); mockLogger = MockFLILogger(); context = IconGeneratorContext( @@ -114,7 +115,7 @@ void main() { group('MacOSIconGenerator end-to-end', () { late IconGeneratorContext context; late IconGenerator generator; - late FlutterLauncherIconsConfig config; + late Config config; late String prefixPath; final assetPath = path.join(Directory.current.path, 'test', 'assets'); @@ -129,7 +130,7 @@ void main() { d.file('app_icon.png', imageFile.readAsBytesSync()), ]).create(); prefixPath = path.join(d.sandbox, 'fli_test'); - config = FlutterLauncherIconsConfig.loadConfigFromPath( + config = Config.loadConfigFromPath( 'flutter_launcher_icons.yaml', prefixPath, )!; diff --git a/test/macos/macos_icon_generator_test.mocks.dart b/test/macos/macos_icon_generator_test.mocks.dart index 1039287ade..69165d866c 100644 --- a/test/macos/macos_icon_generator_test.mocks.dart +++ b/test/macos/macos_icon_generator_test.mocks.dart @@ -4,9 +4,9 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:cli_util/cli_logging.dart' as _i2; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart' - as _i3; -import 'package:flutter_launcher_icons/logger.dart' as _i4; +import 'package:flutter_launcher_icons/config/config.dart' as _i3; +import 'package:flutter_launcher_icons/config/macos_config.dart' as _i4; +import 'package:flutter_launcher_icons/logger.dart' as _i5; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -40,11 +40,10 @@ class _FakeProgress_1 extends _i1.SmartFake implements _i2.Progress { ); } -/// A class which mocks [FlutterLauncherIconsConfig]. +/// A class which mocks [Config]. /// /// See the documentation for Mockito's code generation for more information. -class MockFlutterLauncherIconsConfig extends _i1.Mock - implements _i3.FlutterLauncherIconsConfig { +class MockConfig extends _i1.Mock implements _i3.Config { @override int get minSdkAndroid => (super.noSuchMethod( Invocation.getter(#minSdkAndroid), @@ -101,7 +100,7 @@ class MockFlutterLauncherIconsConfig extends _i1.Mock /// A class which mocks [MacOSConfig]. /// /// See the documentation for Mockito's code generation for more information. -class MockMacOSConfig extends _i1.Mock implements _i3.MacOSConfig { +class MockMacOSConfig extends _i1.Mock implements _i4.MacOSConfig { @override bool get generate => (super.noSuchMethod( Invocation.getter(#generate), @@ -122,7 +121,7 @@ class MockMacOSConfig extends _i1.Mock implements _i3.MacOSConfig { /// A class which mocks [FLILogger]. /// /// See the documentation for Mockito's code generation for more information. -class MockFLILogger extends _i1.Mock implements _i4.FLILogger { +class MockFLILogger extends _i1.Mock implements _i5.FLILogger { @override bool get isVerbose => (super.noSuchMethod( Invocation.getter(#isVerbose), diff --git a/test/main_test.dart b/test/main_test.dart index 4064d5c0c3..7db253fd6c 100644 --- a/test/main_test.dart +++ b/test/main_test.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:flutter_launcher_icons/android.dart' as android; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/ios.dart' as ios; import 'package:flutter_launcher_icons/main.dart' show defaultConfigFile; import 'package:flutter_launcher_icons/main.dart' as main_dart; @@ -62,7 +62,7 @@ flutter_icons: ios: false '''); final ArgResults argResults = parser.parse([]); - final FlutterLauncherIconsConfig? config = + final Config? config = main_dart.loadConfigFileFromArgResults(argResults); expect(config, isNotNull); expect(config!.android, isTrue); @@ -75,7 +75,7 @@ flutter_icons: ios: false '''); ArgResults argResults = parser.parse([]); - final FlutterLauncherIconsConfig? config = + final Config? config = main_dart.loadConfigFileFromArgResults(argResults); expect(config, isNotNull); expect(config!.ios, isFalse); @@ -94,7 +94,7 @@ flutter_icons: '''); // if no argument set, should fail ArgResults argResults = parser.parse(['-f', 'custom.yaml']); - final FlutterLauncherIconsConfig? config = + final Config? config = main_dart.loadConfigFileFromArgResults(argResults); expect(config, isNotNull); expect(config!.ios, isTrue); @@ -115,7 +115,7 @@ flutter_icons: 'android': true, 'ios': true }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect( config.getImagePathAndroid(), equals('assets/images/icon-710x599.png'), @@ -127,7 +127,7 @@ flutter_icons: 'ios': true }; final configAndroid = - FlutterLauncherIconsConfig.fromJson(flutterIconsConfigAndroid); + Config.fromJson(flutterIconsConfigAndroid); expect( configAndroid.getImagePathAndroid(), equals('assets/images/icon-710x599.png'), @@ -140,7 +140,7 @@ flutter_icons: 'ios': true }; final configBoth = - FlutterLauncherIconsConfig.fromJson(flutterIconsConfigBoth); + Config.fromJson(flutterIconsConfigBoth); expect( configBoth.getImagePathAndroid(), equals('assets/images/icon-android.png'), @@ -154,7 +154,7 @@ flutter_icons: 'android': true, 'ios': true }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.hasPlatformConfig, isTrue); }); @@ -162,7 +162,7 @@ flutter_icons: final Map flutterIconsConfig = { 'image_path': 'assets/images/icon-710x599.png' }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.hasPlatformConfig, isFalse); }); @@ -172,7 +172,7 @@ flutter_icons: 'android': false, 'ios': true }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.isNeedingNewAndroidIcon, isFalse); }); @@ -181,7 +181,7 @@ flutter_icons: 'image_path': 'assets/images/icon-710x599.png', 'ios': true }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.isNeedingNewAndroidIcon, isFalse); }); @@ -191,7 +191,7 @@ flutter_icons: 'android': true, 'ios': false }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.isNeedingNewIOSIcon, isFalse); }); @@ -200,7 +200,7 @@ flutter_icons: 'image_path': 'assets/images/icon-710x599.png', 'android': true }; - final config = FlutterLauncherIconsConfig.fromJson(flutterIconsConfig); + final config = Config.fromJson(flutterIconsConfig); expect(config.isNeedingNewIOSIcon, isFalse); }); } diff --git a/test/web/web_icon_generator_test.dart b/test/web/web_icon_generator_test.dart index c3a2226586..6872ffa6a0 100644 --- a/test/web/web_icon_generator_test.dart +++ b/test/web/web_icon_generator_test.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:flutter_launcher_icons/abs/icon_generator.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; import 'package:flutter_launcher_icons/logger.dart'; import 'package:flutter_launcher_icons/web/web_icon_generator.dart'; import 'package:path/path.dart' as path; @@ -14,7 +14,7 @@ void main() { group('WebIconGenerator', () { late IconGeneratorContext context; late IconGenerator generator; - late FlutterLauncherIconsConfig config; + late Config config; late String prefixPath; final assetPath = path.join(Directory.current.path, 'test', 'assets'); @@ -32,7 +32,7 @@ void main() { d.file('app_icon.png', imageFile.readAsBytesSync()), ]).create(); prefixPath = path.join(d.sandbox, 'fli_test'); - config = FlutterLauncherIconsConfig.loadConfigFromPath( + config = Config.loadConfigFromPath( 'flutter_launcher_icons.yaml', prefixPath, )!; diff --git a/test/windows/windows_icon_generator_test.dart b/test/windows/windows_icon_generator_test.dart index 8bc3c8c2ec..2aa520acdd 100644 --- a/test/windows/windows_icon_generator_test.dart +++ b/test/windows/windows_icon_generator_test.dart @@ -1,7 +1,8 @@ import 'dart:io'; import 'package:flutter_launcher_icons/abs/icon_generator.dart'; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; +import 'package:flutter_launcher_icons/config/config.dart'; +import 'package:flutter_launcher_icons/config/windows_config.dart'; import 'package:flutter_launcher_icons/logger.dart'; import 'package:flutter_launcher_icons/windows/windows_icon_generator.dart'; import 'package:mockito/annotations.dart'; @@ -13,12 +14,12 @@ import 'package:test_descriptor/test_descriptor.dart' as d; import '../templates.dart' as templates; import 'windows_icon_generator_test.mocks.dart'; -@GenerateMocks([FlutterLauncherIconsConfig, WindowsConfig, FLILogger]) +@GenerateMocks([Config, WindowsConfig, FLILogger]) void main() { group('WindowsIconGenerator', () { late IconGeneratorContext context; late IconGenerator generator; - late FlutterLauncherIconsConfig mockConfig; + late Config mockConfig; late WindowsConfig mockWindowsConfig; late String prefixPath; late File testImageFile; @@ -33,7 +34,7 @@ void main() { }); setUp(() async { prefixPath = path.join(d.sandbox, 'fli_test'); - mockConfig = MockFlutterLauncherIconsConfig(); + mockConfig = MockConfig(); mockWindowsConfig = MockWindowsConfig(); mockLogger = MockFLILogger(); context = IconGeneratorContext( @@ -122,7 +123,7 @@ void main() { group('WindowsIconGenerator end-to-end', () { late IconGeneratorContext context; late IconGenerator generator; - late FlutterLauncherIconsConfig config; + late Config config; late String prefixPath; final assetPath = path.join(Directory.current.path, 'test', 'assets'); @@ -136,7 +137,7 @@ void main() { d.file('app_icon.png', imageFile.readAsBytesSync()), ]).create(); prefixPath = path.join(d.sandbox, 'fli_test'); - config = FlutterLauncherIconsConfig.loadConfigFromPath( + config = Config.loadConfigFromPath( 'flutter_launcher_icons.yaml', prefixPath, )!; diff --git a/test/windows/windows_icon_generator_test.mocks.dart b/test/windows/windows_icon_generator_test.mocks.dart index 4ca4948570..3bad122ef0 100644 --- a/test/windows/windows_icon_generator_test.mocks.dart +++ b/test/windows/windows_icon_generator_test.mocks.dart @@ -4,9 +4,9 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:cli_util/cli_logging.dart' as _i2; -import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart' - as _i3; -import 'package:flutter_launcher_icons/logger.dart' as _i4; +import 'package:flutter_launcher_icons/config/config.dart' as _i3; +import 'package:flutter_launcher_icons/config/windows_config.dart' as _i4; +import 'package:flutter_launcher_icons/logger.dart' as _i5; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -40,12 +40,11 @@ class _FakeProgress_1 extends _i1.SmartFake implements _i2.Progress { ); } -/// A class which mocks [FlutterLauncherIconsConfig]. +/// A class which mocks [Config]. /// /// See the documentation for Mockito's code generation for more information. -class MockFlutterLauncherIconsConfig extends _i1.Mock - implements _i3.FlutterLauncherIconsConfig { - MockFlutterLauncherIconsConfig() { +class MockConfig extends _i1.Mock implements _i3.Config { + MockConfig() { _i1.throwOnMissingStub(this); } @@ -97,7 +96,7 @@ class MockFlutterLauncherIconsConfig extends _i1.Mock /// A class which mocks [WindowsConfig]. /// /// See the documentation for Mockito's code generation for more information. -class MockWindowsConfig extends _i1.Mock implements _i3.WindowsConfig { +class MockWindowsConfig extends _i1.Mock implements _i4.WindowsConfig { MockWindowsConfig() { _i1.throwOnMissingStub(this); } @@ -120,7 +119,7 @@ class MockWindowsConfig extends _i1.Mock implements _i3.WindowsConfig { /// A class which mocks [FLILogger]. /// /// See the documentation for Mockito's code generation for more information. -class MockFLILogger extends _i1.Mock implements _i4.FLILogger { +class MockFLILogger extends _i1.Mock implements _i5.FLILogger { MockFLILogger() { _i1.throwOnMissingStub(this); }