From 66a64b2bf1cfda98f2439187fec064cb737dc8f2 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 22 Oct 2024 22:10:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Better=20stdouts=20(#593)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What does this change? - Addresses https://github.com/FlutterGen/flutter_gen/pull/592#issuecomment-2424750703 - Make logs prettier ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) --- packages/command/bin/flutter_gen_command.dart | 5 +- .../test/flutter_gen_command_test.dart | 9 +- packages/core/lib/flutter_generator.dart | 8 +- packages/core/lib/settings/config.dart | 48 ++- packages/core/lib/utils/version.dart | 3 - packages/core/test/assets_gen_test.dart | 16 +- .../actual_data/build_assets.gen.dart | 24 +- .../actual_data/build_empty.gen.dart | 357 ++++++++++++++++++ .../actual_data/build_runner_assets.gen.dart | 357 ++++++++++++++++++ packages/core/test_resources/build_empty.yaml | 7 + .../test_resources/build_runner_assets.yaml | 3 + 11 files changed, 787 insertions(+), 50 deletions(-) delete mode 100644 packages/core/lib/utils/version.dart create mode 100644 packages/core/test_resources/actual_data/build_empty.gen.dart create mode 100644 packages/core/test_resources/actual_data/build_runner_assets.gen.dart create mode 100644 packages/core/test_resources/build_empty.yaml diff --git a/packages/command/bin/flutter_gen_command.dart b/packages/command/bin/flutter_gen_command.dart index 001e895a0..e334d3985 100644 --- a/packages/command/bin/flutter_gen_command.dart +++ b/packages/command/bin/flutter_gen_command.dart @@ -3,7 +3,8 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:flutter_gen_core/flutter_generator.dart'; import 'package:flutter_gen_core/utils/cast.dart'; -import 'package:flutter_gen_core/utils/version.dart'; +import 'package:flutter_gen_core/version.gen.dart'; + void main(List args) { final parser = ArgParser(); @@ -42,7 +43,7 @@ void main(List args) { stdout.writeln(parser.usage); return; } else if (results.wasParsed('version')) { - stdout.writeln(flutterGenVersion); + stdout.writeln('FlutterGen v$packageVersion'); return; } } on FormatException catch (e) { diff --git a/packages/command/test/flutter_gen_command_test.dart b/packages/command/test/flutter_gen_command_test.dart index 09cda450e..79faa9acd 100644 --- a/packages/command/test/flutter_gen_command_test.dart +++ b/packages/command/test/flutter_gen_command_test.dart @@ -1,9 +1,10 @@ import 'dart:io' show Platform; -import 'package:flutter_gen_core/utils/version.dart'; +import 'package:flutter_gen_core/version.gen.dart'; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; + final separator = Platform.pathSeparator; void main() { @@ -14,7 +15,7 @@ void main() { ); expect( await process.stdout.next, - equals('$flutterGenVersion Loading ...'), + equals('[FlutterGen] v$packageVersion Loading ...'), ); await process.shouldExit(0); }); @@ -26,7 +27,7 @@ void main() { ); expect( await process.stdout.next, - equals('$flutterGenVersion Loading ...'), + equals('[FlutterGen] v$packageVersion Loading ...'), ); await process.shouldExit(0); }); @@ -48,7 +49,7 @@ void main() { 'dart', ['bin/flutter_gen_command.dart', '--version'], ); - expect(await process.stdout.next, equals(flutterGenVersion)); + expect(await process.stdout.next, equals('[FlutterGen] v$packageVersion')); await process.shouldExit(0); }); diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index ab83b0ebf..d306e3333 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -55,7 +55,7 @@ class FlutterGenerator { final colorsPath = normalize(join(pubspecFile.parent.path, output, colorsName)); writer(generated, colorsPath); - stdout.writeln('Generated: $colorsPath'); + stdout.writeln('[FlutterGen] Generated: $colorsPath'); } if (flutterGen.assets.enabled && flutter.assets.isNotEmpty) { @@ -66,7 +66,7 @@ class FlutterGenerator { final assetsPath = normalize(join(pubspecFile.parent.path, output, assetsName)); writer(generated, assetsPath); - stdout.writeln('Generated: $assetsPath'); + stdout.writeln('[FlutterGen] Generated: $assetsPath'); } if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) { @@ -77,9 +77,9 @@ class FlutterGenerator { final fontsPath = normalize(join(pubspecFile.parent.path, output, fontsName)); writer(generated, fontsPath); - stdout.writeln('Generated: $fontsPath'); + stdout.writeln('[FlutterGen] Generated: $fontsPath'); } - stdout.writeln('FlutterGen finished.'); + stdout.writeln('[FlutterGen] Finished generating.'); } } diff --git a/packages/core/lib/settings/config.dart b/packages/core/lib/settings/config.dart index fb0f0ed6b..2a27482df 100644 --- a/packages/core/lib/settings/config.dart +++ b/packages/core/lib/settings/config.dart @@ -4,7 +4,7 @@ import 'package:flutter_gen_core/settings/config_default.dart'; import 'package:flutter_gen_core/settings/pubspec.dart'; import 'package:flutter_gen_core/utils/error.dart'; import 'package:flutter_gen_core/utils/map.dart'; -import 'package:flutter_gen_core/utils/version.dart'; +import 'package:flutter_gen_core/version.gen.dart'; import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; @@ -20,9 +20,7 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) { join(basename(pubspecFile.parent.path), basename(pubspecFile.path)), ); - stdout.writeln( - '$flutterGenVersion Loading ...', - ); + stdout.writeln('[FlutterGen] v$packageVersion Loading ...'); final defaultMap = loadYaml(configDefaultYamlContent) as Map?; @@ -31,23 +29,35 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) { var mergedMap = mergeMap([defaultMap, pubspecMap]); stdout.writeln( - 'Reading FlutterGen options from $pubspecLocaleHint', + '[FlutterGen] Reading options from $pubspecLocaleHint', ); - if (buildFile != null && buildFile.existsSync()) { - final buildContent = buildFile.readAsStringSync(); - final rawMap = loadYaml(buildContent) as Map?; - final builders = rawMap?['targets']?[r'$default']?['builders']; - final optionBuildMap = (builders?['flutter_gen_runner'] ?? - builders?['flutter_gen'])?['options']; - if (optionBuildMap is YamlMap) { - final buildMap = {'flutter_gen': optionBuildMap}; - mergedMap = mergeMap([mergedMap, buildMap]); - final buildLocaleHint = normalize( - join(basename(buildFile.parent.path), basename(buildFile.path)), - ); - stdout.writeln( - 'Reading FlutterGen options from $buildLocaleHint', + if (buildFile != null) { + if (buildFile.existsSync()) { + final buildContent = buildFile.readAsStringSync(); + final rawMap = loadYaml(buildContent) as Map?; + final builders = rawMap?['targets']?[r'$default']?['builders']; + final optionBuildMap = (builders?['flutter_gen_runner'] ?? + builders?['flutter_gen'])?['options']; + if (optionBuildMap is YamlMap && optionBuildMap.isNotEmpty) { + final buildMap = {'flutter_gen': optionBuildMap}; + mergedMap = mergeMap([mergedMap, buildMap]); + final buildLocaleHint = normalize( + join(basename(buildFile.parent.path), basename(buildFile.path)), + ); + stdout.writeln( + '[FlutterGen] Reading options from $buildLocaleHint', + ); + } else { + stderr.writeln( + '[FlutterGen] Specified ${buildFile.path} as input but the file ' + 'does not contain valid options, ignoring...', + ); + } + } else { + stderr.writeln( + '[FlutterGen] Specified ${buildFile.path} as input but the file ' + 'does not exists.', ); } } diff --git a/packages/core/lib/utils/version.dart b/packages/core/lib/utils/version.dart deleted file mode 100644 index f6223aa89..000000000 --- a/packages/core/lib/utils/version.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:flutter_gen_core/version.gen.dart'; - -String flutterGenVersion = 'FlutterGen v$packageVersion'; diff --git a/packages/core/test/assets_gen_test.dart b/packages/core/test/assets_gen_test.dart index 5d69a8909..79e795fc6 100644 --- a/packages/core/test/assets_gen_test.dart +++ b/packages/core/test/assets_gen_test.dart @@ -230,8 +230,20 @@ void main() { 'Assets on pubspec_assets.yaml and override with build_runner_assets.yaml ', () async { const pubspec = 'test_resources/pubspec_assets.yaml'; - const build = 'test_resources/build_runnfer_assets.yaml'; - const fact = 'test_resources/actual_data/build_assets.gen.dart'; + const build = 'test_resources/build_runner_assets.yaml'; + const fact = 'test_resources/actual_data/build_runner_assets.gen.dart'; + const generated = 'test_resources/lib/build_gen/assets.gen.dart'; + + await expectedAssetsGen(pubspec, generated, fact, build: build); + }, + ); + + test( + 'Assets on pubspec_assets.yaml and override with build_empty.yaml ', + () async { + const pubspec = 'test_resources/pubspec_assets.yaml'; + const build = 'test_resources/build_empty.yaml'; + const fact = 'test_resources/actual_data/build_empty.gen.dart'; const generated = 'test_resources/lib/build_gen/assets.gen.dart'; await expectedAssetsGen(pubspec, generated, fact, build: build); diff --git a/packages/core/test_resources/actual_data/build_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets.gen.dart index 482e6044f..09e91354d 100644 --- a/packages/core/test_resources/actual_data/build_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets.gen.dart @@ -56,16 +56,13 @@ class $AssetsImagesGen { AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); /// File path: assets/images/profile.jpg - AssetGenImage get profileJpg => - const AssetGenImage('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'); + AssetGenImage get profilePng => const AssetGenImage('assets/images/profile.png'); /// List of all assets - List get values => - [chip1, chip2, logo, profileJpg, profilePng]; + List get values => [chip1, chip2, logo, profileJpg, profilePng]; } class $AssetsJsonGen { @@ -105,8 +102,7 @@ class $AssetsImagesChip3Gen { const $AssetsImagesChip3Gen(); /// File path: assets/images/chip3/chip3.jpg - AssetGenImage get chip3 => - const AssetGenImage('assets/images/chip3/chip3.jpg'); + AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); /// List of all assets List get values => [chip3]; @@ -116,8 +112,7 @@ class $AssetsImagesChip4Gen { const $AssetsImagesChip4Gen(); /// File path: assets/images/chip4/chip4.jpg - AssetGenImage get chip4 => - const AssetGenImage('assets/images/chip4/chip4.jpg'); + AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); /// List of all assets List get values => [chip4]; @@ -127,12 +122,10 @@ class $AssetsImagesIconsGen { const $AssetsImagesIconsGen(); /// File path: assets/images/icons/dart@test.svg - SvgGenImage get dartTest => - const SvgGenImage('assets/images/icons/dart@test.svg'); + SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); /// File path: assets/images/icons/fuchsia.svg - SvgGenImage get fuchsia => - const SvgGenImage('assets/images/icons/fuchsia.svg'); + SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); /// File path: assets/images/icons/kmm.svg SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); @@ -305,8 +298,7 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? - (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, ); diff --git a/packages/core/test_resources/actual_data/build_empty.gen.dart b/packages/core/test_resources/actual_data/build_empty.gen.dart new file mode 100644 index 000000000..09e91354d --- /dev/null +++ b/packages/core/test_resources/actual_data/build_empty.gen.dart @@ -0,0 +1,357 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +import 'package:flare_flutter/flare_actor.dart' as _flare_actor; +import 'package:flare_flutter/flare_controller.dart' as _flare_controller; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_svg/flutter_svg.dart' as _svg; +import 'package:vector_graphics/vector_graphics.dart' as _vg; + +class $PicturesGen { + const $PicturesGen(); + + /// File path: pictures/chip5.jpg + AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg'); + + /// List of all assets + List get values => [chip5]; +} + +class $AssetsFlareGen { + const $AssetsFlareGen(); + + /// File path: assets/flare/Penguin.flr + FlareGenImage get penguin => const FlareGenImage('assets/flare/Penguin.flr'); + + /// List of all assets + List get values => [penguin]; +} + +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'); + + /// Directory path: assets/images/chip3 + $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); + + /// Directory path: assets/images/chip4 + $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); + + /// Directory path: assets/images/icons + $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); + + /// 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'); + + /// List of all assets + List get values => [chip1, chip2, logo, profileJpg, profilePng]; +} + +class $AssetsJsonGen { + const $AssetsJsonGen(); + + /// File path: assets/json/list.json + String get list => 'assets/json/list.json'; + + /// File path: assets/json/map.json + String get map => 'assets/json/map.json'; + + /// List of all assets + List get values => [list, map]; +} + +class $AssetsMovieGen { + const $AssetsMovieGen(); + + /// File path: assets/movie/the_earth.mp4 + String get theEarth => 'assets/movie/the_earth.mp4'; + + /// List of all assets + List get values => [theEarth]; +} + +class $AssetsUnknownGen { + const $AssetsUnknownGen(); + + /// File path: assets/unknown/unknown_mime_type.bk + String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk'; + + /// List of all assets + List get values => [unknownMimeType]; +} + +class $AssetsImagesChip3Gen { + const $AssetsImagesChip3Gen(); + + /// File path: assets/images/chip3/chip3.jpg + AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); + + /// List of all assets + List get values => [chip3]; +} + +class $AssetsImagesChip4Gen { + const $AssetsImagesChip4Gen(); + + /// File path: assets/images/chip4/chip4.jpg + AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); + + /// List of all assets + List get values => [chip4]; +} + +class $AssetsImagesIconsGen { + const $AssetsImagesIconsGen(); + + /// File path: assets/images/icons/dart@test.svg + SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); + + /// File path: assets/images/icons/fuchsia.svg + SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); + + /// File path: assets/images/icons/kmm.svg + SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); + + /// File path: assets/images/icons/paint.svg + SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg'); + + /// List of all assets + List get values => [dartTest, fuchsia, kmm, paint]; +} + +class Assets { + Assets._(); + + static const String changelog = 'CHANGELOG.md'; + static const $AssetsFlareGen flare = $AssetsFlareGen(); + static const $AssetsImagesGen images = $AssetsImagesGen(); + static const $AssetsJsonGen json = $AssetsJsonGen(); + static const $AssetsMovieGen movie = $AssetsMovieGen(); + static const $AssetsUnknownGen unknown = $AssetsUnknownGen(); + static const $PicturesGen pictures = $PicturesGen(); + + /// List of all assets + static List get values => [changelog]; +} + +class AssetGenImage { + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }); + + final String _assetName; + + final Size? size; + final Set flavors; + + 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 = true, + 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, + ); + } + + ImageProvider provider({ + AssetBundle? bundle, + String? package, + }) { + return AssetImage( + _assetName, + bundle: bundle, + package: package, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class SvgGenImage { + const SvgGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = false; + + const SvgGenImage.vec( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = true; + + final String _assetName; + final Size? size; + final Set flavors; + final bool _isVecFormat; + + _svg.SvgPicture svg({ + Key? key, + bool matchTextDirection = false, + AssetBundle? bundle, + String? package, + double? width, + double? height, + BoxFit fit = BoxFit.contain, + AlignmentGeometry alignment = Alignment.center, + bool allowDrawingOutsideViewBox = false, + WidgetBuilder? placeholderBuilder, + String? semanticsLabel, + bool excludeFromSemantics = false, + _svg.SvgTheme? theme, + ColorFilter? colorFilter, + Clip clipBehavior = Clip.hardEdge, + @deprecated Color? color, + @deprecated BlendMode colorBlendMode = BlendMode.srcIn, + @deprecated bool cacheColorFilter = false, + }) { + final _svg.BytesLoader loader; + if (_isVecFormat) { + loader = _vg.AssetBytesLoader( + _assetName, + assetBundle: bundle, + packageName: package, + ); + } else { + loader = _svg.SvgAssetLoader( + _assetName, + assetBundle: bundle, + packageName: package, + theme: theme, + ); + } + return _svg.SvgPicture( + loader, + key: key, + matchTextDirection: matchTextDirection, + width: width, + height: height, + fit: fit, + alignment: alignment, + allowDrawingOutsideViewBox: allowDrawingOutsideViewBox, + placeholderBuilder: placeholderBuilder, + semanticsLabel: semanticsLabel, + excludeFromSemantics: excludeFromSemantics, + colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + clipBehavior: clipBehavior, + cacheColorFilter: cacheColorFilter, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class FlareGenImage { + const FlareGenImage( + this._assetName, { + this.flavors = const {}, + }); + + final String _assetName; + final Set flavors; + + _flare_actor.FlareActor flare({ + String? boundsNode, + String? animation, + BoxFit fit = BoxFit.contain, + Alignment alignment = Alignment.center, + bool isPaused = false, + bool snapToEnd = false, + _flare_controller.FlareController? controller, + _flare_actor.FlareCompletedCallback? callback, + Color? color, + bool shouldClip = true, + bool sizeFromArtboard = false, + String? artboard, + bool antialias = true, + }) { + return _flare_actor.FlareActor( + _assetName, + boundsNode: boundsNode, + animation: animation, + fit: fit, + alignment: alignment, + isPaused: isPaused, + snapToEnd: snapToEnd, + controller: controller, + callback: callback, + color: color, + shouldClip: shouldClip, + sizeFromArtboard: sizeFromArtboard, + artboard: artboard, + antialias: antialias, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} diff --git a/packages/core/test_resources/actual_data/build_runner_assets.gen.dart b/packages/core/test_resources/actual_data/build_runner_assets.gen.dart new file mode 100644 index 000000000..ce52a2181 --- /dev/null +++ b/packages/core/test_resources/actual_data/build_runner_assets.gen.dart @@ -0,0 +1,357 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +import 'package:flare_flutter/flare_actor.dart' as _flare_actor; +import 'package:flare_flutter/flare_controller.dart' as _flare_controller; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_svg/flutter_svg.dart' as _svg; +import 'package:vector_graphics/vector_graphics.dart' as _vg; + +class $PicturesGen { + const $PicturesGen(); + + /// File path: pictures/chip5.jpg + AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg'); + + /// List of all assets + List get values => [chip5]; +} + +class $AssetsFlareGen { + const $AssetsFlareGen(); + + /// File path: assets/flare/Penguin.flr + FlareGenImage get penguin => const FlareGenImage('assets/flare/Penguin.flr'); + + /// List of all assets + List get values => [penguin]; +} + +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'); + + /// Directory path: assets/images/chip3 + $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); + + /// Directory path: assets/images/chip4 + $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); + + /// Directory path: assets/images/icons + $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); + + /// 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'); + + /// List of all assets + List get values => [chip1, chip2, logo, profileJpg, profilePng]; +} + +class $AssetsJsonGen { + const $AssetsJsonGen(); + + /// File path: assets/json/list.json + String get list => 'assets/json/list.json'; + + /// File path: assets/json/map.json + String get map => 'assets/json/map.json'; + + /// List of all assets + List get values => [list, map]; +} + +class $AssetsMovieGen { + const $AssetsMovieGen(); + + /// File path: assets/movie/the_earth.mp4 + String get theEarth => 'assets/movie/the_earth.mp4'; + + /// List of all assets + List get values => [theEarth]; +} + +class $AssetsUnknownGen { + const $AssetsUnknownGen(); + + /// File path: assets/unknown/unknown_mime_type.bk + String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk'; + + /// List of all assets + List get values => [unknownMimeType]; +} + +class $AssetsImagesChip3Gen { + const $AssetsImagesChip3Gen(); + + /// File path: assets/images/chip3/chip3.jpg + AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg'); + + /// List of all assets + List get values => [chip3]; +} + +class $AssetsImagesChip4Gen { + const $AssetsImagesChip4Gen(); + + /// File path: assets/images/chip4/chip4.jpg + AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg'); + + /// List of all assets + List get values => [chip4]; +} + +class $AssetsImagesIconsGen { + const $AssetsImagesIconsGen(); + + /// File path: assets/images/icons/dart@test.svg + SvgGenImage get dartTest => const SvgGenImage('assets/images/icons/dart@test.svg'); + + /// File path: assets/images/icons/fuchsia.svg + SvgGenImage get fuchsia => const SvgGenImage('assets/images/icons/fuchsia.svg'); + + /// File path: assets/images/icons/kmm.svg + SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg'); + + /// File path: assets/images/icons/paint.svg + SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg'); + + /// List of all assets + List get values => [dartTest, fuchsia, kmm, paint]; +} + +class BuildAssets { + BuildAssets._(); + + static const String changelog = 'CHANGELOG.md'; + static const $AssetsFlareGen flare = $AssetsFlareGen(); + static const $AssetsImagesGen images = $AssetsImagesGen(); + static const $AssetsJsonGen json = $AssetsJsonGen(); + static const $AssetsMovieGen movie = $AssetsMovieGen(); + static const $AssetsUnknownGen unknown = $AssetsUnknownGen(); + static const $PicturesGen pictures = $PicturesGen(); + + /// List of all assets + static List get values => [changelog]; +} + +class AssetGenImage { + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }); + + final String _assetName; + + final Size? size; + final Set flavors; + + 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 = true, + 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, + ); + } + + ImageProvider provider({ + AssetBundle? bundle, + String? package, + }) { + return AssetImage( + _assetName, + bundle: bundle, + package: package, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class SvgGenImage { + const SvgGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = false; + + const SvgGenImage.vec( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = true; + + final String _assetName; + final Size? size; + final Set flavors; + final bool _isVecFormat; + + _svg.SvgPicture svg({ + Key? key, + bool matchTextDirection = false, + AssetBundle? bundle, + String? package, + double? width, + double? height, + BoxFit fit = BoxFit.contain, + AlignmentGeometry alignment = Alignment.center, + bool allowDrawingOutsideViewBox = false, + WidgetBuilder? placeholderBuilder, + String? semanticsLabel, + bool excludeFromSemantics = false, + _svg.SvgTheme? theme, + ColorFilter? colorFilter, + Clip clipBehavior = Clip.hardEdge, + @deprecated Color? color, + @deprecated BlendMode colorBlendMode = BlendMode.srcIn, + @deprecated bool cacheColorFilter = false, + }) { + final _svg.BytesLoader loader; + if (_isVecFormat) { + loader = _vg.AssetBytesLoader( + _assetName, + assetBundle: bundle, + packageName: package, + ); + } else { + loader = _svg.SvgAssetLoader( + _assetName, + assetBundle: bundle, + packageName: package, + theme: theme, + ); + } + return _svg.SvgPicture( + loader, + key: key, + matchTextDirection: matchTextDirection, + width: width, + height: height, + fit: fit, + alignment: alignment, + allowDrawingOutsideViewBox: allowDrawingOutsideViewBox, + placeholderBuilder: placeholderBuilder, + semanticsLabel: semanticsLabel, + excludeFromSemantics: excludeFromSemantics, + colorFilter: colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), + clipBehavior: clipBehavior, + cacheColorFilter: cacheColorFilter, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class FlareGenImage { + const FlareGenImage( + this._assetName, { + this.flavors = const {}, + }); + + final String _assetName; + final Set flavors; + + _flare_actor.FlareActor flare({ + String? boundsNode, + String? animation, + BoxFit fit = BoxFit.contain, + Alignment alignment = Alignment.center, + bool isPaused = false, + bool snapToEnd = false, + _flare_controller.FlareController? controller, + _flare_actor.FlareCompletedCallback? callback, + Color? color, + bool shouldClip = true, + bool sizeFromArtboard = false, + String? artboard, + bool antialias = true, + }) { + return _flare_actor.FlareActor( + _assetName, + boundsNode: boundsNode, + animation: animation, + fit: fit, + alignment: alignment, + isPaused: isPaused, + snapToEnd: snapToEnd, + controller: controller, + callback: callback, + color: color, + shouldClip: shouldClip, + sizeFromArtboard: sizeFromArtboard, + artboard: artboard, + antialias: antialias, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} diff --git a/packages/core/test_resources/build_empty.yaml b/packages/core/test_resources/build_empty.yaml new file mode 100644 index 000000000..2e504cabe --- /dev/null +++ b/packages/core/test_resources/build_empty.yaml @@ -0,0 +1,7 @@ +name: test + +targets: + $default: + builders: + flutter_gen_runner: + options: diff --git a/packages/core/test_resources/build_runner_assets.yaml b/packages/core/test_resources/build_runner_assets.yaml index e5e293104..451ab058a 100644 --- a/packages/core/test_resources/build_runner_assets.yaml +++ b/packages/core/test_resources/build_runner_assets.yaml @@ -7,3 +7,6 @@ targets: options: output: lib/build_gen/ line_length: 120 + assets: + outputs: + class_name: BuildAssets