From 18e28d4cdc3fe18b964150b1ef52f8e47f235909 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 16 Dec 2024 11:44:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Format=20Dart=20files?= =?UTF-8?q?=20with=20the=20current=20Dart=20version=20instead=20of=20the?= =?UTF-8?q?=20latest=20supported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/lib/flutter_generator.dart | 3 ++- packages/core/test/assets_gen_test.dart | 2 +- packages/core/test/colors_gen_test.dart | 4 ++-- packages/core/test/fonts_gen_test.dart | 2 +- packages/core/test/gen_test_helper.dart | 9 ++++++--- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index 2fb0326ad..9cd22d3e6 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -7,6 +7,7 @@ import 'package:flutter_gen_core/generators/fonts_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:flutter_gen_core/utils/file.dart'; import 'package:path/path.dart'; +import 'package:pub_semver/pub_semver.dart'; class FlutterGenerator { const FlutterGenerator( @@ -32,7 +33,7 @@ class FlutterGenerator { final output = config.pubspec.flutterGen.output; final lineLength = config.pubspec.flutterGen.lineLength; final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: Version.parse(Platform.version.split(' ').first), pageWidth: lineLength, lineEnding: '\n', ); diff --git a/packages/core/test/assets_gen_test.dart b/packages/core/test/assets_gen_test.dart index 59fac2b60..a2b51d119 100644 --- a/packages/core/test/assets_gen_test.dart +++ b/packages/core/test/assets_gen_test.dart @@ -60,7 +60,7 @@ void main() { final pubspec = File('test_resources/pubspec_assets_no_list.yaml'); final config = loadPubspecConfig(pubspec); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); diff --git a/packages/core/test/colors_gen_test.dart b/packages/core/test/colors_gen_test.dart index 95fca2d5c..1d9357bb3 100644 --- a/packages/core/test/colors_gen_test.dart +++ b/packages/core/test/colors_gen_test.dart @@ -23,7 +23,7 @@ void main() { final pubspec = File('test_resources/pubspec_colors_no_inputs.yaml'); final config = loadPubspecConfig(pubspec); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); @@ -38,7 +38,7 @@ void main() { final pubspec = File('test_resources/pubspec_colors_no_inputs_list.yaml'); final config = loadPubspecConfig(pubspec); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); diff --git a/packages/core/test/fonts_gen_test.dart b/packages/core/test/fonts_gen_test.dart index 90c7f85de..e13ed5ea1 100644 --- a/packages/core/test/fonts_gen_test.dart +++ b/packages/core/test/fonts_gen_test.dart @@ -23,7 +23,7 @@ void main() { File('test_resources/pubspec_fonts_no_family.yaml'), ); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); diff --git a/packages/core/test/gen_test_helper.dart b/packages/core/test/gen_test_helper.dart index d47e52096..2b3060711 100644 --- a/packages/core/test/gen_test_helper.dart +++ b/packages/core/test/gen_test_helper.dart @@ -7,8 +7,11 @@ import 'package:flutter_gen_core/generators/colors_generator.dart'; import 'package:flutter_gen_core/generators/fonts_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:path/path.dart' as p; +import 'package:pub_semver/pub_semver.dart' show Version; import 'package:test/test.dart'; +final currentDartVersion = Version.parse(Platform.version.split(' ').first); + Future clearTestResults() async {} Future> runAssetsGen( @@ -32,7 +35,7 @@ Future> runAssetsGen( stdout.writeln('[DEBUG] test: Generate from API...'); final config = loadPubspecConfig(pubspecFile, buildFile: buildFile); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); @@ -76,7 +79,7 @@ Future> runColorsGen( final pubspecFile = File(pubspec); final config = loadPubspecConfig(pubspecFile); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); @@ -120,7 +123,7 @@ Future> runFontsGen( final pubspecFile = File(pubspec); final config = loadPubspecConfig(pubspecFile); final formatter = DartFormatter( - languageVersion: DartFormatter.latestLanguageVersion, + languageVersion: currentDartVersion, pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', ); From 22112eda2bbfe5893c03ad1c15e7a0a8b7b72c1c Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 16 Dec 2024 11:44:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Format=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/example/lib/main.dart | 201 +++++++++++---------- packages/core/lib/settings/asset_type.dart | 41 ++--- 2 files changed, 118 insertions(+), 124 deletions(-) diff --git a/examples/example/lib/main.dart b/examples/example/lib/main.dart index ba105f511..9861eb2c7 100644 --- a/examples/example/lib/main.dart +++ b/examples/example/lib/main.dart @@ -4,121 +4,122 @@ import 'package:example/gen/fonts.gen.dart'; import 'package:example_resources/gen/assets.gen.dart'; import 'package:flutter/material.dart'; -void main() async { - WidgetsFlutterBinding.ensureInitialized(); - // await Firebase.initializeApp( - // options: DefaultFirebaseOptions.currentPlatform, - // ); - - // flavors sample - // output: {'extern'} +void main() { print(MyAssets.images.chip4.chip4.flavors); + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); - runApp(MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // Auto generated font from FlutterGen. - fontFamily: MyFontFamily.raleway, - primarySwatch: MyColorName.crimsonRed, - ), - home: Scaffold( - appBar: AppBar( - title: const Text('FlutterGen'), + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + // Auto generated font from FlutterGen. + fontFamily: MyFontFamily.raleway, + primarySwatch: MyColorName.crimsonRed, ), - body: Center( - child: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // Auto generated image from FlutterGen. - SizedBox( - width: 200, - height: 200, - child: MyAssets.rive.vehicles.rive( - fit: BoxFit.contain, + home: Scaffold( + appBar: AppBar( + title: const Text('FlutterGen'), + ), + body: Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // Auto generated image from FlutterGen. + SizedBox( + width: 200, + height: 200, + child: MyAssets.rive.vehicles.rive( + fit: BoxFit.contain, + ), ), - ), - SizedBox( - width: 200, - height: 200, - child: MyAssets.lottie.hamburgerArrow.lottie( - fit: BoxFit.contain, + SizedBox( + width: 200, + height: 200, + child: MyAssets.lottie.hamburgerArrow.lottie( + fit: BoxFit.contain, + ), ), - ), - SizedBox( - width: 200, - height: 200, - child: MyAssets.lottie.geometricalAnimation.lottie( - fit: BoxFit.contain, + SizedBox( + width: 200, + height: 200, + child: MyAssets.lottie.geometricalAnimation.lottie( + fit: BoxFit.contain, + ), ), - ), - SizedBox( - width: 200, - height: 200, - child: MyAssets.lottie.alarmClockLottieV440.lottie( - fit: BoxFit.contain, + SizedBox( + width: 200, + height: 200, + child: MyAssets.lottie.alarmClockLottieV440.lottie( + fit: BoxFit.contain, + ), ), - ), - MyAssets.images.chip1.image(), - Container( - height: 400, - decoration: BoxDecoration( - image: DecorationImage( - image: MyAssets.images.chip1.provider(), + MyAssets.images.chip1.image(), + Container( + height: 400, + decoration: BoxDecoration( + image: DecorationImage( + image: MyAssets.images.chip1.provider(), + ), ), + child: const Center(child: Text('Deco')), + ), + // Use from example_resource package. + MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')), + MyAssets.images.icons.fuchsia.svg(), + MyAssets.images.icons.paint.svg( + width: 120, + height: 120, ), - child: const Center(child: Text('Deco')), - ), - // Use from example_resource package. - MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')), - MyAssets.images.icons.fuchsia.svg(), - MyAssets.images.icons.paint.svg( - width: 120, - height: 120, - ), - // MyAssets.pictures.chip5.image( - // key: const Key("chip5"), - // width: 120, - // height: 120, - // fit: BoxFit.scaleDown, - // ), + // MyAssets.pictures.chip5.image( + // key: const Key("chip5"), + // width: 120, + // height: 120, + // fit: BoxFit.scaleDown, + // ), - // example_resource package. - Text(MyAssets.images.icons.kmm.path), - Text(MyAssets.images.icons.kmm.keyName), - Text(ResAssets.images.dart.path), - Text(ResAssets.images.dart.keyName), - ResAssets.images.flutter3.image(), - ResAssets.images.dart.svg(), - SizedBox( - width: 200, - height: 200, - child: ResAssets.images.skills.rive( - fit: BoxFit.contain, + // example_resource package. + Text(MyAssets.images.icons.kmm.path), + Text(MyAssets.images.icons.kmm.keyName), + Text(ResAssets.images.dart.path), + Text(ResAssets.images.dart.keyName), + ResAssets.images.flutter3.image(), + ResAssets.images.dart.svg(), + SizedBox( + width: 200, + height: 200, + child: ResAssets.images.skills.rive( + fit: BoxFit.contain, + ), ), - ), - SizedBox( - width: 200, - height: 200, - child: ResAssets.images.runningCarOnRoad.lottie( - fit: BoxFit.contain, + SizedBox( + width: 200, + height: 200, + child: ResAssets.images.runningCarOnRoad.lottie( + fit: BoxFit.contain, + ), ), - ), - const Text( - 'Hi there, I\'m FlutterGen', - style: TextStyle( - // Auto generated color from FlutterGen. - color: MyColorName.black60, + const Text( + 'Hi there, I\'m FlutterGen', + style: TextStyle( + // Auto generated color from FlutterGen. + color: MyColorName.black60, - // Auto generated font from FlutterGen. - fontFamily: MyFontFamily.robotoMono, - fontFamilyFallback: [MyFontFamily.raleway], + // Auto generated font from FlutterGen. + fontFamily: MyFontFamily.robotoMono, + fontFamilyFallback: [MyFontFamily.raleway], + ), ), - ), - ], + ], + ), ), ), ), - ), - )); + ); + } } diff --git a/packages/core/lib/settings/asset_type.dart b/packages/core/lib/settings/asset_type.dart index d058a11da..0a4e316ff 100644 --- a/packages/core/lib/settings/asset_type.dart +++ b/packages/core/lib/settings/asset_type.dart @@ -17,42 +17,35 @@ class AssetType { final Set flavors; final List _children = List.empty(growable: true); + late final children = _children.sortedBy((e) => e.path); - bool get isDefaultAssetsDirectory => path == 'assets' || path == 'asset'; + late final isDefaultAssetsDirectory = path == 'assets' || path == 'asset'; + late final mime = lookupMimeType(path); + late final isUnKnownMime = mime == null; - String? get mime => lookupMimeType(path); + /// Returns a name for this asset. + late final name = p.withoutExtension(path); + late final baseName = p.basenameWithoutExtension(path); + late final extension = p.extension(path); + + /// Returns the full absolute path for reading the asset file. + late final fullPath = p.join(rootPath, path); + + // Replace to Posix style for Windows separator. + late final posixStylePath = path.replaceAll(r'\', r'/'); - bool get isIgnoreFile { + late final bool isIgnoreFile = () { switch (baseName) { case '.DS_Store': return true; } - switch (extension) { case '.DS_Store': case '.swp': return true; } - return false; - } - - bool get isUnKnownMime => mime == null; - - /// Returns a name for this asset. - String get name => p.withoutExtension(path); - - String get baseName => p.basenameWithoutExtension(path); - - String get extension => p.extension(path); - - /// Returns the full absolute path for reading the asset file. - String get fullPath => p.join(rootPath, path); - - // Replace to Posix style for Windows separator. - String get posixStylePath => path.replaceAll(r'\', r'/'); - - List get children => _children.sortedBy((e) => e.path); + }(); void addChild(AssetType type) { _children.add(type); @@ -125,7 +118,7 @@ class UniqueAssetType extends AssetType { } extension AssetTypeIterable on Iterable { - /// Takes a Iterable and mutates the AssetType's to ensure each + /// Takes a `Iterable` and mutates the AssetType's to ensure each /// AssetType has a unique name. /// /// The strategy is as follows: From dace76512acb27b15fac0fdb6506922300e7b600 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 16 Dec 2024 11:52:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20--?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analysis_options.yaml | 2 +- melos.yaml | 12 ++++-------- packages/core/lib/flutter_generator.dart | 8 ++++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 2d2d27e06..45b67cfcf 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -13,7 +13,7 @@ analyzer: linter: rules: - always_use_package_imports: true + # always_use_package_imports: true avoid_equals_and_hash_code_on_mutable_classes: true avoid_classes_with_only_static_members: true directives_ordering: true diff --git a/melos.yaml b/melos.yaml index 98650bb4a..5e1644944 100644 --- a/melos.yaml +++ b/melos.yaml @@ -20,17 +20,13 @@ command: description: flutter clean scripts: - get: - run: flutter pub get - exec: - concurrency: 1 - description: flutter pub get - upgrade: - run: flutter pub upgrade + run: dart pub upgrade exec: concurrency: 1 - description: flutter pub upgrade + packageFilters: + flutter: false + description: dart pub upgrade analyze: exec: flutter analyze diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index 9cd22d3e6..33c6af26a 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -1,13 +1,13 @@ -import 'dart:io'; +import 'dart:io' show stdout, Directory, File, Platform; -import 'package:dart_style/dart_style.dart'; +import 'package:dart_style/dart_style.dart' show DartFormatter; import 'package:flutter_gen_core/generators/assets_generator.dart'; import 'package:flutter_gen_core/generators/colors_generator.dart'; import 'package:flutter_gen_core/generators/fonts_generator.dart'; import 'package:flutter_gen_core/settings/config.dart'; import 'package:flutter_gen_core/utils/file.dart'; -import 'package:path/path.dart'; -import 'package:pub_semver/pub_semver.dart'; +import 'package:path/path.dart' show join, normalize; +import 'package:pub_semver/pub_semver.dart' show Version; class FlutterGenerator { const FlutterGenerator(