From 8450cb87cc8ee2f4a9248ddd76e0e015612f68d3 Mon Sep 17 00:00:00 2001 From: wasabeef Date: Mon, 12 Sep 2022 17:08:01 +0900 Subject: [PATCH 1/4] fix: remove trailing comma --- .vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7241e21a..78ab0977 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,6 +28,6 @@ "--config", "${workspaceFolder}/example/pubspec.yaml" ] - }, + } ] -} \ No newline at end of file +} From 549067a2639ab37fbdaf838ca95fa768d332b741 Mon Sep 17 00:00:00 2001 From: wasabeef Date: Mon, 12 Sep 2022 17:08:33 +0900 Subject: [PATCH 2/4] chore: update sample codes --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile.lock | 48 ++++++++++---------- example/ios/Runner.xcodeproj/project.pbxproj | 6 +-- example/lib/gen/assets.gen.dart | 4 +- example/lib/gen/colors.gen.dart | 4 +- example/lib/gen/fonts.gen.dart | 4 +- example/lib/main.dart | 34 +++++++------- example/pubspec.yaml | 12 ++++- 8 files changed, 60 insertions(+), 54 deletions(-) diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index f2872cf4..4f8d4d24 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 6a6fccb1..ed76dcbd 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -202,11 +202,11 @@ PODS: - GoogleUtilities/Network (~> 7.7) - "GoogleUtilities/NSData+zlib (~> 7.7)" - nanopb (~> 2.30908.0) - - GoogleDataTransport (9.1.4): + - GoogleDataTransport (9.2.0): - GoogleUtilities/Environment (~> 7.7) - nanopb (< 2.30910.0, >= 2.30908.0) - PromisesObjC (< 3.0, >= 1.2) - - GoogleSignIn (6.2.1): + - GoogleSignIn (6.2.3): - AppAuth (~> 1.5) - GTMAppAuth (~> 1.3) - GTMSessionFetcher/Core (~> 1.1) @@ -244,15 +244,15 @@ PODS: - Flutter - is_firebase_test_lab_activated (0.0.1): - Flutter - - libwebp (1.2.1): - - libwebp/demux (= 1.2.1) - - libwebp/mux (= 1.2.1) - - libwebp/webp (= 1.2.1) - - libwebp/demux (1.2.1): + - libwebp (1.2.3): + - libwebp/demux (= 1.2.3) + - libwebp/mux (= 1.2.3) + - libwebp/webp (= 1.2.3) + - libwebp/demux (1.2.3): - libwebp/webp - - libwebp/mux (1.2.1): + - libwebp/mux (1.2.3): - libwebp/demux - - libwebp/webp (1.2.1) + - libwebp/webp (1.2.3) - local_auth_ios (0.0.1): - Flutter - Mantle (2.2.0): @@ -272,14 +272,14 @@ PODS: - Flutter - permission_handler_apple (9.0.4): - Flutter - - PromisesObjC (2.1.0) + - PromisesObjC (2.1.1) - ReachabilitySwift (5.0.0) - - SDWebImage (5.12.5): - - SDWebImage/Core (= 5.12.5) - - SDWebImage/Core (5.12.5) - - SDWebImageWebPCoder (0.8.4): + - SDWebImage (5.13.2): + - SDWebImage/Core (= 5.13.2) + - SDWebImage/Core (5.13.2) + - SDWebImageWebPCoder (0.9.1): - libwebp (~> 1.0) - - SDWebImage/Core (~> 5.10) + - SDWebImage/Core (~> 5.13) - Sentry (7.11.0): - Sentry/Core (= 7.11.0) - Sentry/Core (7.11.0) @@ -518,7 +518,7 @@ SPEC CHECKSUMS: FirebaseMessaging: 5ebc42d281567658a2cb72b9ef3506e4a1a1a6e4 FirebasePerformance: ecaa182ba9c6654e2e3813e759036d80e22269a8 FirebaseRemoteConfig: a5d9188d8f57f602636f111eca6460ebe32b9b71 - Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_facebook_auth: a030aef1c2552fdc7cb090acc716ac836e3bb63c flutter_image_compress: fd2b476345226e1a10ea352fa306af95704642c1 flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721 @@ -527,10 +527,10 @@ SPEC CHECKSUMS: FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a geocoding: 32cfcdb16d38d907caaba65e2e42ad10d38bee58 geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401 - google_sign_in_ios: 90eec6616c4c2105b9f9fe5c774773d13565b504 + google_sign_in_ios: 4f85eb9f937450765c8573bb85fd8cd6a5af675c GoogleAppMeasurement: 71156240babd3cc6ced03e0d54816f01a880c730 - GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b - GoogleSignIn: 9c69f4188921d8f789816e4c99ba2a1f5f868ddc + GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f + GoogleSignIn: f4d3939cc0d9264d7509c4b9a924a6c987e30b54 GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1 GTMAppAuth: 4d8f864896f3646f0c33baf38a28362f4c601e15 GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba @@ -539,7 +539,7 @@ SPEC CHECKSUMS: in_app_review: 4a97249f7a2f539a0f294c2d9196b7fe35e49541 integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5 is_firebase_test_lab_activated: 84effe92e5d79a58455a2861b5e1ba688016cf57 - libwebp: 98a37e597e40bfdb4c911fc98f2c53d0b12d05fc + libwebp: 60305b2e989864154bd9be3d772730f08fc6a59c local_auth_ios: 0d333dde7780f669e66f19d2ff6005f3ea84008d Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96 @@ -548,10 +548,10 @@ SPEC CHECKSUMS: package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce - PromisesObjC: 99b6f43f9e1044bd87a95a60beff28c2c44ddb72 + PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 - SDWebImage: 0905f1b7760fc8ac4198cae0036600d67478751e - SDWebImageWebPCoder: f93010f3f6c031e2f8fb3081ca4ee6966c539815 + SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866 + SDWebImageWebPCoder: 18503de6621dd2c420d680e33d46bf8e1d5169b0 Sentry: 0c5cd63d714187b4a39c331c1f0eb04ba7868341 sentry_flutter: efb3df2c203cd03aad255892a8d628a458656d14 share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68 @@ -568,4 +568,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index a1a05320..8a7d67dc 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -340,7 +340,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -425,7 +425,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -474,7 +474,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/lib/gen/assets.gen.dart b/example/lib/gen/assets.gen.dart index 2cacdc5c..7d9b07c5 100644 --- a/example/lib/gen/assets.gen.dart +++ b/example/lib/gen/assets.gen.dart @@ -105,8 +105,8 @@ class $AssetsImagesIconsGen { SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg'); } -class Assets { - Assets._(); +class MyAssets { + MyAssets._(); static const $AssetsFlareGen flare = $AssetsFlareGen(); static const $AssetsImagesGen images = $AssetsImagesGen(); diff --git a/example/lib/gen/colors.gen.dart b/example/lib/gen/colors.gen.dart index 530b11c8..8d4e9756 100644 --- a/example/lib/gen/colors.gen.dart +++ b/example/lib/gen/colors.gen.dart @@ -10,8 +10,8 @@ import 'package:flutter/painting.dart'; import 'package:flutter/material.dart'; -class ColorName { - ColorName._(); +class MyColorName { + MyColorName._(); /// Color: #000000 static const Color black = Color(0xFF000000); diff --git a/example/lib/gen/fonts.gen.dart b/example/lib/gen/fonts.gen.dart index 9c088f07..e7fd2191 100644 --- a/example/lib/gen/fonts.gen.dart +++ b/example/lib/gen/fonts.gen.dart @@ -7,8 +7,8 @@ // ignore_for_file: type=lint // ignore_for_file: directives_ordering,unnecessary_import -class FontFamily { - FontFamily._(); +class MyFontFamily { + MyFontFamily._(); /// Font family: Raleway static const String raleway = 'Raleway'; diff --git a/example/lib/main.dart b/example/lib/main.dart index 327cf4c7..c9fe64ee 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,24 +1,22 @@ -import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; import 'package:example_resources/gen/assets.gen.dart' as res; +import 'package:flutter/material.dart'; -import 'firebase_options.dart'; import 'gen/assets.gen.dart'; import 'gen/colors.gen.dart'; import 'gen/fonts.gen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp( - options: DefaultFirebaseOptions.currentPlatform, - ); + // await Firebase.initializeApp( + // options: DefaultFirebaseOptions.currentPlatform, + // ); runApp(MaterialApp( title: 'Flutter Demo', theme: ThemeData( // Auto generated font from FlutterGen. - fontFamily: FontFamily.raleway, - primarySwatch: ColorName.crimsonRed, + fontFamily: MyFontFamily.raleway, + primarySwatch: MyColorName.crimsonRed, ), home: Scaffold( appBar: AppBar( @@ -33,7 +31,7 @@ void main() async { SizedBox( width: 200, height: 200, - child: Assets.flare.penguin.flare( + child: MyAssets.flare.penguin.flare( animation: 'walk', fit: BoxFit.contain, ), @@ -41,21 +39,21 @@ void main() async { SizedBox( width: 200, height: 200, - child: Assets.rive.vehicles.rive( + child: MyAssets.rive.vehicles.rive( fit: BoxFit.contain, ), ), - Assets.images.chip1.image(), + MyAssets.images.chip1.image(), // Use from example_resource package. res.Assets.images.flutter3.image(), res.Assets.images.dart.svg(), - Assets.images.icons.kmm.svg(key: const Key("kmm_svg")), - Assets.images.icons.fuchsia.svg(), - Assets.images.icons.paint.svg( + MyAssets.images.icons.kmm.svg(key: const Key("kmm_svg")), + MyAssets.images.icons.fuchsia.svg(), + MyAssets.images.icons.paint.svg( width: 120, height: 120, ), - // Assets.pictures.chip5.image( + // MyAssets.pictures.chip5.image( // key: const Key("chip5"), // width: 120, // height: 120, @@ -65,11 +63,11 @@ void main() async { 'Hi there, I\'m FlutterGen', style: TextStyle( // Auto generated color from FlutterGen. - color: ColorName.black60, + color: MyColorName.black60, // Auto generated font from FlutterGen. - fontFamily: FontFamily.robotoMono, - fontFamilyFallback: [FontFamily.raleway], + fontFamily: MyFontFamily.robotoMono, + fontFamilyFallback: [MyFontFamily.raleway], ), ), ], diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 95dfce1d..301034f6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: local_auth: 2.0.1 flutter_hooks: 0.18.3 hooks_riverpod: 1.0.3 - async: 2.8.2 + # async: 2.9.0 dio: 4.0.6 connectivity_plus: 2.3.0 ua_client_hints: 1.1.0 @@ -131,16 +131,24 @@ flutter_gen: # Assets.images.chip (default style) # style: dot-delimiter - exclude: + + outputs: + class_name: MyAssets + + exclude: - assets/images/chip3/chip3.jpg - pictures/chip5.jpg - assets/flare/ fonts: enabled: true + outputs: + class_name: MyFontFamily colors: enabled: true + outputs: + class_name: MyColorName inputs: - assets/color/colors.xml - assets/color/colors2.xml From 111e4fb9a9773814fdd417308e42de182c70ab43 Mon Sep 17 00:00:00 2001 From: wasabeef Date: Mon, 12 Sep 2022 18:03:47 +0900 Subject: [PATCH 3/4] refactor: change require to output param only pubspec.dart --- packages/core/lib/flutter_generator.dart | 7 ++-- .../core/lib/generators/assets_generator.dart | 14 ++++---- .../core/lib/generators/colors_generator.dart | 8 ++--- .../core/lib/generators/fonts_generator.dart | 8 ++--- packages/core/lib/settings/pubspec.dart | 32 +++++++++++-------- packages/core/lib/settings/pubspec.g.dart | 26 +++++++-------- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index 067b97ce..16b8daaa 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -76,11 +76,8 @@ class FlutterGenerator { } if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) { - final generated = generateFonts( - formatter, - flutter.fonts, - genFonts: flutterGen.fonts, - ); + final generated = + generateFonts(formatter, flutter.fonts, flutterGen.fonts); final fonts = File(normalize(join(pubspecFile.parent.path, output, fontsName))); writeAsString(generated, file: fonts); diff --git a/packages/core/lib/generators/assets_generator.dart b/packages/core/lib/generators/assets_generator.dart index accf25d1..aff8c2d6 100644 --- a/packages/core/lib/generators/assets_generator.dart +++ b/packages/core/lib/generators/assets_generator.dart @@ -213,7 +213,7 @@ String _dotDelimiterStyleDefinition( List integrations, ) { final buffer = StringBuffer(); - final className = config.flutterGen.assets.outputs?.className; + final className = config.flutterGen.assets.outputs.className; final assetRelativePathList = _getAssetRelativePathList( config.rootPath, config.assets, @@ -328,12 +328,12 @@ String _flatStyleDefinition( ) .whereType<_Statement>() .toList(); - final className = config.flutterGen.assets.outputs?.className; + final className = config.flutterGen.assets.outputs.className; return _flatStyleAssetsClassDefinition(className, statements); } String _flatStyleAssetsClassDefinition( - String? className, + String className, List<_Statement> statements, ) { final statementsBlock = @@ -344,7 +344,7 @@ String _flatStyleAssetsClassDefinition( } String _dotDelimiterStyleAssetsClassDefinition( - String? className, + String className, List<_Statement> statements, ) { final statementsBlock = @@ -352,10 +352,10 @@ String _dotDelimiterStyleAssetsClassDefinition( return _assetsClassDefinition(className, statementsBlock); } -String _assetsClassDefinition(String? className, String statementsBlock) { +String _assetsClassDefinition(String className, String statementsBlock) { return ''' -class ${className ?? 'Assets'} { - ${className ?? 'Assets'}._(); +class $className { + $className._(); $statementsBlock } diff --git a/packages/core/lib/generators/colors_generator.dart b/packages/core/lib/generators/colors_generator.dart index e421637f..db518b87 100644 --- a/packages/core/lib/generators/colors_generator.dart +++ b/packages/core/lib/generators/colors_generator.dart @@ -15,15 +15,15 @@ import 'generator_helper.dart'; String generateColors( File pubspecFile, DartFormatter formatter, - FlutterGenColors genColors, + FlutterGenColors colorsConfig, ) { - if (genColors.inputs.isEmpty) { + if (colorsConfig.inputs.isEmpty) { throw const InvalidSettingsException( 'The value of "flutter_gen/colors:" is incorrect.'); } final buffer = StringBuffer(); - final className = genColors.outputs?.className ?? 'ColorName'; + final className = colorsConfig.outputs.className; buffer.writeln(header); buffer.writeln(ignore); buffer.writeln("import 'package:flutter/painting.dart';"); @@ -34,7 +34,7 @@ String generateColors( buffer.writeln(); final colorList = <_Color>[]; - genColors.inputs + colorsConfig.inputs .map((file) => ColorPath(join(pubspecFile.parent.path, file))) .forEach((colorFile) { final data = colorFile.file.readAsStringSync(); diff --git a/packages/core/lib/generators/fonts_generator.dart b/packages/core/lib/generators/fonts_generator.dart index a67ccdd1..795e0408 100644 --- a/packages/core/lib/generators/fonts_generator.dart +++ b/packages/core/lib/generators/fonts_generator.dart @@ -10,16 +10,16 @@ import 'generator_helper.dart'; String generateFonts( DartFormatter formatter, - List fonts, { - FlutterGenFonts? genFonts, -}) { + List fonts, + FlutterGenFonts fontsConfig, +) { if (fonts.isEmpty) { throw InvalidSettingsException( 'The value of "flutter/fonts:" is incorrect.'); } final buffer = StringBuffer(); - final className = genFonts?.outputs?.className ?? 'FontFamily'; + final className = fontsConfig.outputs.className; buffer.writeln(header); buffer.writeln(ignore); buffer.writeln('class $className {'); diff --git a/packages/core/lib/settings/pubspec.dart b/packages/core/lib/settings/pubspec.dart index 5cb38a41..150b2b98 100644 --- a/packages/core/lib/settings/pubspec.dart +++ b/packages/core/lib/settings/pubspec.dart @@ -28,7 +28,10 @@ class Pubspec { @JsonSerializable() class Flutter { - Flutter({required this.assets, required this.fonts}); + Flutter({ + required this.assets, + required this.fonts, + }); @JsonKey(name: 'assets', required: true) final List assets; @@ -86,7 +89,7 @@ class FlutterGenColors { FlutterGenColors({ required this.enabled, required this.inputs, - this.outputs, + required this.outputs, }); @JsonKey(name: 'enabled', required: true) @@ -95,8 +98,8 @@ class FlutterGenColors { @JsonKey(name: 'inputs', required: true) final List inputs; - @JsonKey(name: 'outputs', required: false) - final FlutterGenElementOutputs? outputs; + @JsonKey(name: 'outputs', required: true) + final FlutterGenElementOutputs outputs; factory FlutterGenColors.fromJson(Map json) => _$FlutterGenColorsFromJson(json); @@ -112,7 +115,7 @@ class FlutterGenAssets { required this.enabled, required this.packageParameterEnabled, required this.style, - this.outputs, + required this.outputs, required this.exclude, }) { if (style != dotDelimiterStyle && @@ -131,8 +134,8 @@ class FlutterGenAssets { @JsonKey(name: 'style', required: true) final String style; - @JsonKey(name: 'outputs', required: false) - final FlutterGenElementOutputs? outputs; + @JsonKey(name: 'outputs', required: true) + final FlutterGenElementOutputs outputs; @JsonKey(name: 'exclude', required: true) final List exclude; @@ -149,13 +152,16 @@ class FlutterGenAssets { @JsonSerializable() class FlutterGenFonts { - FlutterGenFonts({required this.enabled, this.outputs}); + FlutterGenFonts({ + required this.enabled, + required this.outputs, + }); @JsonKey(name: 'enabled', required: true) final bool enabled; - @JsonKey(name: 'outputs', required: false) - final FlutterGenElementOutputs? outputs; + @JsonKey(name: 'outputs', required: true) + final FlutterGenElementOutputs outputs; factory FlutterGenFonts.fromJson(Map json) => _$FlutterGenFontsFromJson(json); } @@ -183,10 +189,10 @@ class FlutterGenIntegrations { @JsonSerializable() class FlutterGenElementOutputs { - FlutterGenElementOutputs({this.className}); + FlutterGenElementOutputs({required this.className}); - @JsonKey(name: 'class_name', required: false) - final String? className; + @JsonKey(name: 'class_name', required: true) + final String className; factory FlutterGenElementOutputs.fromJson(Map json) => _$FlutterGenElementOutputsFromJson(json); diff --git a/packages/core/lib/settings/pubspec.g.dart b/packages/core/lib/settings/pubspec.g.dart index 15d7b4a6..4b96a1e1 100644 --- a/packages/core/lib/settings/pubspec.g.dart +++ b/packages/core/lib/settings/pubspec.g.dart @@ -100,17 +100,14 @@ FlutterGenColors _$FlutterGenColorsFromJson(Map json) => $checkedCreate( ($checkedConvert) { $checkKeys( json, - requiredKeys: const ['enabled', 'inputs'], + requiredKeys: const ['enabled', 'inputs', 'outputs'], ); final val = FlutterGenColors( enabled: $checkedConvert('enabled', (v) => v as bool), inputs: $checkedConvert('inputs', (v) => (v as List).map((e) => e as String).toList()), outputs: $checkedConvert( - 'outputs', - (v) => v == null - ? null - : FlutterGenElementOutputs.fromJson(v as Map)), + 'outputs', (v) => FlutterGenElementOutputs.fromJson(v as Map)), ); return val; }, @@ -126,6 +123,7 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) => $checkedCreate( 'enabled', 'package_parameter_enabled', 'style', + 'outputs', 'exclude' ], ); @@ -135,10 +133,7 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) => $checkedCreate( $checkedConvert('package_parameter_enabled', (v) => v as bool), style: $checkedConvert('style', (v) => v as String), outputs: $checkedConvert( - 'outputs', - (v) => v == null - ? null - : FlutterGenElementOutputs.fromJson(v as Map)), + 'outputs', (v) => FlutterGenElementOutputs.fromJson(v as Map)), exclude: $checkedConvert('exclude', (v) => (v as List).map((e) => e as String).toList()), ); @@ -155,15 +150,12 @@ FlutterGenFonts _$FlutterGenFontsFromJson(Map json) => $checkedCreate( ($checkedConvert) { $checkKeys( json, - requiredKeys: const ['enabled'], + requiredKeys: const ['enabled', 'outputs'], ); final val = FlutterGenFonts( enabled: $checkedConvert('enabled', (v) => v as bool), outputs: $checkedConvert( - 'outputs', - (v) => v == null - ? null - : FlutterGenElementOutputs.fromJson(v as Map)), + 'outputs', (v) => FlutterGenElementOutputs.fromJson(v as Map)), ); return val; }, @@ -196,8 +188,12 @@ FlutterGenElementOutputs _$FlutterGenElementOutputsFromJson(Map json) => 'FlutterGenElementOutputs', json, ($checkedConvert) { + $checkKeys( + json, + requiredKeys: const ['class_name'], + ); final val = FlutterGenElementOutputs( - className: $checkedConvert('class_name', (v) => v as String?), + className: $checkedConvert('class_name', (v) => v as String), ); return val; }, From 8663a4069e64889fa342f583dee9aeb6f0a969d4 Mon Sep 17 00:00:00 2001 From: wasabeef Date: Mon, 12 Sep 2022 18:04:19 +0900 Subject: [PATCH 4/4] test: add test for change the class name --- packages/core/test/assets_gen_test.dart | 10 ++ packages/core/test/colors_gen_test.dart | 10 ++ packages/core/test/fonts_gen_test.dart | 13 ++- packages/core/test/gen_test_helper.dart | 14 ++- .../assets_change_class_name.gen.dart | 100 ++++++++++++++++++ .../colors_change_class_name.gen.dart | 96 +++++++++++++++++ .../fonts_change_class_name.gen.dart | 15 +++ .../pubspec_assets_change_class_name.yaml | 13 +++ .../pubspec_colors_change_class_name.yaml | 11 ++ .../pubspec_fonts_change_class_name.yaml | 18 ++++ 10 files changed, 294 insertions(+), 6 deletions(-) create mode 100644 packages/core/test_resources/actual_data/assets_change_class_name.gen.dart create mode 100644 packages/core/test_resources/actual_data/colors_change_class_name.gen.dart create mode 100644 packages/core/test_resources/actual_data/fonts_change_class_name.gen.dart create mode 100644 packages/core/test_resources/pubspec_assets_change_class_name.yaml create mode 100644 packages/core/test_resources/pubspec_colors_change_class_name.yaml create mode 100644 packages/core/test_resources/pubspec_fonts_change_class_name.yaml diff --git a/packages/core/test/assets_gen_test.dart b/packages/core/test/assets_gen_test.dart index f1a5055f..e8f1d16b 100644 --- a/packages/core/test/assets_gen_test.dart +++ b/packages/core/test/assets_gen_test.dart @@ -84,5 +84,15 @@ void main() { await expectedAssetsGen(pubspec, generated, fact); }); + + test('Assets with change the class name', () async { + const pubspec = 'test_resources/pubspec_assets_change_class_name.yaml'; + const fact = + 'test_resources/actual_data/assets_change_class_name.gen.dart'; + const generated = + 'test_resources/lib/gen/assets_change_class_name.gen.dart'; + + await expectedAssetsGen(pubspec, generated, fact); + }); }); } diff --git a/packages/core/test/colors_gen_test.dart b/packages/core/test/colors_gen_test.dart index c03bb5a9..966bcc90 100644 --- a/packages/core/test/colors_gen_test.dart +++ b/packages/core/test/colors_gen_test.dart @@ -53,5 +53,15 @@ void main() { ColorPath('test_resources/assets/json/fruits.json'); expect(wrongColorPath.isXml, isFalse); }); + + test('Change the class name', () async { + const pubspec = 'test_resources/pubspec_colors_change_class_name.yaml'; + const fact = + 'test_resources/actual_data/colors_change_class_name.gen.dart'; + const generated = + 'test_resources/lib/gen/colors_change_class_name.gen.dart'; + + await expectedColorsGen(pubspec, generated, fact); + }); }); } diff --git a/packages/core/test/fonts_gen_test.dart b/packages/core/test/fonts_gen_test.dart index c5bd9960..c37f8890 100644 --- a/packages/core/test/fonts_gen_test.dart +++ b/packages/core/test/fonts_gen_test.dart @@ -27,8 +27,19 @@ void main() { pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n'); expect(() { - return generateFonts(formatter, config.pubspec.flutter.fonts); + return generateFonts(formatter, config.pubspec.flutter.fonts, + config.pubspec.flutterGen.fonts); }, throwsA(isA())); }); + + test('Change the class name', () async { + const pubspec = 'test_resources/pubspec_fonts_change_class_name.yaml'; + const fact = + 'test_resources/actual_data/fonts_change_class_name.gen.dart'; + const generated = + 'test_resources/lib/gen/fonts_change_class_name.gen.dart'; + + await expectedFontsGen(pubspec, generated, fact); + }); }); } diff --git a/packages/core/test/gen_test_helper.dart b/packages/core/test/gen_test_helper.dart index ecdd137a..1396e6f6 100644 --- a/packages/core/test/gen_test_helper.dart +++ b/packages/core/test/gen_test_helper.dart @@ -38,7 +38,8 @@ Future expectedAssetsGen( /// Colors Future expectedColorsGen( String pubspec, String generated, String fact) async { - await FlutterGenerator(File(pubspec)).build(); + await FlutterGenerator(File(pubspec), colorsName: basename(generated)) + .build(); final pubspecFile = File(pubspec); final config = await loadPubspecConfig(pubspecFile); @@ -47,7 +48,8 @@ Future expectedColorsGen( final actual = generateColors(pubspecFile, formatter, config.pubspec.flutterGen.colors); - final expected = File(fact).readAsStringSync().replaceAll('\r\n', '\n'); + final expected = + formatter.format(File(fact).readAsStringSync().replaceAll('\r\n', '\n')); expect( File(generated).readAsStringSync(), @@ -59,15 +61,17 @@ Future expectedColorsGen( /// Fonts Future expectedFontsGen( String pubspec, String generated, String fact) async { - await FlutterGenerator(File(pubspec)).build(); + await FlutterGenerator(File(pubspec), fontsName: basename(generated)).build(); final pubspecFile = File(pubspec); final config = await loadPubspecConfig(pubspecFile); final formatter = DartFormatter( pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n'); - final actual = generateFonts(formatter, config.pubspec.flutter.fonts); - final expected = File(fact).readAsStringSync().replaceAll('\r\n', '\n'); + final actual = generateFonts( + formatter, config.pubspec.flutter.fonts, config.pubspec.flutterGen.fonts); + final expected = + formatter.format(File(fact).readAsStringSync().replaceAll('\r\n', '\n')); expect( File(generated).readAsStringSync(), diff --git a/packages/core/test_resources/actual_data/assets_change_class_name.gen.dart b/packages/core/test_resources/actual_data/assets_change_class_name.gen.dart new file mode 100644 index 00000000..f8f1b01a --- /dev/null +++ b/packages/core/test_resources/actual_data/assets_change_class_name.gen.dart @@ -0,0 +1,100 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import + +import 'package:flutter/widgets.dart'; + +class $AssetsImagesGen { + const $AssetsImagesGen(); + + /// File path: assets/images/chip1.jpg + AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg'); + + /// File path: assets/images/chip2.jpg + AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); + + /// File path: assets/images/logo.png + AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); + + /// File path: assets/images/profile.jpg + AssetGenImage get profileJpg => + const AssetGenImage('assets/images/profile.jpg'); + + /// File path: assets/images/profile.png + AssetGenImage get profilePng => + const AssetGenImage('assets/images/profile.png'); +} + +class MyAssets { + MyAssets._(); + + static const $AssetsImagesGen images = $AssetsImagesGen(); +} + +class AssetGenImage { + const AssetGenImage(this._assetName); + + final String _assetName; + + Image image({ + Key? key, + AssetBundle? bundle, + ImageFrameBuilder? frameBuilder, + ImageErrorWidgetBuilder? errorBuilder, + String? semanticLabel, + bool excludeFromSemantics = false, + double? scale, + double? width, + double? height, + Color? color, + Animation? opacity, + BlendMode? colorBlendMode, + BoxFit? fit, + AlignmentGeometry alignment = Alignment.center, + ImageRepeat repeat = ImageRepeat.noRepeat, + Rect? centerSlice, + bool matchTextDirection = false, + bool gaplessPlayback = false, + bool isAntiAlias = false, + String? package, + FilterQuality filterQuality = FilterQuality.low, + int? cacheWidth, + int? cacheHeight, + }) { + return Image.asset( + _assetName, + key: key, + bundle: bundle, + frameBuilder: frameBuilder, + errorBuilder: errorBuilder, + semanticLabel: semanticLabel, + excludeFromSemantics: excludeFromSemantics, + scale: scale, + width: width, + height: height, + color: color, + opacity: opacity, + colorBlendMode: colorBlendMode, + fit: fit, + alignment: alignment, + repeat: repeat, + centerSlice: centerSlice, + matchTextDirection: matchTextDirection, + gaplessPlayback: gaplessPlayback, + isAntiAlias: isAntiAlias, + package: package, + filterQuality: filterQuality, + cacheWidth: cacheWidth, + cacheHeight: cacheHeight, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} diff --git a/packages/core/test_resources/actual_data/colors_change_class_name.gen.dart b/packages/core/test_resources/actual_data/colors_change_class_name.gen.dart new file mode 100644 index 00000000..c47f7cae --- /dev/null +++ b/packages/core/test_resources/actual_data/colors_change_class_name.gen.dart @@ -0,0 +1,96 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import + +import 'package:flutter/painting.dart'; +import 'package:flutter/material.dart'; + +class MyColorName { + MyColorName._(); + + /// Color: #000000 + static const Color black = Color(0xFF000000); + + /// MaterialColor: + /// 50: #FFF9E5E5 + /// 100: #FFF1BFBF + /// 200: #FFE79595 + /// 300: #FFDD6A6A + /// 400: #FFD64A4A + /// 500: #FFCF2A2A + /// 600: #FFCA2525 + /// 700: #FFC31F1F + /// 800: #FFBD1919 + /// 900: #FFB20F0F + static const MaterialColor crimsonRed = MaterialColor( + 0xFFCF2A2A, + { + 50: Color(0xFFF9E5E5), + 100: Color(0xFFF1BFBF), + 200: Color(0xFFE79595), + 300: Color(0xFFDD6A6A), + 400: Color(0xFFD64A4A), + 500: Color(0xFFCF2A2A), + 600: Color(0xFFCA2525), + 700: Color(0xFFC31F1F), + 800: Color(0xFFBD1919), + 900: Color(0xFFB20F0F), + }, + ); + + /// Color: #979797 + static const Color gray410 = Color(0xFF979797); + + /// Color: #EEEEEE + static const Color gray70 = Color(0xFFEEEEEE); + + /// Color: #FFFFFF + static const Color white = Color(0xFFFFFFFF); + + /// MaterialColor: + /// 50: #FFFBF2E5 + /// 100: #FFF5DFBE + /// 200: #FFEFCA93 + /// 300: #FFE9B568 + /// 400: #FFE4A547 + /// 500: #FFDF9527 + /// 600: #FFDB8D23 + /// 700: #FFD7821D + /// 800: #FFD27817 + /// 900: #FFCA670E + static const MaterialColor yellowOcher = MaterialColor( + 0xFFDF9527, + { + 50: Color(0xFFFBF2E5), + 100: Color(0xFFF5DFBE), + 200: Color(0xFFEFCA93), + 300: Color(0xFFE9B568), + 400: Color(0xFFE4A547), + 500: Color(0xFFDF9527), + 600: Color(0xFFDB8D23), + 700: Color(0xFFD7821D), + 800: Color(0xFFD27817), + 900: Color(0xFFCA670E), + }, + ); + + /// MaterialAccentColor: + /// 100: #FFFFE8E0 + /// 200: #FFFFBCA3 + /// 400: #FFFFA989 + /// 700: #FFFF9E7A + static const MaterialAccentColor yellowOcherAccent = MaterialAccentColor( + 0xFFFFBCA3, + { + 100: Color(0xFFFFE8E0), + 200: Color(0xFFFFBCA3), + 400: Color(0xFFFFA989), + 700: Color(0xFFFF9E7A), + }, + ); +} diff --git a/packages/core/test_resources/actual_data/fonts_change_class_name.gen.dart b/packages/core/test_resources/actual_data/fonts_change_class_name.gen.dart new file mode 100644 index 00000000..d9606a9f --- /dev/null +++ b/packages/core/test_resources/actual_data/fonts_change_class_name.gen.dart @@ -0,0 +1,15 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import + +class MyFontFamily { + MyFontFamily._(); + + /// Font family: Raleway + static const String raleway = 'Raleway'; +} diff --git a/packages/core/test_resources/pubspec_assets_change_class_name.yaml b/packages/core/test_resources/pubspec_assets_change_class_name.yaml new file mode 100644 index 00000000..10b3c202 --- /dev/null +++ b/packages/core/test_resources/pubspec_assets_change_class_name.yaml @@ -0,0 +1,13 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + assets: + outputs: + class_name: MyAssets + +flutter: + assets: + - assets/images diff --git a/packages/core/test_resources/pubspec_colors_change_class_name.yaml b/packages/core/test_resources/pubspec_colors_change_class_name.yaml new file mode 100644 index 00000000..7f28947e --- /dev/null +++ b/packages/core/test_resources/pubspec_colors_change_class_name.yaml @@ -0,0 +1,11 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + colors: + outputs: + class_name: MyColorName + inputs: + - assets/color/colors.xml diff --git a/packages/core/test_resources/pubspec_fonts_change_class_name.yaml b/packages/core/test_resources/pubspec_fonts_change_class_name.yaml new file mode 100644 index 00000000..a19c1de1 --- /dev/null +++ b/packages/core/test_resources/pubspec_fonts_change_class_name.yaml @@ -0,0 +1,18 @@ +name: test + +flutter_gen: + output: lib/gen/ # Optional (default: lib/gen/) + line_length: 80 # Optional (default: 80) + + + fonts: + outputs: + class_name: MyFontFamily + +flutter: + fonts: + - family: Raleway + fonts: + - asset: assets/fonts/Raleway-Regular.ttf + - asset: assets/fonts/Raleway-Italic.ttf + style: italic